oxalica / nocargo

[alpha] Build Rust crates with Nix Build System.
MIT License
138 stars 9 forks source link

Can’t use LTO #5

Closed shivjm closed 2 years ago

shivjm commented 2 years ago

With (thin or fat) LTO enabled in the release profile, I immediately get this error:

rust_maplit> unpacking sources
rust_maplit> unpacking source archive /nix/store/g5pwgk95hnam0dw6x5kbz3yzsdh54f6g-crate-maplit-1.0.2.tar.gz
rust_maplit> source root is maplit-1.0.2
rust_maplit> setting SOURCE_DATE_EPOCH to timestamp 1566667343 of file maplit-1.0.2/Cargo.toml.orig
rust_maplit> patching sources
rust_maplit> configuring
rust_maplit> building
rust_maplit> Building lib: RUSTC 'src/lib.rs' '--out-dir=/nix/store/mdndwnmzpcxq6x3s2kryf1z1rf5852kw-rust_maplit-1.0.2/lib' '--crate-name=maplit' '--crate-type=lib' '--emit=metadata,link' '-Cembed-bitcode=no' '-Cextra-filename=-295a311dcdfdc3f7' '--color=always' '-Copt-level=3' '-Cdebuginfo=0' '-Cdebug-assertions=no' '-Coverflow-checks=no' '-Clto=fat' '-Cpanic=unwind' '-Ccodegen-units=1' '--cap-lints=allow' '-Cmetadata=295a311dcdfdc3f7' '-Ldependency=/nix/store/lwwq906vh2hg0p8g7hqbfb7rr50h6r0c-rust_maplit-1.0.2-dev/rust-support/deps-closure'
rust_maplit> error: options `-C embed-bitcode=no` and `-C lto` are incompatible

I can see -Cembed-bitcode=no is hard-coded:

https://github.com/oxalica/nocargo/blob/e3cd8e3396e85966e71f96f93586d64c797f56b9/build-rust-crate/builder-build-script.sh#L44-L51

I’m completely new to Nix; is this required for nocargo to function? Would it be possible to disable that flag or make it optional? Does LTO not make sense in this context?

shivjm commented 2 years ago

I’ve been experimenting to see if I could implement this, but I don’t think I know enough about linkers or about Nix to proceed.

oxalica commented 2 years ago

Fixed in 69dc641ff910f2350480db76d619d2efad318d92

shivjm commented 2 years ago

That’s great news, thank you! Is there any way this can work even with proc macro crates? This is the output I get, for example:

rust_async-trait> unpacking sources
rust_async-trait> unpacking source archive /nix/store/gagh6m6s2nrish3rnyvdal4xfd6y7j0r-crate-async-trait-0.1.57.tar.gz
rust_async-trait> source root is async-trait-0.1.57
rust_async-trait> setting SOURCE_DATE_EPOCH to timestamp 1153704088 of file async-trait-0.1.57/tests/ui/unsupported-self.stderr
rust_async-trait> patching sources
rust_async-trait> configuring
rust_async-trait> export OUT_DIR=/nix/store/30ryrbm27b00m0hszsd9l03nj1sih664-rust_async-trait-0.1.57-build/rust-support/out-dir
rust_async-trait> building
rust_async-trait> Building lib: RUSTC 'src/lib.rs' '--out-dir=/nix/store/l5cdqnw8d0fi054g3q571gnsdpagl9q2-rust_async-trait-0.1.57/lib' '--crate-name=async_trait' '--crate-type=proc-macro' '--emit=metadata,link' '-Cextra-filename=-e32805d186f61ce1' '-Copt-level=3' '-Cdebug-assertions=no' '-Coverflow-checks=no' '-Clto=thin' '-Ccodegen-units=1' '--cap-lints=allow' '--color=always' '-Cmetadata=e32805d186f61ce1' '--edition=2018' '--extern=proc_macro' '--extern=proc_macro2=/nix/store/ww3jdgaa70f5ly33853339js0masmz4r-rust_proc-macro2-1.0.43/lib/libproc_macro2-184e1004c4ac269c.rlib' '--extern=quote=/nix/store/q8ilfbznqfgy6dnza70fd8rrr9zvcj4b-rust_quote-1.0.21/lib/libquote-5598a87da415ddfe.rlib' '--extern=syn=/nix/store/4vgjxg6j41g0qw8kqg7w8fdrfwb8cf7f-rust_syn-1.0.99/lib/libsyn-ef320449b0c06c65.rlib' '-Ldependency=/nix/store/8jaycq86y6i17rppd7r4k30papvllijl-rust_async-trait-0.1.57-dev/rust-support/deps-closure'
rust_async-trait> error: lto can only be run for executables, cdylibs and static library outputs
rust_async-trait> error: aborting due to previous error
error: builder for '/nix/store/hg18yyha0lrzjbc4mcfsngqhfyn6da3p-rust_async-trait-0.1.57.drv' failed with exit code 1
oxalica commented 2 years ago

Is there any way this can work even with proc macro crates?

Should be fixed in a6681f1aca683a6d190768438fb298e912214e5d.

Also if you run into more problems, please open new issues.

shivjm commented 2 years ago

That works. Thank you very much for fixing both things so quickly. And of course, if I have any further issues, I’ll open new… er, issues.