Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support x86_64-pc-windows-gnu toolchain ? #2001

Open
abcfy2 opened this issue Mar 13, 2024 · 7 comments · May be fixed by #2026
Open

Support x86_64-pc-windows-gnu toolchain ? #2001

abcfy2 opened this issue Mar 13, 2024 · 7 comments · May be fixed by #2026

Comments

@abcfy2
Copy link

abcfy2 commented Mar 13, 2024

I uses msys2 rust, which build target is x86_64-pc-windows-gnu (output file name is index.win32-x64-gnu.node). I hope this toolchain could be supported. Currently only win32-x64-msvc supported.

? Choose targets you want to support (Press <space> to select, <a> to toggle all, <i> to invert selection, and <enter> to proceed)
 ( ) armv7-unknown-linux-gnueabihf
 (*) x86_64-apple-darwin
 (*) x86_64-pc-windows-msvc
>(*) x86_64-unknown-linux-gnu
 ( ) x86_64-unknown-linux-musl
 ( ) x86_64-unknown-freebsd
 ( ) i686-pc-windows-msvc

And the generated index.js only judgements x86_64-pc-windows-msvc:

  case 'win32':
    switch (arch) {
      case 'x64':
        localFileExisted = existsSync(
          join(__dirname, 'index.win32-x64-msvc.node')
        )
        try {
          if (localFileExisted) {
            nativeBinding = require('./index.win32-x64-msvc.node')
          } else {
            nativeBinding = require('index-win32-x64-msvc')
          }
        } catch (e) {
          loadError = e
        }
        break
@abcfy2 abcfy2 changed the title Support win32-x64-gnu toolchain ? Support x86_64-pc-windows-gnu toolchain ? Mar 13, 2024
@Brooooooklyn
Copy link
Sponsor Member

@abcfy2
Copy link
Author

abcfy2 commented Mar 15, 2024

Any plan ?

@Brooooooklyn
Copy link
Sponsor Member

@abcfy2 no, unless there are official Node.js releases for the windows-gnu target

@Kreijstal
Copy link

Kreijstal commented Mar 23, 2024

related #1893
doesn't https://packages.msys2.org/package/mingw-w64-x86_64-nodejs count?
see the patches and PKGBUILD here https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-nodejs

This impedes some work on rollup

@Kreijstal
Copy link

@abcfy2 no, unless there are official Node.js releases for the windows-gnu target

At least write some docs on how to build this from source. I've been struggling, it seems it builds without errors, however when doing cargo test, I get the warning

Load Node-API [napi_get_last_error_info] from host runtime failed: GetProcAddress failed

running some c code msys2/MINGW-packages#20407 (comment) it seems GetProcAddress can indeed get the address from the dll. However not sure how to tell that to rust.

@Kreijstal
Copy link

Here I try to create a minimal example

user@computer UCRT64 ~/node/t/l
$ ls
Cargo.lock  Cargo.toml  l.node  src  target

user@computer UCRT64 ~/node/t/l
$ cat src/lib.rs
use napi::bindgen_prelude::*;
//use napi_derive::napi;

user@computer UCRT64 ~/node/t/l
$ cat Cargo.toml
[package]
name = "l"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib"]

[dependencies]
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
napi = { version = "2.16.0", default-features = false, features = ["napi4"] }
napi-derive = "2.16.0"


user@computer UCRT64 ~/node/t/l
$ cargo b
warning: unused import: `napi::bindgen_prelude::*`
 --> src\lib.rs:1:5
  |
1 | use napi::bindgen_prelude::*;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: `l` (lib) generated 1 warning (run `cargo fix --lib -p l` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.05s

user@computer UCRT64 ~/node/t/l
$ cp target/debug/l.dll l.node

user@computer UCRT64 ~/node/t/l
$ node l.node
Load Node-API [napi_get_last_error_info] from host runtime failed: GetProcAddress failed
Load Node-API [napi_get_uv_event_loop] from host runtime failed: GetProcAddress failed
Load Node-API [napi_fatal_exception] from host runtime failed: GetProcAddress failed
Load Node-API [napi_create_threadsafe_function] from host runtime failed: GetProcAddress failed
thread '<unnamed>' panicked at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\napi-sys-2.3.0\src\f
unctions.rs:7:3:
Must load N-API bindings
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5

it really does not want to load the bindings, the code is minimal

@Kreijstal
Copy link

Kreijstal commented Apr 4, 2024

yeah so the thing is nodejs does not load the bindings, you have to link to libnode.dll directly, which you never do. You try to load them from the current process using GetModuleHandleExW(0,NULL,_) this will not work, or your interface to it see https://github.com/napi-rs/napi-rs/blob/e4ad4767efaf093fdff3dc768856f6100a6e3f72/crates/sys/src/functions.rs#L786C14-L786C46 and https://docs.rs/libloading/latest/src/libloading/os/windows/mod.rs.html#85. please load libnode.dll before using the napi, just as the error message tells you.
please see msys2/MINGW-packages#20407 (comment) the DLOAD_FROM_PROCESS version won't work.


I have to admit I have not verified if solving this problem will make it work, so I am not sure if there are further issues than this

@Kreijstal Kreijstal linked a pull request Apr 5, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants