napi-rs Docs

Frequently Asked Questions

Frequently Asked Questions

Build for Linux alpine

You can not set compile crate-type to cdylib when compile target is *-unknown-linux-musl by default.

If you want to do so, you need pass -C target-feature=-crt-static to rustc.

There are two ways to pass this argument:

  • Set RUSTFLAGS env, RUSTFLAGS="-C target-feature=-crt-static"

  • Set it in .cargo/config.toml:

    crt_static = false

Build for Windows i686

There is codegen error when compile target is i686-windows-*: Rust issue 67497.

There is a workaround to avoid this issue:

  • Set lto to false, if you haven't set lto in your Cargo.toml, the value is false by default, you can ignore this one.
  • Set codegen-units to 32 (or bigger). The default value of codegen-units is 16 by default when compile target is release, you can set CARGO_PROFILE_RELEASE_CODEGEN_UNITS=32 and CARGO_PROFILE_RELEASE_LTO='false' to make compiler happy when targeting i686-windows-*. Here is an example.
Edit this page on GitHub