1eba8b6baSopenharmony_ciconst child_process = require('child_process');
2eba8b6baSopenharmony_ciconst toolchain = process.env.INPUT_TOOLCHAIN;
3eba8b6baSopenharmony_ciconst fs = require('fs');
4eba8b6baSopenharmony_ci
5eba8b6baSopenharmony_cifunction set_env(name, val) {
6eba8b6baSopenharmony_ci  fs.appendFileSync(process.env['GITHUB_ENV'], `${name}=${val}\n`)
7eba8b6baSopenharmony_ci}
8eba8b6baSopenharmony_ci
9eba8b6baSopenharmony_ci// Needed for now to get 1.24.2 which fixes a bug in 1.24.1 that causes issues
10eba8b6baSopenharmony_ci// on Windows.
11eba8b6baSopenharmony_ciif (process.platform === 'win32') {
12eba8b6baSopenharmony_ci  child_process.execFileSync('rustup', ['self', 'update']);
13eba8b6baSopenharmony_ci}
14eba8b6baSopenharmony_ci
15eba8b6baSopenharmony_cichild_process.execFileSync('rustup', ['set', 'profile', 'minimal']);
16eba8b6baSopenharmony_cichild_process.execFileSync('rustup', ['update', toolchain, '--no-self-update']);
17eba8b6baSopenharmony_cichild_process.execFileSync('rustup', ['default', toolchain]);
18eba8b6baSopenharmony_ci
19eba8b6baSopenharmony_ci// Deny warnings on CI to keep our code warning-free as it lands in-tree. Don't
20eba8b6baSopenharmony_ci// do this on nightly though since there's a fair amount of warning churn there.
21eba8b6baSopenharmony_ci// RUSTIX: Disable this so that it doesn't overwrite RUSTFLAGS for setting
22eba8b6baSopenharmony_ci// "--cfg rustix_use_libc". We re-add it manually in the workflow.
23eba8b6baSopenharmony_ci//if (!toolchain.startsWith('nightly')) {
24eba8b6baSopenharmony_ci//  set_env("RUSTFLAGS", "-D warnings");
25eba8b6baSopenharmony_ci//}
26eba8b6baSopenharmony_ci
27eba8b6baSopenharmony_ci// Save disk space by avoiding incremental compilation, and also we don't use
28eba8b6baSopenharmony_ci// any caching so incremental wouldn't help anyway.
29eba8b6baSopenharmony_ciset_env("CARGO_INCREMENTAL", "0");
30eba8b6baSopenharmony_ci
31eba8b6baSopenharmony_ci// Turn down debuginfo from 2 to 1 to help save disk space
32eba8b6baSopenharmony_ciset_env("CARGO_PROFILE_DEV_DEBUG", "1");
33eba8b6baSopenharmony_ciset_env("CARGO_PROFILE_TEST_DEBUG", "1");
34eba8b6baSopenharmony_ci
35eba8b6baSopenharmony_ciif (process.platform === 'darwin') {
36eba8b6baSopenharmony_ci  set_env("CARGO_PROFILE_DEV_SPLIT_DEBUGINFO", "unpacked");
37eba8b6baSopenharmony_ci  set_env("CARGO_PROFILE_TEST_SPLIT_DEBUGINFO", "unpacked");
38eba8b6baSopenharmony_ci}
39