allow disabling RUSTFLAGS config

This commit is contained in:
Jean Mertz 2023-05-19 12:00:54 +02:00 committed by Jonas Bushart
parent cf60eafd0a
commit 24274e4435
2 changed files with 29 additions and 8 deletions

View file

@ -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. 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. Afterward, the `components` and `target` specified via inputs are installed in addition to the items from the toolchain file.
| Name | Description | Default | | Name | Description | Default |
| ------------ | --------------------------------------------------------------------------------- | ------- | | ------------ | -------------------------------------------------------------------------------------- | ------------- |
| `toolchain` | Rustup toolchain specifier e.g. `stable`, `nightly`, `1.42.0`. | stable | | `toolchain` | Rustup toolchain specifier e.g. `stable`, `nightly`, `1.42.0`. | stable |
| `target` | Additional target support to install e.g. `wasm32-unknown-unknown` | | | `target` | Additional target support to install e.g. `wasm32-unknown-unknown` | |
| `components` | Comma-separated string of additional components to install e.g. `clippy, rustfmt` | | | `components` | Comma-separated string of additional components to install e.g. `clippy, rustfmt` | |
| `cache` | Automatically configure Rust cache (using `Swatinem/rust-cache`) | true | | `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 ## Outputs
@ -68,3 +82,4 @@ License].
[MIT License]: LICENSE [MIT License]: LICENSE
[Problem Matchers]: https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md [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

View file

@ -26,6 +26,10 @@ inputs:
description: "Automatically configure Rust cache" description: "Automatically configure Rust cache"
required: false required: false
default: "true" default: "true"
rustflags:
description: "set RUSTFLAGS environment variable, set to empty string to avoid overwriting build.rustflags"
requred: false
default: "-D warnings"
outputs: outputs:
rustc-version: rustc-version:
@ -76,8 +80,8 @@ runs:
if [[ ! -v RUST_BACKTRACE ]]; then if [[ ! -v RUST_BACKTRACE ]]; then
echo "RUST_BACKTRACE=short" >> $GITHUB_ENV echo "RUST_BACKTRACE=short" >> $GITHUB_ENV
fi fi
if [[ ! -v RUSTFLAGS ]]; then if [[ -v "$NEW_RUSTFLAGS" ]]; then
echo "RUSTFLAGS=-D warnings" >> $GITHUB_ENV echo "RUSTFLAGS="$NEW_RUSTFLAGS" >> $GITHUB_ENV
fi fi
# Enable faster sparse index on nightly # Enable faster sparse index on nightly
# The value is ignored on stable and causes no problems # The value is ignored on stable and causes no problems
@ -89,6 +93,8 @@ runs:
echo "CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse" >> $GITHUB_ENV echo "CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse" >> $GITHUB_ENV
fi fi
shell: bash shell: bash
env:
NEW_RUSTFLAGS: ${{inputs.rustflags}}
- name: "Install Rust Problem Matcher" - name: "Install Rust Problem Matcher"
run: echo "::add-matcher::${{ github.action_path }}/rust.json" run: echo "::add-matcher::${{ github.action_path }}/rust.json"
shell: bash shell: bash