windows fixes

This commit is contained in:
Anton-4 2022-11-14 19:37:25 +01:00
parent 39b10f0dc8
commit 29230921e6
No known key found for this signature in database
GPG Key ID: A13F4A6E21141925
3 changed files with 114 additions and 95 deletions

View File

@ -1,52 +1,55 @@
on: [pull_request]
name: Test windows build
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
RUST_BACKTRACE: 1
jobs:
windows-cargo-build:
name: windows-cargo-build
runs-on: windows-2022
env:
LLVM_SYS_130_PREFIX: C:\LLVM-13.0.1-win64
timeout-minutes: 150
steps:
- uses: actions/checkout@v2
- run: Add-Content -Path "$env:GITHUB_ENV" -Value "GITHUB_RUNNER_CPU=$((Get-CimInstance Win32_Processor).Name)"
- uses: Swatinem/rust-cache@v2
with:
shared-key: "rust-cache-windows-${{env.GITHUB_RUNNER_CPU}}"
- name: download and install zig
run: |
curl.exe --output "C:\zig-windows-x86_64-0.9.1.zip" --url https://ziglang.org/download/0.9.1/zig-windows-x86_64-0.9.1.zip
cd C:\
7z x zig-windows-x86_64-0.9.1.zip
Add-Content $env:GITHUB_PATH "C:\zig-windows-x86_64-0.9.1\"
- name: zig version
run: zig version
- name: set up llvm 13
run: |
curl.exe -L -O https://github.com/roc-lang/llvm-package-windows/releases/download/v13.0.1/LLVM-13.0.1-win64.7z
7z x LLVM-13.0.1-win64.7z -oC:\LLVM-13.0.1-win64
- name: Build tests --release without running. Twice for zig lld-link error.
run: cargo test --locked --release --no-run || cargo test --locked --release --no-run
# Why are these tests not build with previous command? => fingerprint error. Use `CARGO_LOG=cargo::core::compiler::fingerprint=info` to investigate
- name: Build specific tests without running. Twice for zig lld-link error.
run: cargo test --locked --release --no-run -p roc_ident -p roc_region -p roc_collections -p roc_can -p roc_types -p roc_solve -p roc_mono -p roc_gen_dev -p roc_gen_wasm -p roc_serialize -p roc_editor -p roc_linker -p roc_cli || cargo test --locked --release --no-run -p roc_ident -p roc_region -p roc_collections -p roc_can -p roc_types -p roc_solve -p roc_mono -p roc_gen_dev -p roc_gen_wasm -p roc_serialize -p roc_editor -p roc_linker -p roc_cli
- name: Actually run the tests.
run: cargo test --locked --release -p roc_ident -p roc_region -p roc_collections -p roc_can -p roc_types -p roc_solve -p roc_mono -p roc_gen_dev -p roc_gen_wasm -p roc_serialize -p roc_editor -p roc_linker -p roc_cli
on: [pull_request]
name: Test windows build
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
RUST_BACKTRACE: 1
jobs:
windows-cargo-build:
name: windows-cargo-build
runs-on: windows-2022
env:
LLVM_SYS_130_PREFIX: C:\LLVM-13.0.1-win64
timeout-minutes: 150
steps:
- uses: actions/checkout@v2
- run: Add-Content -Path "$env:GITHUB_ENV" -Value "GITHUB_RUNNER_CPU=$((Get-CimInstance Win32_Processor).Name)"
- uses: Swatinem/rust-cache@v2
with:
shared-key: "rust-cache-windows-${{env.GITHUB_RUNNER_CPU}}"
- name: download and install zig
run: |
curl.exe --output "C:\zig-windows-x86_64-0.9.1.zip" --url https://ziglang.org/download/0.9.1/zig-windows-x86_64-0.9.1.zip
cd C:\
7z x zig-windows-x86_64-0.9.1.zip
Add-Content $env:GITHUB_PATH "C:\zig-windows-x86_64-0.9.1\"
- name: zig version
run: zig version
- name: install rust nightly 1.64
run: rustup install nightly-2022-08-06
- name: set up llvm 13
run: |
curl.exe -L -O https://github.com/roc-lang/llvm-package-windows/releases/download/v13.0.1/LLVM-13.0.1-win64.7z
7z x LLVM-13.0.1-win64.7z -oC:\LLVM-13.0.1-win64
- name: Build tests --release without running. Twice for zig lld-link error.
run: cargo test --locked --release --no-run || cargo test --locked --release --no-run
# Why are these tests not build with previous command? => fingerprint error. Use `CARGO_LOG=cargo::core::compiler::fingerprint=info` to investigate
- name: Build specific tests without running. Twice for zig lld-link error.
run: cargo test --locked --release --no-run -p roc_ident -p roc_region -p roc_collections -p roc_can -p roc_types -p roc_solve -p roc_mono -p roc_gen_dev -p roc_gen_wasm -p roc_serialize -p roc_editor -p roc_linker -p roc_cli || cargo test --locked --release --no-run -p roc_ident -p roc_region -p roc_collections -p roc_can -p roc_types -p roc_solve -p roc_mono -p roc_gen_dev -p roc_gen_wasm -p roc_serialize -p roc_editor -p roc_linker -p roc_cli
- name: Actually run the tests.
run: cargo test --locked --release -p roc_ident -p roc_region -p roc_collections -p roc_can -p roc_types -p roc_solve -p roc_mono -p roc_gen_dev -p roc_gen_wasm -p roc_serialize -p roc_editor -p roc_linker -p roc_cli

View File

@ -186,11 +186,15 @@ pub fn build_zig_host_native(
opt_level: OptLevel,
shared_lib_path: Option<&Path>,
) -> Command {
// to prevent `clang failed with stderr: zig: error: unable to make temporary file: No such file or directory`
let env_userprofile = env::var("USERPROFILE").unwrap_or_else(|_| "".to_string());
let mut zig_cmd = zig();
zig_cmd
.env_clear()
.env("PATH", env_path)
.env("HOME", env_home);
.env("HOME", env_home)
.env("USERPROFILE", env_userprofile);
if let Some(shared_lib_path) = shared_lib_path {
zig_cmd.args(&[
@ -419,7 +423,7 @@ pub fn build_c_host_native(
dest,
sources[0],
find_zig_str_path().to_str().unwrap(),
"x86_64-windows-gnu",
get_target_str(target),
opt_level,
Some(shared_lib_path),
);
@ -578,23 +582,16 @@ pub fn rebuild_host(
shared_lib_path,
)
}
Architecture::X86_64 => {
let target = match target.operating_system {
OperatingSystem::Windows => "x86_64-windows-gnu",
_ => "native",
};
build_zig_host_native(
&env_path,
&env_home,
host_dest.to_str().unwrap(),
zig_host_src.to_str().unwrap(),
zig_str_path.to_str().unwrap(),
target,
opt_level,
shared_lib_path,
)
}
Architecture::X86_64 => build_zig_host_native(
&env_path,
&env_home,
host_dest.to_str().unwrap(),
zig_host_src.to_str().unwrap(),
zig_str_path.to_str().unwrap(),
get_target_str(target),
opt_level,
shared_lib_path,
),
Architecture::X86_32(_) => build_zig_host_native(
&env_path,
&env_home,
@ -636,7 +633,7 @@ pub fn rebuild_host(
// on windows, we need the nightly toolchain so we can use `-Z export-executable-symbols`
// using `+nightly` only works when running cargo through rustup
let mut cmd = rustup();
cmd.args(["run", "nightly", "cargo"]);
cmd.args(["run", "nightly-2022-08-06", "cargo"]);
cmd
} else {
@ -807,6 +804,16 @@ pub fn rebuild_host(
host_dest
}
fn get_target_str(target: &Triple) -> &str {
if target.operating_system == OperatingSystem::Windows
&& target.environment == target_lexicon::Environment::Gnu
{
"x86_64-windows-gnu"
} else {
"native"
}
}
fn nix_path_opt() -> Option<String> {
env::var_os("NIX_GLIBC_PATH").map(|path| path.into_string().unwrap())
}
@ -1227,7 +1234,7 @@ fn link_wasm32(
}
fn link_windows(
_target: &Triple,
target: &Triple,
output_path: PathBuf,
input_paths: &[&str],
link_type: LinkType,
@ -1263,7 +1270,7 @@ fn link_windows(
.args(input_paths)
.args([
"-target",
"x86_64-windows-gnu",
get_target_str(target),
"--subsystem",
"console",
"-lc",
@ -1386,24 +1393,26 @@ fn run_build_command(mut command: Command, file_to_build: &str, flaky_fail_count
match std::str::from_utf8(&cmd_output.stderr) {
Ok(stderr) => {
// flaky error seen on macos 12 apple silicon, related to https://github.com/ziglang/zig/issues/9711
if stderr.contains("unable to save cached ZIR code") && flaky_fail_counter < max_flaky_fail_count {
run_build_command(command, file_to_build, flaky_fail_counter + 1)
if stderr.contains("unable to save cached ZIR code") {
if flaky_fail_counter < max_flaky_fail_count {
run_build_command(command, file_to_build, flaky_fail_counter + 1)
} else {
internal_error!(
"Error:\n Failed to rebuild {} {} times, this is not a flaky failure:\n The executed command was:\n {}\n stderr of that command:\n {}",
file_to_build,
max_flaky_fail_count,
cmd_str,
stderr
)
}
} else {
internal_error!(
"Error:\n Failed to rebuild {} {} times, this is not a flaky failure:\n The executed command was:\n {}\n stderr of that command:\n {}",
"Error:\n Failed to rebuild {}:\n The executed command was:\n {}\n stderr of that command:\n {}",
file_to_build,
max_flaky_fail_count,
cmd_str,
stderr
)
}
internal_error!(
"Error:\n Failed to rebuild {}:\n The executed command was:\n {}\n stderr of that command:\n {}",
file_to_build,
cmd_str,
stderr
)
},
Err(utf8_err) => internal_error!(
"Error:\n Failed to rebuild {}:\n The executed command was:\n {}\n stderr of that command could not be parsed as valid utf8:\n {}",

View File

@ -1,10 +1,17 @@
[toolchain]
channel = "1.64.0" # when changing this, update the date below with the last nightly with matching version using the link below
# https://github.com/oxalica/rust-overlay/tree/master/manifests/nightly/2022
# channel = "nightly-2022-08-06" # 1.64 nightly to be able to use unstable features
profile = "default"
components = [
# for usages of rust-analyzer or similar tools inside `nix develop`
"rust-src"
]
targets = [ "x86_64-unknown-linux-gnu" ]
[toolchain]
# How to update version:
# - update `channel = "RUST_VERSION"`
# - to update the nightly version:
# - Find the latest nightly release that matches RUST_VERSION here: https://github.com/oxalica/rust-overlay/tree/master/manifests/nightly/2022
# - update `channel = "nightly-OLD_DATE"` below
# - update nightly-OLD_DATE in .github/workflows/windows.yml
# - update nightly-OLD_DATE in crates/compiler/build/src/link.rs
channel = "1.64.0" # check ^^^ when changing this
#
# channel = "nightly-2022-08-06" # 1.64 nightly to be able to use unstable features
profile = "default"
components = [
# for usages of rust-analyzer or similar tools inside `nix develop`
"rust-src"
]