From 24274e4435325db028283c34bfb6f6f518d8af06 Mon Sep 17 00:00:00 2001 From: Jean Mertz Date: Fri, 19 May 2023 12:00:54 +0200 Subject: [PATCH 1/5] allow disabling `RUSTFLAGS` config --- README.md | 27 +++++++++++++++++++++------ action.yml | 10 ++++++++-- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4515c04..a6ec00a 100644 --- a/README.md +++ b/README.md @@ -46,12 +46,26 @@ If a [toolchain file](https://rust-lang.github.io/rustup/overrides.html#the-tool First, all items specified in the toolchain file are installed. Afterward, the `components` and `target` specified via inputs are installed in addition to the items from the toolchain file. -| Name | Description | Default | -| ------------ | --------------------------------------------------------------------------------- | ------- | -| `toolchain` | Rustup toolchain specifier e.g. `stable`, `nightly`, `1.42.0`. | stable | -| `target` | Additional target support to install e.g. `wasm32-unknown-unknown` | | -| `components` | Comma-separated string of additional components to install e.g. `clippy, rustfmt` | | -| `cache` | Automatically configure Rust cache (using `Swatinem/rust-cache`) | true | +| Name | Description | Default | +| ------------ | -------------------------------------------------------------------------------------- | ------------- | +| `toolchain` | Rustup toolchain specifier e.g. `stable`, `nightly`, `1.42.0`. | stable | +| `target` | Additional target support to install e.g. `wasm32-unknown-unknown` | | +| `components` | Comma-separated string of additional components to install e.g. `clippy, rustfmt` | | +| `cache` | Automatically configure Rust cache (using `Swatinem/rust-cache`) | true | +| `rustflags` | Set the value of `RUSTFLAGS` (set to empty string to avoid overwriting existing flags) | "-D warnings" | + +### RUSTFLAGS + +By default, this action sets the `RUSTFLAGS` environment variable to `-D warnings`. + +However, rustflags sources are mutually exclusive, so setting this environment +variable omits any configuration through `target.*.rustflags` or +`build.rustflags`. + +To prevent this from happening, set the `rustflags` input to an empty string, which will +prevent the action from setting `RUSTFLAGS` at all, keeping any existing preferences. + +You can read more rustflags, and their load order, in the [Cargo reference]. ## Outputs @@ -68,3 +82,4 @@ License]. [MIT License]: LICENSE [Problem Matchers]: https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md +[Cargo reference]: https://doc.rust-lang.org/cargo/reference/config.html?highlight=unknown#buildrustflags \ No newline at end of file diff --git a/action.yml b/action.yml index d91e807..071288f 100644 --- a/action.yml +++ b/action.yml @@ -26,6 +26,10 @@ inputs: description: "Automatically configure Rust cache" required: false default: "true" + rustflags: + description: "set RUSTFLAGS environment variable, set to empty string to avoid overwriting build.rustflags" + requred: false + default: "-D warnings" outputs: rustc-version: @@ -76,8 +80,8 @@ runs: if [[ ! -v RUST_BACKTRACE ]]; then echo "RUST_BACKTRACE=short" >> $GITHUB_ENV fi - if [[ ! -v RUSTFLAGS ]]; then - echo "RUSTFLAGS=-D warnings" >> $GITHUB_ENV + if [[ -v "$NEW_RUSTFLAGS" ]]; then + echo "RUSTFLAGS="$NEW_RUSTFLAGS" >> $GITHUB_ENV fi # Enable faster sparse index on nightly # The value is ignored on stable and causes no problems @@ -89,6 +93,8 @@ runs: echo "CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse" >> $GITHUB_ENV fi shell: bash + env: + NEW_RUSTFLAGS: ${{inputs.rustflags}} - name: "Install Rust Problem Matcher" run: echo "::add-matcher::${{ github.action_path }}/rust.json" shell: bash From aaa7eef1a2edc8d8a8537b85859e7ed77e91da2a Mon Sep 17 00:00:00 2001 From: Jean Mertz Date: Fri, 19 May 2023 12:02:38 +0200 Subject: [PATCH 2/5] requred -> required --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 071288f..bdff1c4 100644 --- a/action.yml +++ b/action.yml @@ -28,7 +28,7 @@ inputs: default: "true" rustflags: description: "set RUSTFLAGS environment variable, set to empty string to avoid overwriting build.rustflags" - requred: false + required: false default: "-D warnings" outputs: From 823a4a135dd7e1bcfc03717aeb5360a52f26916a Mon Sep 17 00:00:00 2001 From: Jean Mertz Date: Fri, 19 May 2023 12:10:05 +0200 Subject: [PATCH 3/5] fixes --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index bdff1c4..f6a4d7b 100644 --- a/action.yml +++ b/action.yml @@ -80,8 +80,8 @@ runs: if [[ ! -v RUST_BACKTRACE ]]; then echo "RUST_BACKTRACE=short" >> $GITHUB_ENV fi - if [[ -v "$NEW_RUSTFLAGS" ]]; then - echo "RUSTFLAGS="$NEW_RUSTFLAGS" >> $GITHUB_ENV + if [[ -v NEW_RUSTFLAGS ]]; then + echo "RUSTFLAGS=$NEW_RUSTFLAGS" >> $GITHUB_ENV fi # Enable faster sparse index on nightly # The value is ignored on stable and causes no problems From 70241ab2e90413cc777cbfcedd182e8337bb886a Mon Sep 17 00:00:00 2001 From: Jean Mertz Date: Fri, 19 May 2023 12:46:47 +0200 Subject: [PATCH 4/5] fixes --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f6a4d7b..8214b98 100644 --- a/action.yml +++ b/action.yml @@ -80,7 +80,7 @@ runs: if [[ ! -v RUST_BACKTRACE ]]; then echo "RUST_BACKTRACE=short" >> $GITHUB_ENV fi - if [[ -v NEW_RUSTFLAGS ]]; then + if [[ "$NEW_RUSTFLAGS" != "" ]]; then echo "RUSTFLAGS=$NEW_RUSTFLAGS" >> $GITHUB_ENV fi # Enable faster sparse index on nightly From 1ef811fbfbdd61296f9a3b8ce232ad25e2530320 Mon Sep 17 00:00:00 2001 From: Jonas Bushart Date: Mon, 29 May 2023 21:38:39 +0200 Subject: [PATCH 5/5] Restore behavior to not touch existing RUSTFLAGS variable Add changelog --- CHANGELOG.md | 6 ++++++ README.md | 10 ++++++---- action.yml | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a140dc..0375f7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Before only the items listed in `rust-toolchain` were installed. Now all the items from the toolchain file are installed and then all the `target`s and `components` that are provided as action inputs. This allows installing extra tools only for CI or simplify testing special targets in CI. +* Allow skipping the creation of a `RUSTFLAGS` environment variable. + Cargos logic for rustflags is complicated, and setting the `RUSTFLAGS` environment variable prevents other ways of working. + Provide a new `rustflags` input, which controls the environment variable creation. + If the value is set to the empty string, then `RUSTFLAGS` is not created. + + Pre-existing `RUSTFLAGS` variables are never modified by this extension. ## [1.4.4] - 2023-03-18 diff --git a/README.md b/README.md index a6ec00a..517e0d4 100644 --- a/README.md +++ b/README.md @@ -57,10 +57,12 @@ Afterward, the `components` and `target` specified via inputs are installed in a ### RUSTFLAGS By default, this action sets the `RUSTFLAGS` environment variable to `-D warnings`. +However, rustflags sources are mutually exclusive, so setting this environment variable omits any configuration through `target.*.rustflags` or `build.rustflags`. -However, rustflags sources are mutually exclusive, so setting this environment -variable omits any configuration through `target.*.rustflags` or -`build.rustflags`. +* If `RUSTFLAGS` is already set, no modifications of the variable are made and the original value remains. +* If `RUSTFLAGS` is unset and the `rustflags` input is empty (i.e., the empty string), then it will remain unset. + Use this, if you want to prevent the value from being set because you make use of `target.*.rustflags` or `build.rustflags`. +* Otherwise, the environment variable `RUSTFLAGS` is set to the content of `rustflags`. To prevent this from happening, set the `rustflags` input to an empty string, which will prevent the action from setting `RUSTFLAGS` at all, keeping any existing preferences. @@ -82,4 +84,4 @@ License]. [MIT License]: LICENSE [Problem Matchers]: https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md -[Cargo reference]: https://doc.rust-lang.org/cargo/reference/config.html?highlight=unknown#buildrustflags \ No newline at end of file +[Cargo reference]: https://doc.rust-lang.org/cargo/reference/config.html?highlight=unknown#buildrustflags diff --git a/action.yml b/action.yml index 8214b98..5f0639e 100644 --- a/action.yml +++ b/action.yml @@ -80,7 +80,7 @@ runs: if [[ ! -v RUST_BACKTRACE ]]; then echo "RUST_BACKTRACE=short" >> $GITHUB_ENV fi - if [[ "$NEW_RUSTFLAGS" != "" ]]; then + if [[ ( ! -v RUSTFLAGS ) && $NEW_RUSTFLAGS != "" ]]; then echo "RUSTFLAGS=$NEW_RUSTFLAGS" >> $GITHUB_ENV fi # Enable faster sparse index on nightly