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, simplify RUSTFLAGS computation rule #289

Merged
merged 6 commits into from
Jan 22, 2025

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

@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

race-of-sloths commented Jan 15, 2025

@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: executed
Reviewer Score
@akorchyn 13

Your contribution is much appreciated with a final score of 13!
You have received 150 (130 base + 15% lifetime bonus) Sloth points for this contribution

@akorchyn received 25 Sloth Points for reviewing and scoring 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

Copy link
Collaborator

@akorchyn akorchyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@race-of-sloths score 13

Good job!

cargo-near-build/src/cargo_native/compile.rs Outdated Show resolved Hide resolved
cargo-near-build/src/cargo_native/compile.rs Outdated Show resolved Hide resolved
@dj8yfo dj8yfo force-pushed the test_remove_cargo_encoded_rustflags_env branch from 6930c38 to 3c168e3 Compare January 22, 2025 15:07
@@ -109,7 +109,7 @@ impl ReproducibleBuild {
for command_token in build_command {
if command_token
.chars()
.any(|c| !c.is_ascii() || c.is_ascii_control() || c.is_ascii_whitespace())
.any(|c| !c.is_ascii() || c.is_ascii_control())
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing this allows doing

container_build_command = ["cargo", "near", "build", "non-reproducible-wasm", "--locked", "--env", "RUSTFLAGS=--verbose -C link-arg=-s"]

@dj8yfo dj8yfo changed the title fix: remove from env CARGO_ENCODED_RUSTFLAGS for easier nested builds fix: remove from env CARGO_ENCODED_RUSTFLAGS for easier nested builds, simplify RUSTFLAGS computation rule Jan 22, 2025
@dj8yfo dj8yfo enabled auto-merge (squash) January 22, 2025 15:17
@dj8yfo dj8yfo merged commit 4c97799 into near:main Jan 22, 2025
17 checks passed
@frol frol mentioned this pull request Jan 22, 2025
dj8yfo pushed a commit that referenced this pull request Jan 22, 2025
## 🤖 New release
* `cargo-near`: 0.13.2 -> 0.13.3 (✓ API compatible changes)
* `cargo-near-build`: 0.4.2 -> 0.4.3 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

## `cargo-near`
<blockquote>

##
[0.13.3](cargo-near-v0.13.2...cargo-near-v0.13.3)
- 2025-01-22

### Other

- update near-cli-rs to 0.18.0 (#293)
- update `cargo near new` template `image` and `image_digest`
([#288](#288))
- update `cargo near new` template `image` and `image_digest`
([#283](#283))
</blockquote>

## `cargo-near-build`
<blockquote>

##
[0.4.3](cargo-near-build-v0.4.2...cargo-near-build-v0.4.3)
- 2025-01-22

### Fixed

- remove from env CARGO_ENCODED_RUSTFLAGS for easier nested builds,
simplify RUSTFLAGS computation rule (#289)

### Other

- optimize out retriggering 2nd stage of build + of wasmopt stage in
tests context (#292)
- update `cargo near new` template `image` and `image_digest`
([#288](#288))
- unpin `cc` after issue resolution (#285)
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants