Skip to content

Commit f3c84ee

Browse files
authored
Merge pull request #18 from JeanMertz/rustflags
2 parents cf60eaf + 1ef811f commit f3c84ee

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
Before only the items listed in `rust-toolchain` were installed.
1616
Now all the items from the toolchain file are installed and then all the `target`s and `components` that are provided as action inputs.
1717
This allows installing extra tools only for CI or simplify testing special targets in CI.
18+
* Allow skipping the creation of a `RUSTFLAGS` environment variable.
19+
Cargos logic for rustflags is complicated, and setting the `RUSTFLAGS` environment variable prevents other ways of working.
20+
Provide a new `rustflags` input, which controls the environment variable creation.
21+
If the value is set to the empty string, then `RUSTFLAGS` is not created.
22+
23+
Pre-existing `RUSTFLAGS` variables are never modified by this extension.
1824

1925
## [1.4.4] - 2023-03-18
2026

README.md

+23-6
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,28 @@ 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+
However, rustflags sources are mutually exclusive, so setting this environment variable omits any configuration through `target.*.rustflags` or `build.rustflags`.
61+
62+
* If `RUSTFLAGS` is already set, no modifications of the variable are made and the original value remains.
63+
* If `RUSTFLAGS` is unset and the `rustflags` input is empty (i.e., the empty string), then it will remain unset.
64+
Use this, if you want to prevent the value from being set because you make use of `target.*.rustflags` or `build.rustflags`.
65+
* Otherwise, the environment variable `RUSTFLAGS` is set to the content of `rustflags`.
66+
67+
To prevent this from happening, set the `rustflags` input to an empty string, which will
68+
prevent the action from setting `RUSTFLAGS` at all, keeping any existing preferences.
69+
70+
You can read more rustflags, and their load order, in the [Cargo reference].
5571

5672
## Outputs
5773

@@ -68,3 +84,4 @@ License].
6884

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

action.yml

+8-2
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+
required: 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 RUSTFLAGS ) && $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)