-
Notifications
You must be signed in to change notification settings - Fork 88
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 -Z build-std #146
Comments
I came across this because I got this warning and tried using the latest stable:
I'm also using https://github.com/oxalica/rust-overlay/ over nixpkgs-mozilla, though it does support the latter's API. |
I've ran into the same error as @Stupremee while using
|
There is also a relevant discussion on the Nix Discourse: https://discourse.nixos.org/t/build-rust-app-using-cargos-build-std-feature-with-naersk-fails-because-rust-src-is-missing/13161/5 The current workaround is to list all extra dependencies in the cargo file of the project you want to build. This is pretty unwieldy unfortunately. |
This allows for an extra Cargo.lock, which is useful when using build-std to ensure the requires crates are available. Related to: nix-community#146
I've created a PR that aims to make this workflow easier: #328 |
This allows for an extra Cargo.lock, which is useful when using build-std to ensure the requires crates are available. Related to: #146
You can use let
rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
in
naersk.buildPackage {
...
cargoBuildOptions = x: x ++ [ "-Z" "build-std=core,std,panic_abort,alloc,test" ];
additionalCargoLock = "${rust-toolchain.availableComponents.rust-src}/lib/rustlib/src/rust/Cargo.lock";
CARGO_BUILD_TARGET = "wasm32-unknown-unknown";
RUSTFLAGS = "-C target-feature=+atomics,+bulk-memory,+mutable-globals -C link-arg=--max-memory=4294967296";
} And then you don't even need to copy any Cargo.lock but directly use the one from the Rust toolchain you're using |
I haven't tried it out but it looks like the issue should be resolved. Thank you very much @bouk ! Do you think it makes sense to add those instructions to the README? |
See
Currently, if you try to build a project that uses
build-std
, you'll get errors about dependencies that are not found, but definitelyexist.
Example project
.cargo/config.toml
src/lib.rs
#![no_std]
default.nix
If I try to build this project, I get the following error:
Error
The text was updated successfully, but these errors were encountered: