-
Notifications
You must be signed in to change notification settings - Fork 17
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
fix: remove from env CARGO_ENCODED_RUSTFLAGS for easier nested builds #289
base: main
Are you sure you want to change the base?
Conversation
match key { | ||
"RUSTFLAGS" => { | ||
let rustflags: &mut String = final_env | ||
.entry(key) | ||
.or_insert_with(|| std::env::var(key).unwrap_or_default()); | ||
// helps avoids situation on complete match `RUSTFLAGS="-C link-arg=-s -C link-arg=-s"` | ||
if !rustflags.contains(value) { | ||
if !rustflags.is_empty() { | ||
rustflags.push(' '); | ||
} | ||
rustflags.push_str(value); | ||
} | ||
} | ||
_ => { | ||
final_env.insert(key, value.to_string()); | ||
} | ||
} |
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.
this is just a simplification to avoid concatenating with value from env.
It will be simply -Awarnings
for abi builds and -C link-arg=-s
for wasm builds
// CARGO_ENCODED_RUSTFLAGS="-Awarnings" and RUSTFLAGS="-Awarnings" both result | ||
// in mysterious failures of `cargo build --target wasm32-unknown-unknown` (rustc bug) | ||
cmd.env_remove("CARGO_ENCODED_RUSTFLAGS"); |
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.
The comment says that both CARGO_ENCODED_RUSTFLAGS
and RUSTFLAGS
cause problems, but we only remove CARGO_ENCODED_RUSTFLAGS
, is this intended?
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.
RUSTFLAGS gets reset to unset in build scripts, so the 2nd or 3rd of 4th build won't inherit this value from
previous 1st or 2nd or 3rd one,
and the 1st build isn't having its value concatenated with value from env as per another commented change,
and will have it defined as -Awarnings
for abi builds and -C link-arg=-s
for wasm builds
let mut final_env = BTreeMap::new(); | ||
|
||
// this will overwrite any other RUSTFLAGS specified | ||
if hide_warnings { | ||
env.push(("RUSTFLAGS", "-Awarnings")); | ||
} | ||
|
||
// last instance of a key gets inserted | ||
for (key, value) in env { | ||
match key { | ||
"RUSTFLAGS" => { | ||
let rustflags: &mut String = final_env | ||
.entry(key) | ||
.or_insert_with(|| std::env::var(key).unwrap_or_default()); | ||
// helps avoids situation on complete match `RUSTFLAGS="-C link-arg=-s -C link-arg=-s"` | ||
if !rustflags.contains(value) { | ||
if !rustflags.is_empty() { | ||
rustflags.push(' '); | ||
} | ||
rustflags.push_str(value); | ||
} | ||
} | ||
_ => { | ||
final_env.insert(key, value.to_string()); | ||
} | ||
} | ||
final_env.insert(key, value.to_string()); |
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.
nit: feel free to ignore this comment.
It seems that it can be simplified:
let mut final_env: BTreeMap<_, _> = env.into_iter().collect();
if hide_warnings {
final_env.set("RUSTFLAGS", "-Awarnings");
}
And env
function argument can be just an immutable slice then
somewhat redundantly tested this on dj8yfo/neardevhub-treasury-dashboard@6e8f765 via build log only (no deploy): - Binary: /home/near/code/web4/treasury-web4/target/near/treasury_web4.wasm
- SHA-256 checksum hex : 94d35d0c174020f04a59cbe18f8408021e3f86a0d426686fb8e9f2a64b0a2323
- SHA-256 checksum bs58: B1xGfvAYbi4ZktyztiiqGaVbvG7JtXmBuxc3rUV1s7HU │ warning: [email protected]: Build artifact path: /home/near/code/web4/treasury-web4/target/near/treasury_web4.wasm
│ warning: [email protected]: Sub-build artifact SHA-256 checksum hex: 94d35d0c174020f04a59cbe18f8408021e3f86a0d426686fb8e9f2a64b0a2323
│ warning: [email protected]: Sub-build artifact SHA-256 checksum bs58: B1xGfvAYbi4ZktyztiiqGaVbvG7JtXmBuxc3rUV1s7HU
│ warning: [email protected]:
│ warning: [email protected]:
│ warning: [email protected]: Path to result artifact of build is exported to `BUILD_RS_WEB4_TREASURY_WEB4_WASM` |
@race-of-sloths include |
@dj8yfo Thank you for your contribution! Your pull request is now a part of the Race of Sloths! Current status: waiting for scoringWe're waiting for maintainer to score this pull request with What is the Race of SlothsRace of Sloths is a friendly competition where you can participate in challenges and compete with other open-source contributors within your normal workflow For contributors:
For maintainers:
Feel free to check our website for additional details! Bot commands
|
resolves #287
this stuff gets set for build-scripts https://github.com/rust-lang/cargo/blob/master/src/cargo/core/compiler/custom_build.rs#L378, while
RUSTFLAGS
is unsettested to help resolve problem in #287 on dj8yfo/neardevhub-treasury-dashboard@56bcbcf