Skip to content

Commit

Permalink
Test build for rust-lang/cc-rs#1176
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Aug 10, 2024
1 parent 040bd38 commit 5b050d1
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 57 deletions.
4 changes: 2 additions & 2 deletions build/cargo-c.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ PKG := cargo-c
$(PKG)_WEBSITE := https://github.com/lu-zero/cargo-c
$(PKG)_DESCR := cargo applet to build and install C-ABI compatibile libraries
$(PKG)_IGNORE :=
$(PKG)_VERSION := 0.10.2
$(PKG)_CHECKSUM := 0217c26fee99f3af867ce52719a39349d19ec6cfac084eea3901f8046f4607c6
$(PKG)_VERSION := 0.10.3
$(PKG)_CHECKSUM := 922171afb3ceaf6553ff3916ae4663d3743ba22f80725f2300a26b76eb6eb94f
$(PKG)_PATCHES := $(realpath $(sort $(wildcard $(dir $(lastword $(MAKEFILE_LIST)))/patches/$(PKG)-[0-9]*.patch)))
$(PKG)_GH_CONF := lu-zero/cargo-c/tags,v
$(PKG)_TARGETS := $(BUILD)
Expand Down
9 changes: 5 additions & 4 deletions build/overrides.mk
Original file line number Diff line number Diff line change
Expand Up @@ -560,16 +560,17 @@ define librsvg_BUILD
$(if $(IS_LLVM), \
cd '$(BUILD_DIR)' && \
MXE_ENABLE_NETWORK=1 \
cargo vendor --manifest-path '$(SOURCE_DIR)/Cargo.toml' -s '$(PREFIX)/$(BUILD)/lib/rustlib/src/rust/library/sysroot/Cargo.toml')
cargo vendor --manifest-path '$(SOURCE_DIR)/Cargo.toml' -s '$(PREFIX)/$(BUILD)/lib/rustlib/src/rust/library/Cargo.toml')

$(if $(IS_LLVM), \
(cd '$(BUILD_DIR)' && $(PATCH) -p1 -u) < $(realpath $(dir $(lastword $(librsvg_PATCHES))))/librsvg-llvm-mingw.patch \
# Update expected Cargo SHA256 hashes for the vendored files we have patched
$(SED) -i 's/ddb4a16b289d368cc5c02080e67e2fd66091eed0b8478dfdb05006469494f6b0/42daa223b23e5df3f03e9da95e1e61411bfe507cba5a403bb6b8867892a95db0/' '$(BUILD_DIR)/vendor/cfg-expr/.cargo-checksum.json'; \
$(SED) -i 's/666c050a52920a8eda20d9d2f2e645cb09660d5c17ce549c233a05c53ae6799b/525fa47360e61be4f017863ed397fd59ac23ac6e625175210efd2c96b7ae687c/' '$(BUILD_DIR)/vendor/compiler_builtins/.cargo-checksum.json'; \
$(SED) -i 's/995997abcd5cb764c07fb27c9e2af82f1b713d8ae0577fc9e2d9fff9a5b997e8/4c6478a4de07f25c72d3b62dee381ef706df0c4de0d363e2029c415508e873bc/' '$(BUILD_DIR)/vendor/compiler_builtins/.cargo-checksum.json'; \
$(SED) -i 's/d30364448703ab32cd2464745f9bbba314a7cee09c48f51027e532655b91b27b/58c03e8aea8836fabb019ede1e532e4839252e5194cc21abade4206786f986da/' '$(BUILD_DIR)/vendor/compiler_builtins/.cargo-checksum.json'; \
$(SED) -i 's/a7be2be8ecb1feaafd2c22847d27f1a86d1090e771bd7097af831b1c94ba5bb4/ad4a2305fce53f883715d22d6f1f7b5f2175bc4790fcd541a4b7059d74781fc0/' '$(BUILD_DIR)/vendor/compiler_builtins/.cargo-checksum.json'; \
$(SED) -i 's/204bc39a8213167dcab8dd273c57e5fae3afbac8fa3887dbe43ad082d55446e4/0e8c4e6440c5377f487918f16a8ea80aae53fa4d47e495a9e9c0119b575db0ab/' '$(BUILD_DIR)/vendor/windows-sys/.cargo-checksum.json'; \
$(SED) -i 's/92440d3adb5cb6ea05596d9ca860a205d3937dbf0fc959e524bac5f2b748c1af/d7c8f937883854fa016e98e408faaccecb4c88ec95a0d2bdcc5791d871032723/' '$(BUILD_DIR)/vendor/cc-1.0.99/.cargo-checksum.json'; \
$(SED) -i 's/92440d3adb5cb6ea05596d9ca860a205d3937dbf0fc959e524bac5f2b748c1af/553a632e29e3f5123891cbe73d67797093fb470822de027ad09bbe5e5a1e86b9/' '$(BUILD_DIR)/vendor/cc-1.0.99/.cargo-checksum.json'; \
$(SED) -i 's/342be00f6215e161d8163e272a2945bb9f52f171648e15e11d46800a73186955/f939a570c99d897fdd37cd491a4ee0657e2c7480ec71acbd9cbee48732d4bfbc/' '$(BUILD_DIR)/vendor/cc-1.0.99/.cargo-checksum.json'; \
# Install Cargo config
$(INSTALL) -d '$(BUILD_DIR)/.cargo'
(echo '[source.crates-io]'; \
Expand Down
46 changes: 45 additions & 1 deletion build/patches/cargo-c-0.10-fixes.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <github@kleisauke.nl>
Date: Sat, 2 Jan 2021 20:00:00 +0100
Subject: [PATCH 1/1] Add llvm-mingw armv7 dlltool target
Subject: [PATCH 1/2] Add llvm-mingw armv7 dlltool target

Upstream-Status: Inappropriate [enable feature]
armv7-pc-windows-gnullvm is not an officially supported Rust target.
Expand All @@ -18,3 +18,47 @@ index 1111111..2222222 100644
_ => unimplemented!("Windows support for {} is not implemented yet.", arch),
};

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <github@kleisauke.nl>
Date: Sat, 10 Aug 2024 11:43:45 +0200
Subject: [PATCH 2/2] Bump cargo to rust-lang/cargo@50237f4

To fix the build with `-Zbuild-std`.

diff --git a/Cargo.toml b/Cargo.toml
index 1111111..2222222 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -28,8 +28,8 @@ name = "cargo-ctest"
path = "src/bin/ctest.rs"

[dependencies]
-cargo = "0.81.0"
-cargo-util = "0.2"
+cargo = { git = "https://github.com/rust-lang/cargo.git", rev = "50237f4" }
+cargo-util = { git = "https://github.com/rust-lang/cargo.git", rev = "50237f4" }
semver = "1.0.3"
log = "0.4"
clap = { version = "4.0.29", features = ["color", "derive", "cargo", "string"] }
diff --git a/src/build.rs b/src/build.rs
index 1111111..2222222 100644
--- a/src/build.rs
+++ b/src/build.rs
@@ -1071,7 +1071,7 @@ pub fn cbuild(
let only_staticlib = !libkinds.contains(&"cdylib");
let only_cdylib = !libkinds.contains(&"staticlib");

- let profile = args.get_profile_name(config, default_profile, ProfileChecking::Custom)?;
+ let profile = args.get_profile_name(default_profile, ProfileChecking::Custom)?;

let profiles = Profiles::new(ws, profile)?;

@@ -1258,7 +1258,7 @@ pub fn ctest(
mut compile_opts: CompileOptions,
) -> CliResult {
compile_opts.build_config.requested_profile =
- args.get_profile_name(config, "test", ProfileChecking::Custom)?;
+ args.get_profile_name("test", ProfileChecking::Custom)?;
compile_opts.build_config.mode = CompileMode::Test;

compile_opts.filter = ops::CompileFilter::new(
65 changes: 40 additions & 25 deletions build/patches/librsvg-llvm-mingw.patch
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ diff --git a/vendor/compiler_builtins/build.rs b/vendor/compiler_builtins/build.
index 1111111..2222222 100644
--- a/vendor/compiler_builtins/build.rs
+++ b/vendor/compiler_builtins/build.rs
@@ -421,7 +421,7 @@ mod c {
@@ -502,7 +502,7 @@ mod c {
}
}

- if target_arch == "arm" && target_vendor != "apple" && target_env != "msvc" {
+ if target_arch == "arm" && target_vendor != "apple" && target_os != "windows" {
- if target.arch == "arm" && target.vendor != "apple" && target.env != "msvc" {
+ if target.arch == "arm" && target.vendor != "apple" && target.os != "windows" {
sources.extend(&[
("__aeabi_div0", "arm/aeabi_div0.c"),
("__aeabi_drsub", "arm/aeabi_drsub.c"),
Expand Down Expand Up @@ -247,38 +247,53 @@ index 1111111..2222222 100644
*self

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <github@kleisauke.nl>
Date: Mon, 29 Jul 2024 15:00:00 +0200
Subject: [PATCH 5/5] Ensure compatibility with LLVM 19
From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= <mati865@gmail.com>
Date: Sat, 10 Aug 2024 12:21:00 +0200
Subject: [PATCH 5/5] Remap Windows targets triples to their LLVM counterparts

See: https://github.com/rust-lang/cc-rs/issues/1167
Fixes https://github.com/rust-lang/cc-rs/issues/1167

Upstream-Status: Pending
Upstream-Status: Submitted [https://github.com/rust-lang/cc-rs/pull/1176]

diff --git a/vendor/cc-1.0.99/src/lib.rs b/vendor/cc-1.0.99/src/lib.rs
index 1111111..2222222 100644
--- a/vendor/cc-1.0.99/src/lib.rs
+++ b/vendor/cc-1.0.99/src/lib.rs
@@ -1889,7 +1889,10 @@ impl Build {
cmd.push_opt_unless_duplicate(format!("-O{}", opt_level).into());
}

- if cmd.is_like_clang() && target.contains("windows") {
+ if cmd.is_like_clang()
+ && target.contains("windows")
+ && !target.ends_with("-gnullvm")
+ {
// Disambiguate mingw and msvc on Windows. Problem is that
// depending on the origin clang can default to a mismatchig
// run-time.
@@ -2129,6 +2132,10 @@ impl Build {
@@ -2129,6 +2129,17 @@ impl Build {
}

cmd.push_cc_arg(format!("--target={}", target).into());
+ } else if target.ends_with("-gnullvm") {
+ cmd.push_cc_arg(
+ format!("--target={}", target.strip_suffix("llvm").unwrap()).into(),
+ );
+ } else if let Ok(index) = target_info::WINDOWS_TRIPLE_MAPPING
+ .binary_search_by_key(&target, |(target, _)| target)
+ {
+ cmd.args.push(
+ format!(
+ "--target={}-{}",
+ target_info::WINDOWS_TRIPLE_MAPPING[index].1,
+ rest
+ )
+ .into(),
+ )
} else {
cmd.push_cc_arg(format!("--target={}", target).into());
}
diff --git a/vendor/cc-1.0.99/src/target_info.rs b/vendor/cc-1.0.99/src/target_info.rs
index 1111111..2222222 100644
--- a/vendor/cc-1.0.99/src/target_info.rs
+++ b/vendor/cc-1.0.99/src/target_info.rs
@@ -12,3 +12,15 @@ pub const RISCV_ARCH_MAPPING: &[(&str, &str)] = &[
("riscv64gc", "riscv64"),
("riscv64imac", "riscv64"),
];
+pub const WINDOWS_TRIPLE_MAPPING: &[(&str, &str)] = &[
+ ("aarch64-pc-windows-gnullvm", "aarch64-pc-windows-gnu"),
+ ("aarch64-uwp-windows-msvc", "aarch64-pc-windows-msvc"),
+ ("i686-pc-windows-gnullvm", "i686-pc-windows-gnu"),
+ ("i686-uwp-windows-gnu", "i686-pc-windows-gnu"),
+ ("i686-uwp-windows-msvc", "i686-pc-windows-msvc"),
+ ("i686-win7-windows-msvc", "i686-pc-windows-msvc"),
+ ("thumbv7a-uwp-windows-msvc", "thumbv7a-pc-windows-msvc"),
+ ("x86_64-pc-windows-gnullvm", "x86_64-pc-windows-gnu"),
+ ("x86_64-uwp-windows-gnu", "x86_64-pc-windows-gnu"),
+ ("x86_64-uwp-windows-msvc", "x86_64-pc-windows-msvc"),
+];
71 changes: 67 additions & 4 deletions build/plugins/llvm-mingw/patches/rust-1-fixes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Contains ad hoc patches for cross building.
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <github@kleisauke.nl>
Date: Tue, 15 Sep 2020 11:50:00 +0200
Subject: [PATCH 1/4] Add `armv7-pc-windows-gnullvm` triple
Subject: [PATCH 1/5] Add `armv7-pc-windows-gnullvm` triple

Upstream-Status: Pending

Expand Down Expand Up @@ -54,7 +54,7 @@ index 1111111..2222222 100644
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <github@kleisauke.nl>
Date: Tue, 22 Sep 2020 10:00:00 +0200
Subject: [PATCH 2/4] std/unwind: Fix linker errors on `armv7-pc-windows-gnullvm`
Subject: [PATCH 2/5] std/unwind: Fix linker errors on `armv7-pc-windows-gnullvm`

Details:
ld.lld: error: undefined symbol: __gnu_unwind_frame
Expand Down Expand Up @@ -106,7 +106,7 @@ index 1111111..2222222 100644
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <github@kleisauke.nl>
Date: Tue, 30 Aug 2022 23:20:27 +0200
Subject: [PATCH 3/4] windows-gnullvm: Avoid linking to libunwind statically
Subject: [PATCH 3/5] windows-gnullvm: Avoid linking to libunwind statically

Avoid linking against the static variant of libunwind, which is not
always available. Instead, prefer to use the unwind library from the
Expand Down Expand Up @@ -155,7 +155,7 @@ index 1111111..2222222 100644
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <github@kleisauke.nl>
Date: Mon, 17 Oct 2022 11:50:00 +0200
Subject: [PATCH 4/4] Use GCC-style unwinding on MinGW targets other than i686
Subject: [PATCH 4/5] Use GCC-style unwinding on MinGW targets other than i686

See: https://github.com/msys2/MINGW-packages/pull/13278

Expand Down Expand Up @@ -200,3 +200,66 @@ index 1111111..2222222 100644
// We declare these as opaque types. This is fine since you just need to
// pass them to _GCC_specific_handler and forget about them.
pub enum EXCEPTION_RECORD {}

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <github@kleisauke.nl>
Date: Tue, 16 Apr 2024 15:51:34 +0000
Subject: [PATCH 5/5] std: revert use of `raw-dylib`

See: https://github.com/msys2/MINGW-packages/issues/21017

diff --git a/library/std/src/sys/pal/windows/c.rs b/library/std/src/sys/pal/windows/c.rs
index 1111111..2222222 100644
--- a/library/std/src/sys/pal/windows/c.rs
+++ b/library/std/src/sys/pal/windows/c.rs
@@ -112,7 +112,7 @@ pub struct MOUNT_POINT_REPARSE_BUFFER {

// Use raw-dylib to import ProcessPrng as we can't rely on there being an import library.
cfg_if::cfg_if! {
-if #[cfg(not(target_vendor = "win7"))] {
+if #[cfg(any())] {
#[cfg(target_arch = "x86")]
#[link(name = "bcryptprimitives", kind = "raw-dylib", import_name_type = "undecorated")]
extern "system" {
@@ -157,19 +157,7 @@ pub fn GetTempPath2W(bufferlength: u32, buffer: PWSTR) -> u32 {
}

#[cfg(not(target_vendor = "win7"))]
-// Use raw-dylib to import synchronization functions to workaround issues with the older mingw import library.
-#[cfg_attr(
- target_arch = "x86",
- link(
- name = "api-ms-win-core-synch-l1-2-0",
- kind = "raw-dylib",
- import_name_type = "undecorated"
- )
-)]
-#[cfg_attr(
- not(target_arch = "x86"),
- link(name = "api-ms-win-core-synch-l1-2-0", kind = "raw-dylib")
-)]
+#[link(name = "synchronization")]
extern "system" {
pub fn WaitOnAddress(
address: *const c_void,
diff --git a/library/std/src/sys/pal/windows/rand.rs b/library/std/src/sys/pal/windows/rand.rs
index 1111111..2222222 100644
--- a/library/std/src/sys/pal/windows/rand.rs
+++ b/library/std/src/sys/pal/windows/rand.rs
@@ -2,7 +2,7 @@

use crate::sys::c;

-#[cfg(not(target_vendor = "win7"))]
+#[cfg(any())]
#[inline]
pub fn hashmap_random_keys() -> (u64, u64) {
let mut v = (0, 0);
@@ -13,7 +13,6 @@ pub fn hashmap_random_keys() -> (u64, u64) {
v
}

-#[cfg(target_vendor = "win7")]
pub fn hashmap_random_keys() -> (u64, u64) {
use crate::ffi::c_void;
use crate::io;
28 changes: 7 additions & 21 deletions build/plugins/llvm-mingw/rust.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ PKG := rust
$(PKG)_WEBSITE := https://www.rust-lang.org/
$(PKG)_DESCR := A systems programming language focused on safety, speed and concurrency.
$(PKG)_IGNORE :=
# https://static.rust-lang.org/dist/2024-08-05/rustc-nightly-src.tar.xz.sha256
# https://static.rust-lang.org/dist/2024-08-10/rustc-nightly-src.tar.xz.sha256
$(PKG)_VERSION := nightly
$(PKG)_CHECKSUM := 49657b6ce056360c7d9e3b9e619761ddd2c7b41b98f18b34232e6da9d9f1fa55
$(PKG)_CHECKSUM := 9ed5c76d3e6b324838af0151f4c97843f94a9f3620a60eb16cb1f9a67d0d2536
$(PKG)_PATCHES := $(realpath $(sort $(wildcard $(dir $(lastword $(MAKEFILE_LIST)))/patches/$(PKG)-[0-9]*.patch)))
$(PKG)_SUBDIR := $(PKG)c-$($(PKG)_VERSION)-src
$(PKG)_FILE := $(PKG)c-$($(PKG)_VERSION)-src.tar.xz
$(PKG)_URL := https://static.rust-lang.org/dist/2024-08-05/$($(PKG)_FILE)
$(PKG)_URL := https://static.rust-lang.org/dist/2024-08-10/$($(PKG)_FILE)
$(PKG)_DEPS := $(BUILD)~$(PKG)
$(PKG)_TARGETS := $(BUILD) $(MXE_TARGETS)

Expand All @@ -32,20 +32,11 @@ define $(PKG)_BUILD_$(BUILD)
$(eval unexport CXXFLAGS)
$(eval unexport LDFLAGS)

# ld.lld: error: librsvg_c_api.a(bcryptprimitives.dll): .idata$4 should not refer to special section 0
(cd '$(SOURCE_DIR)' && $(PATCH) -p1 -u) < \
'$(SOURCE_DIR)/compiler/rustc_codegen_cranelift/patches/0029-stdlib-rawdylib-processprng.patch'

# libtool: error: object name conflicts in archive: .libs/librsvg-2.lax/librsvg_c_api.a//<<BUILDDIR>>/./.libs/librsvg_c_api.a
(cd '$(SOURCE_DIR)' && $(PATCH) -p1 -u) < \
'$(SOURCE_DIR)/compiler/rustc_codegen_cranelift/patches/0030-stdlib-Revert-use-raw-dylib-for-Windows-futex-APIs.patch'

# TODO(kleisauke): Build with --enable-vendor if we are no longer
# patching panic_unwind/unwind.
cd '$(BUILD_DIR)' && $(SOURCE_DIR)/configure \
--prefix='$(PREFIX)/$(BUILD)' \
--sysconfdir='etc' \
--release-channel=nightly \
--enable-vendor \
--enable-extended \
--tools=cargo,src \
--disable-docs \
Expand All @@ -72,11 +63,6 @@ define $(PKG)_BUILD_$(BUILD)
cd '$(BUILD_DIR)' && \
$(PYTHON3) $(SOURCE_DIR)/x.py install --stage 1 -j '$(JOBS)' -v

# Copy the Cargo.lock for Rust to places `vendor` will see
# https://github.com/rust-lang/wg-cargo-std-aware/issues/23#issuecomment-720455524
# https://github.com/rust-lang/cargo/pull/12088
cp '$(PREFIX)/$(BUILD)/lib/rustlib/src/rust/Cargo.lock' '$(PREFIX)/$(BUILD)/lib/rustlib/src/rust/library/sysroot'

# `c` feature of the `compiler-builtins` crate needs the
# compiler-rt sources from LLVM
$(call PREPARE_PKG_SOURCE,llvm,$(BUILD_DIR))
Expand All @@ -89,7 +75,7 @@ define $(PKG)_BUILD

# Build and prepare startup objects like rsbegin.o and rsend.o
$(foreach FILE, rsbegin rsend, \
$(PREFIX)/$(BUILD)/bin/rustc -Ainternal_features --target='$(TARGET_RUST)' --emit=obj -o '$(BUILD_DIR)/$(FILE).o' \
$(PREFIX)/$(BUILD)/bin/rustc --target='$(TARGET_RUST)' --emit=obj -o '$(BUILD_DIR)/$(FILE).o' \
'$(PREFIX)/$(BUILD)/lib/rustlib/src/rust/library/rtstartup/$(FILE).rs';)

# Install the startup objects
Expand All @@ -107,7 +93,7 @@ define $(PKG)_BUILD
echo 'CC_$(TARGET_RUST) = "$(TARGET)-clang"'; \
echo 'RUST_COMPILER_RT_ROOT = "$(PREFIX)/$(BUILD)/lib/rustlib/src/rust/src/llvm-project/compiler-rt"'; \
echo '[target.$(TARGET_RUST)]'; \
echo 'linker = "$(TARGET)-clang"'; \
echo 'ar = "$(PREFIX)/$(BUILD)/bin/llvm-ar"';) \
echo 'ar = "$(PREFIX)/$(BUILD)/bin/llvm-ar"'; \
echo 'linker = "$(TARGET)-clang"';) \
> '$(PREFIX)/$(TARGET)/.cargo/config.toml'
endef

0 comments on commit 5b050d1

Please sign in to comment.