-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathlint.sh
More file actions
executable file
·74 lines (65 loc) · 3.04 KB
/
lint.sh
File metadata and controls
executable file
·74 lines (65 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
set -e
# Custom lints
# 1. Disallow `std::env` (mis)use from `rustc_codegen_spirv`
# HACK(eddyb) see `docs/src/codegen-args.md` for more context around this,
# but basically we're implementing a custom "lint" to ban `std::env` usage,
# which could be disastrous because env vars access can't be tracked by
# `rustc`, unlike its CLI flags (which are integrated with incremental).
if (
egrep -r '::\s*env|env\s*::' crates/rustc_codegen_spirv/src |
# HACK(eddyb) exclude the one place in `rustc_codegen_spirv`
# needing access to an env var (only for codegen args `--help`).
egrep -v '^crates/rustc_codegen_spirv/src/codegen_cx/mod.rs: let help_flag_comes_from_spirv_builder_env_var = std::env::var\(spirv_builder_env_var\)$' |
# HACK(LegNeato) exclude logging. This mirrors `rustc` (`RUSTC_LOG`) and
#`rustdoc` (`RUSTDOC_LOG`).
# There is not a risk of this being disastrous as it does not change the build settings.
egrep -v '^crates/rustc_codegen_spirv/src/lib.rs:.*(RUSTGPU_LOG|RUSTGPU_LOG_FORMAT|RUSTGPU_LOG_COLOR).*$' |
egrep -v '^crates/rustc_codegen_spirv/src/lib.rs: use std::env::{self, VarError};$'
); then
echo '^^^'
echo '!!! Found disallowed `std::env` usage in `rustc_codegen_spirv` !!!'
echo ' ("codegen args" should be used instead of environment variables)'
echo
echo 'For more details on "codegen args", see: docs/src/codegen-args.md'
echo ' (and/or https://github.com/EmbarkStudios/rust-gpu/pull/959)'
echo
exit 1
fi
# 2. Ensure `spirv-std` & helper crates have necessary dependency versions
# listed in their `Cargo.toml` files, by using `cargo -Z minimal-versions`.
echo 'Testing dependency versions with `cargo -Z minimal-versions`:'
function version_test() {
local crate_path="$1"
local crate_name="$(basename "$crate_path")"
local test_dir="$(mktemp -d --tmpdir "version-test-$crate_name-XXXXXXXXXX")"
local test_cargoflags=(
-Z minimal-versions
--manifest-path "$test_dir/Cargo.toml"
)
echo ::group::"$crate_name (via $test_dir)"
cargo init --lib --vcs none --name "version-test-$crate_name" "$test_dir"
cargo add "${test_cargoflags[@]}" --path "$crate_path"
cargo clippy "${test_cargoflags[@]}" -- -D warnings
rm -r "$test_dir"
echo ::endgroup::
}
# FIXME(eddyb) try to get this working for `spirv-builder`, which has a larger
# dependency graph, with too much imprecision in upstream `Cargo.toml` files.
version_test crates/spirv-std
# 3. Ensure `rustc_codegen_spirv` still compiles with `rustc_codegen_ssa`.
# HACK(eddyb) see `crates/rustc_codegen_spirv/build.rs` for more on `pqp_cg_ssa`
# (a patched copy of `rustc_codegen_ssa`).
echo ::group::rustc_codegen_spirv_disable_pqp_cg_ssa
if [[ -z "${CI}" ]]; then
FEAT="use-compiled-tools"
else
FEAT="use-installed-tools"
fi
cargo clippy \
--manifest-path "crates/rustc_codegen_spirv/Cargo.toml" \
--no-default-features \
--features "$FEAT" \
--all-targets \
-- -D warnings --cfg rustc_codegen_spirv_disable_pqp_cg_ssa
echo ::endgroup::