Skip to content

Commit

Permalink
Fix Windows CMake Invalid character escape '\U' error
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Sep 10, 2023
1 parent ef2886e commit d92a7e9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
23 changes: 13 additions & 10 deletions src/zig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
};
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d92a7e9

Please sign in to comment.