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

Don't rely on unstable flags. #189

Merged
merged 1 commit into from
Aug 23, 2021
Merged

Don't rely on unstable flags. #189

merged 1 commit into from
Aug 23, 2021

Conversation

dpc
Copy link
Contributor

@dpc dpc commented Aug 19, 2021

Fix #100

@dpc dpc requested a review from nmattia as a code owner August 19, 2021 04:37
@dpc
Copy link
Contributor Author

dpc commented Aug 19, 2021

I tested it with beta and stable and on my little project seems to work. Other than this I have no idea what I'm doing.

@nmattia
Copy link
Collaborator

nmattia commented Aug 19, 2021

Thanks! @basvandijk do you remember why we used --out-dir and not CARGO_TARGET_DIR? I know there was a reason, but right it escapes me...

@nmattia
Copy link
Collaborator

nmattia commented Aug 19, 2021

Ah, I think I knew. The difference is explained here: rust-lang/cargo#5203

The --out-dir parameter is only for final artifacts, and not intermediary results like rlibs (I think). Can you check the final build size with and without your changes?

@dpc
Copy link
Contributor Author

dpc commented Aug 19, 2021

CARGO_TARGET_DIR — Location of where to place all generated artifacts, relative to the current working directory. See build.target-dir to set via config.

https://doc.rust-lang.org/cargo/reference/environment-variables.html

Is it a problem if everything goes into the out dir?

Edit: Oh. The build size, you say... :(

@dpc
Copy link
Contributor Author

dpc commented Aug 19, 2021

Would it be OK if we just delete needless stuff from the output dir? I mean - it's not all that difficult. All the subdirs, and then bunch of .d and .rmeta files, and job done?

@dpc
Copy link
Contributor Author

dpc commented Aug 19, 2021

BTW. I have no idea why, but I'm building my Rust project under a special name (just to make sure I am looking at the right output):

~/l/dotr (master)> find /nix/store/ | grep dotrx
/nix/store/f6x9qjq27ixjdlb38g1fdc95rc7157vr-dotr-0.4.0/bin/dotrx

No other files than the binary. No idea why.

@nmattia
Copy link
Collaborator

nmattia commented Aug 20, 2021

Mh ok that's odd. Maybe that actually works since the top-level derivation only builds the executable? what if you set single-step to true so that everything is built in one derivation?

@dpc
Copy link
Contributor Author

dpc commented Aug 20, 2021

Weird. Same? I've changed the name to dotrxx now.

[I] 08-20 11:41 dpc@futex ~/l/dotr (master)> find /nix/store/y9r0lhv3q8mkk3vxlrisjy38c1dxwmlx-dotr-0.4.0
/nix/store/y9r0lhv3q8mkk3vxlrisjy38c1dxwmlx-dotr-0.4.0
/nix/store/y9r0lhv3q8mkk3vxlrisjy38c1dxwmlx-dotr-0.4.0/bin
/nix/store/y9r0lhv3q8mkk3vxlrisjy38c1dxwmlx-dotr-0.4.0/bin/dotrxx

previous one (no singleStep), to double check.

[I] 08-20 11:41 dpc@futex ~/l/dotr (master)> find /nix/store/f6x9qjq27ixjdlb38g1fdc95rc7157vr-dotr-0.4.0
/nix/store/f6x9qjq27ixjdlb38g1fdc95rc7157vr-dotr-0.4.0
/nix/store/f6x9qjq27ixjdlb38g1fdc95rc7157vr-dotr-0.4.0/bin
/nix/store/f6x9qjq27ixjdlb38g1fdc95rc7157vr-dotr-0.4.0/bin/dotrx

@dpc
Copy link
Contributor Author

dpc commented Aug 20, 2021

Is it because of

    # The value is written to the `cargo_bins_jq_filter` variable.                                                                           
    copyBinsFilter = attrs0.copyBinsFilter or                                                                                                
      ''select(.reason == "compiler-artifact" and .executable != null and .profile.test == false)'';                                         

?

So there is already a redundant mechanism for picking the important stuff from out, it seems.

@nmattia
Copy link
Collaborator

nmattia commented Aug 23, 2021

Well then! if it breaks anything, we'll revert and add a test :)

@nmattia nmattia merged commit f9e6e8d into nix-community:master Aug 23, 2021
@nmattia
Copy link
Collaborator

nmattia commented Aug 23, 2021

Actually I just reverted the commit. I realized that you were setting CARGO_TARGET_DIR locally, for the build only, meaning that cargo test, clippy, doc, etc will be rebuilding from scratch, since they'd revert to the default target/!

@dpc
Copy link
Contributor Author

dpc commented Aug 23, 2021

Does it mean I should add that flag into other places as well?

@nmattia
Copy link
Collaborator

nmattia commented Aug 24, 2021

Yes I think you can export it like so:

export RUST_TEST_THREADS="''${RUST_TEST_THREADS:-$NIX_BUILD_CORES}"

Thanks!

@dpc
Copy link
Contributor Author

dpc commented Aug 24, 2021

I am completely confused what am I doing. I don't understand why exactly it was reverted and what is the problem in the first place. :)

Is is that when using nix develop or something and having ./target local to the workdir, is supposed to be used when doing nix build .# or something?

@nmattia
Copy link
Collaborator

nmattia commented Aug 26, 2021

I guess I could have been clearer! Here you set CARGO_TARGET_DIR for the cargo build command. The CARGO_TARGET_DIR specifies where to put all the build outputs, but also all the intermediary outputs. The default is ./target. This means that other commands like cargo test or cargo clippy will still use ./target, and won't benefit from anything built by CARGO_TARGET_DIR! So either we specify CARGO_TARGET_DIR for all commands, or we don't specify it at all and use target instead of out as the expected output directory. Hope this clarifies :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is it possible for naersk to use stable Rust
2 participants