From d92a7e953910f281942c9ea55bd98b29ed94f883 Mon Sep 17 00:00:00 2001 From: messense Date: Sun, 10 Sep 2023 19:24:43 +0800 Subject: [PATCH] Fix Windows CMake `Invalid character escape '\U'` error --- .github/workflows/CI.yml | 11 +++++++++-- src/zig.rs | 23 +++++++++++++---------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 39acae6..dee21ae 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -76,7 +76,7 @@ jobs: if: matrix.toolchain != '1.63.0' shell: bash run: | - set -e + set -euo pipefail git clone --recurse-submodules https://github.com/gyscos/zstd-rs.git tests/zstd-rs cargo run zigbuild --manifest-path tests/zstd-rs/Cargo.toml --features bindgen --target aarch64-unknown-linux-gnu cargo run zigbuild --manifest-path tests/zstd-rs/Cargo.toml --features bindgen --target x86_64-pc-windows-gnu @@ -97,7 +97,7 @@ jobs: env: SDK: MacOSX11.3.sdk run: | - set -e + set -euo pipefail curl -sqL https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/$SDK.tar.xz | tar -Jx export SDKROOT=$PWD/$SDK @@ -127,7 +127,9 @@ jobs: ldd -r -v ./target/x86_64-unknown-linux-gnu/debug/cargo-zigbuild ./target/x86_64-unknown-linux-gnu/debug/cargo-zigbuild --help - name: Linux - Test glibc build + shell: bash run: | + set -euo pipefail cargo run zigbuild --target aarch64-unknown-linux-gnu cargo run zigbuild --target aarch64-unknown-linux-gnu.2.17 @@ -142,6 +144,7 @@ jobs: - name: Linux - Test glibc run/test if: matrix.os == 'ubuntu-latest' run: | + set -euo pipefail # Install qemu for `cargo-zigbuild run` support sudo apt-get update sudo apt-get install -y qemu-user qemu-user-static gcc-aarch64-linux-gnu binfmt-support @@ -160,7 +163,9 @@ jobs: cargo run zigbuild --target aarch64-unknown-linux-musl cargo run zigbuild --target aarch64-unknown-linux-musl --manifest-path tests/hello-rustls/Cargo.toml - name: Windows - Test gnu build + shell: bash run: | + set -euo pipefail cargo run zigbuild --target x86_64-pc-windows-gnu cargo run zigbuild --target x86_64-pc-windows-gnu --manifest-path tests/hello-windows/Cargo.toml cargo run zigbuild --target i686-pc-windows-gnu @@ -171,7 +176,9 @@ jobs: cargo run zigbuild --target aarch64-unknown-linux-gnu --manifest-path tests/hello-rustls/Cargo.toml --features curl - name: Windows - Test run if: matrix.os == 'windows-latest' + shell: bash run: | + set -euo pipefail ./target/x86_64-pc-windows-gnu/debug/cargo-zigbuild.exe zigbuild --help ./tests/hello-windows/target/x86_64-pc-windows-gnu/debug/hello-windows.exe diff --git a/src/zig.rs b/src/zig.rs index 48abd9b..0196aae 100644 --- a/src/zig.rs +++ b/src/zig.rs @@ -170,12 +170,10 @@ impl Zig { } } } - if is_macos { - if arg.starts_with("-Wl,--exported_symbols_list,") { - // zig doesn't support --exported_symbols_list arg - // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-exported_symbols_list - return None; - } + if is_macos && arg.starts_with("-Wl,--exported_symbols_list,") { + // zig doesn't support --exported_symbols_list arg + // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-exported_symbols_list + return None; } Some(arg.to_string()) }; @@ -863,16 +861,21 @@ impl Zig { set(CMAKE_SYSTEM_NAME {system_name}) set(CMAKE_SYSTEM_PROCESSOR {system_processor}) set(CMAKE_C_COMPILER {cc}) +set(CMAKE_C_LINK_EXECUTABLE {cc}) set(CMAKE_CXX_COMPILER {cxx}) +set(CMAKE_CXX_LINK_EXECUTABLE {cxx}) set(CMAKE_RANLIB {ranlib})"#, system_name = system_name, system_processor = system_processor, - cc = zig_wrapper.cc.display(), - cxx = zig_wrapper.cxx.display(), - ranlib = zig_wrapper.ranlib.display(), + cc = zig_wrapper.cc.to_slash_lossy(), + cxx = zig_wrapper.cxx.to_slash_lossy(), + ranlib = zig_wrapper.ranlib.to_slash_lossy(), ); if enable_zig_ar { - content.push_str(&format!("\nset(CMAKE_AR {})\n", zig_wrapper.ar.display())); + content.push_str(&format!( + "\nset(CMAKE_AR {})\n", + zig_wrapper.ar.to_slash_lossy() + )); } fs::write(&toolchain_file, content)?; Ok(toolchain_file)