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
buildRustCrate: add heuristic to picking the right binary source files #46210
Conversation
@GrahamcOfBorg build way-cooler cargo-update cargo-download cargo-vendor cargo-edit carnix |
Failure on aarch64-linux (full log) Attempted: way-cooler, cargo-update, cargo-download, cargo-vendor, cargo-edit, carnix Partial log (click to expand)
|
Failure on x86_64-darwin (full log) Attempted: cargo-update, cargo-download, cargo-vendor, cargo-edit, carnix The following builds were skipped because they don't evaluate on x86_64-darwin: way-cooler Partial log (click to expand)
|
Success on x86_64-linux (full log) Attempted: way-cooler, cargo-update, cargo-download, cargo-vendor, cargo-edit, carnix Partial log (click to expand)
|
|
||
# the first two cases are the "new" default IIRC | ||
BIN_NAME_=$(echo $BIN_NAME | sed -e 's/_/-/g') | ||
FILES="src/bin/$BIN_NAME_.rs src/bin/$BIN_NAME_/main.rs src/bin/main.rs src/main.rs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be an array instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should be an array instead. I'll dig how to do that with bash.
201c1a5
to
8e07e16
Compare
I started restructuring the |
@GrahamcOfBorg build buildRustCrateTests |
Success on x86_64-darwin (full log) Attempted: buildRustCrateTests Partial log (click to expand)
|
Success on aarch64-linux (full log) Attempted: buildRustCrateTests Partial log (click to expand)
|
Success on x86_64-linux (full log) Attempted: buildRustCrateTests Partial log (click to expand)
|
8e07e16
to
d4edaa5
Compare
I started playing with this a bit more and it seems that there is still a lot of headroom to improve in regards to what carnix produces and what we are able to properly build.. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely more readable and build with all our current expression.
Cargo has a few odd (old) ways of picking source files if the `bin.path` attribute isn't given in the Cargo.toml. This commit adds support for some of those. The previous behaviour always defaulted to `src/main.rs` which was not always the right choice. Since there is look-ahead into the unpacked sources before running the actual builder the path selection logic has to be embedded within the build script. `buildRustCrate` currently supports two ways of running building binaries when processing a crate: - Explicit definition of all the binaries (& optionally the paths to their respective `main.rs`) and, - if not binary was explictly configured all files matching the patterns `src/main.rs`, `src/bin/*.rs`. When the explicit list is given without path information paths are now being picked from a list of candidates. The first match wins. The order is the same as within the cargo compatibility code. If the crate does not provide any libraries the path `src/{bin_name}.rs` is also considered. All underscores within the binary names are translated into dashes (`-`) before the lookups are made. This seems to be a common convention.
The build expression got quiet large over time and to make it a bit easier to grasp the different scripts involved in the build are now separated from the nix file.
d4edaa5
to
65d62b6
Compare
This commit adds test based on real-world crates (brotli). There were a few more edge cases that were missing beforehand. Also it turned out that we can get rid of the `finalBins` list since that will now be handled during runtime.
65d62b6
to
fc5e595
Compare
Motivation for this change
Cargo has a few odd (old) ways of picking source files if the
bin.path
attribute isn't given in the Cargo.toml. This commit adds support for
some of those. The previous behaviour always defaulted to
src/main.rs
which was not always the right choice.
Since there is look-ahead into the unpacked sources before running the
actual builder the path selection logic has to be embedded within the
build script.
buildRustCrate
currently supports two ways of running buildingbinaries when processing a crate:
their respective
main.rs
) and,src/main.rs
,src/bin/*.rs
.When the explicit list is given without path information paths are now
being picked from a list of candidates. The first match wins. The order
is the same as within the cargo compatibility code.
If the crate does not provide any libraries the path
src/{bin_name}.rs
is also considered.
All underscores within the binary names are translated into dashes (
-
)before the lookups are made. This seems to be a common convention.
cc some of the people that touched the code before me: @shlevy @Mic92
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)