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

fix: remove from env CARGO_ENCODED_RUSTFLAGS for easier nested builds #289

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

dj8yfo
Copy link
Collaborator

@dj8yfo dj8yfo commented Jan 10, 2025

image

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 unset


tested to help resolve problem in #287 on dj8yfo/neardevhub-treasury-dashboard@56bcbcf

Comment on lines 32 to 48
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());
}
}
Copy link
Collaborator Author

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

Comment on lines 109 to 111
// 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");
Copy link
Contributor

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?

Copy link
Collaborator Author

@dj8yfo dj8yfo Jan 10, 2025

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

Comment on lines 25 to 34
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());
Copy link
Contributor

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

@dj8yfo dj8yfo changed the title fix: remove CARGO_ENCODED_RUSTFLAGS for easier nested builds fix: remove from env CARGO_ENCODED_RUSTFLAGS for easier nested builds Jan 10, 2025
@dj8yfo
Copy link
Collaborator Author

dj8yfo commented Jan 15, 2025

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`

@dj8yfo dj8yfo marked this pull request as ready for review January 15, 2025 15:36
@dj8yfo
Copy link
Collaborator Author

dj8yfo commented Jan 15, 2025

@race-of-sloths include

@race-of-sloths
Copy link

@dj8yfo Thank you for your contribution! Your pull request is now a part of the Race of Sloths!
King of Sloths shakes your hand! Yellow leader's jersey is yours deservedly!

Shows inviting banner with latest news.

Shows profile picture for the author of the PR

Current status: waiting for scoring

We're waiting for maintainer to score this pull request with @race-of-sloths score [0,1,2,3,5,8,13] command. Alternatively, autoscoring [1,2] will be applied for this pull request

What is the Race of Sloths

Race 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:

  • Tag @race-of-sloths inside your pull requests
  • Wait for the maintainer to review and score your pull request
  • Check out your position in the Leaderboard
  • Keep weekly and monthly streaks to reach higher positions
  • Boast your contributions with a dynamic picture of your Profile

For maintainers:

  • Score pull requests that participate in the Race of Sloths and receive a reward
  • Engage contributors with fair scoring and fast responses so they keep their streaks
  • Promote the Race to the point where the Race starts promoting you
  • Grow the community of your contributors

Feel free to check our website for additional details!

Bot commands
  • For contributors
    • Include a PR: @race-of-sloths include to enter the Race with your PR
  • For maintainers:
    • Invite contributor @race-of-sloths invite to invite the contributor to participate in a race or include it, if it's already a runner.
    • Assign points: @race-of-sloths score [1/2/3/5/8/13] to award points based on your assessment.
    • Reject this PR: @race-of-sloths exclude to send this PR back to the drawing board.
    • Exclude repo: @race-of-sloths pause to stop bot activity in this repo until @race-of-sloths unpause command is called

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