Skip to content

Commit 24274e4

Browse files
JeanMertzjonasbb
authored andcommitted
allow disabling RUSTFLAGS config
1 parent cf60eaf commit 24274e4

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,26 @@ If a [toolchain file](https://rust-lang.github.io/rustup/overrides.html#the-tool
4646
First, all items specified in the toolchain file are installed.
4747
Afterward, the `components` and `target` specified via inputs are installed in addition to the items from the toolchain file.
4848

49-
| Name | Description | Default |
50-
| ------------ | --------------------------------------------------------------------------------- | ------- |
51-
| `toolchain` | Rustup toolchain specifier e.g. `stable`, `nightly`, `1.42.0`. | stable |
52-
| `target` | Additional target support to install e.g. `wasm32-unknown-unknown` | |
53-
| `components` | Comma-separated string of additional components to install e.g. `clippy, rustfmt` | |
54-
| `cache` | Automatically configure Rust cache (using `Swatinem/rust-cache`) | true |
49+
| Name | Description | Default |
50+
| ------------ | -------------------------------------------------------------------------------------- | ------------- |
51+
| `toolchain` | Rustup toolchain specifier e.g. `stable`, `nightly`, `1.42.0`. | stable |
52+
| `target` | Additional target support to install e.g. `wasm32-unknown-unknown` | |
53+
| `components` | Comma-separated string of additional components to install e.g. `clippy, rustfmt` | |
54+
| `cache` | Automatically configure Rust cache (using `Swatinem/rust-cache`) | true |
55+
| `rustflags` | Set the value of `RUSTFLAGS` (set to empty string to avoid overwriting existing flags) | "-D warnings" |
56+
57+
### RUSTFLAGS
58+
59+
By default, this action sets the `RUSTFLAGS` environment variable to `-D warnings`.
60+
61+
However, rustflags sources are mutually exclusive, so setting this environment
62+
variable omits any configuration through `target.*.rustflags` or
63+
`build.rustflags`.
64+
65+
To prevent this from happening, set the `rustflags` input to an empty string, which will
66+
prevent the action from setting `RUSTFLAGS` at all, keeping any existing preferences.
67+
68+
You can read more rustflags, and their load order, in the [Cargo reference].
5569

5670
## Outputs
5771

@@ -68,3 +82,4 @@ License].
6882

6983
[MIT License]: LICENSE
7084
[Problem Matchers]: https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md
85+
[Cargo reference]: https://doc.rust-lang.org/cargo/reference/config.html?highlight=unknown#buildrustflags

action.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ inputs:
2626
description: "Automatically configure Rust cache"
2727
required: false
2828
default: "true"
29+
rustflags:
30+
description: "set RUSTFLAGS environment variable, set to empty string to avoid overwriting build.rustflags"
31+
requred: false
32+
default: "-D warnings"
2933

3034
outputs:
3135
rustc-version:
@@ -76,8 +80,8 @@ runs:
7680
if [[ ! -v RUST_BACKTRACE ]]; then
7781
echo "RUST_BACKTRACE=short" >> $GITHUB_ENV
7882
fi
79-
if [[ ! -v RUSTFLAGS ]]; then
80-
echo "RUSTFLAGS=-D warnings" >> $GITHUB_ENV
83+
if [[ -v "$NEW_RUSTFLAGS" ]]; then
84+
echo "RUSTFLAGS="$NEW_RUSTFLAGS" >> $GITHUB_ENV
8185
fi
8286
# Enable faster sparse index on nightly
8387
# The value is ignored on stable and causes no problems
@@ -89,6 +93,8 @@ runs:
8993
echo "CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse" >> $GITHUB_ENV
9094
fi
9195
shell: bash
96+
env:
97+
NEW_RUSTFLAGS: ${{inputs.rustflags}}
9298
- name: "Install Rust Problem Matcher"
9399
run: echo "::add-matcher::${{ github.action_path }}/rust.json"
94100
shell: bash

0 commit comments

Comments
 (0)