Control: tags -1 + patch


On Tue, Aug 8 2023 at 06:22:28 PM -04:00:00, Andres Salomon <[email protected]> wrote:
Package: src:rustc
Version: 1.66.0+dfsg1-1
Severity: wishlist

Chromium's new rust build requirements include the need for /usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/libprofiler_builtins-*.rlib. It would be really helpful to have this built into Debian's rust packages.

Ubuntu apparently enabled it, and you can see their patch here:
<https://git.launchpad.net/~canonical-foundations/ubuntu/+source/rustc/commit/?id=2a926a400334303921a379328cf3fcbbfc247f90>

However, that didn't work for me, at least not with the default of BUILD_WINDOWS=true in rustc's current debian/rules. The build involving --target $(WINDOWS_ARCH)-pc-windows-gnu requires libclang-rt-15-dev-wasm64 and some extra logic. I'm currently working on an updated patch now.





Alright, here's a patch that builds in sid. I don't know exactly whether the stuff with wasi targets are okay building against libclang-rt-15-dev (amd64 package), or if it's supposed to be using the two dev-wasm packages, but I assumed the wasm packages. I'm also not sure if the versioned build-deps in the ubuntu patch are necessary, but I didn't include them.

This patch adds "cargo:rustc-link-search=/usr/lib/clang/15/lib/linux/" and "cargo:rustc-link-lib=static=clang_rt.profile-x86_64" (or whatever architecture it happens to be building on) to the profiler_builtins build flags when the target matches the host. In the case where the target is different from the host, it assumes a wasm build and sets "rustc-link-lib=static=clang_rt.builtins-wasm32" or "cargo:rustc-link-lib=static=clang_rt.builtins-wasm64" depending upon whether the target is 32 or 64 bits, respectively.

Along with sid, I'd also obviously love to see this in bookworm - but given that chromium in bullseye gets another 5 months of support, I'm still trying to figure out our options.



diff -urN a/debian/changelog b/debian/changelog
--- a/debian/changelog	2023-06-27 15:12:20.000000000 +0000
+++ b/debian/changelog	2023-08-09 00:17:21.192106183 +0000
@@ -1,3 +1,10 @@
+rustc (1.66.0+dfsg1-1.1) unstable; urgency=medium
+
+  * NMU
+  * add profiler.patch and profiler=true.
+
+ -- Andres Salomon <[email protected]>  Mon, 07 Aug 2023 22:23:05 +0000
+
 rustc (1.66.0+dfsg1-1) unstable; urgency=medium
 
   * Upload to unstable
diff -urN a/debian/config.toml.in b/debian/config.toml.in
--- a/debian/config.toml.in	2023-06-20 18:22:34.000000000 +0000
+++ b/debian/config.toml.in	2023-08-09 00:17:21.192106183 +0000
@@ -5,6 +5,7 @@
 vendor = true
 locked-deps = false
 verbose = VERBOSITY
+profiler = true
 
 rustc = "RUST_DESTDIR/usr/bin/rustc"
 cargo = "RUST_DESTDIR/usr/bin/cargo"
diff -urN a/debian/control b/debian/control
--- a/debian/control	2023-06-27 15:11:38.000000000 +0000
+++ b/debian/control	2023-08-09 00:17:21.192106183 +0000
@@ -18,6 +18,9 @@
  rustc:native (<= 1.66.0++)    <!pkg.rustc.dlstage0>,
  llvm-15-dev:native,
  llvm-15-tools:native,
+ libclang-rt-15-dev,
+ libclang-rt-15-dev-wasm32,
+ libclang-rt-15-dev-wasm64,
  gcc-mingw-w64-x86-64-posix:native [amd64] <!nowindows>,
  gcc-mingw-w64-i686-posix:native [i386] <!nowindows>,
  libllvm15 (>= 1:15.0.0),
diff -urN a/debian/patches/profiler.patch b/debian/patches/profiler.patch
--- a/debian/patches/profiler.patch	1970-01-01 00:00:00.000000000 +0000
+++ b/debian/patches/profiler.patch	2023-08-09 00:17:21.196106193 +0000
@@ -0,0 +1,27 @@
+--- a/library/profiler_builtins/build.rs
++++ b/library/profiler_builtins/build.rs
+@@ -7,6 +7,24 @@ use std::path::Path;
+ 
+ fn main() {
+     let target = env::var("TARGET").expect("TARGET was not set");
++    // use system profiler runtime if possible
++    println!(
++        "cargo:rustc-link-search=/usr/lib/clang/{}/lib/{}/",
++        env::var("DEB_LLVM_VERSION").unwrap(),
++        env::var("DEB_CLANG_RT_OS").unwrap()
++    );
++    if target == std::env::var("HOST").unwrap() {
++        println!(
++            "cargo:rustc-link-lib=static=clang_rt.profile-{}",
++            env::var("DEB_CLANG_RT_ARCH").unwrap()
++        );
++        return;
++    } else {
++        println!("cargo:rustc-link-lib=static=clang_rt.builtins-wasm{}",
++            if env::var("DEB_CLANG_RT_ARCH").unwrap() == "x86_64" { "64" } else { "32" }
++        );
++        return;
++    }
+     let cfg = &mut cc::Build::new();
+ 
+     // FIXME: `rerun-if-changed` directives are not currently emitted and the build script
diff -urN a/debian/patches/series b/debian/patches/series
--- a/debian/patches/series	2023-06-27 15:11:38.000000000 +0000
+++ b/debian/patches/series	2023-08-09 00:17:21.196106193 +0000
@@ -19,6 +19,7 @@
 
 # Debian-specific patches, not suitable for upstream
 d-fix-rustix-outline.patch
+profiler.patch
 
 ## Patches needed by debian/prune-unused-deps, for building bootstrap
 d-0000-ignore-removed-submodules.patch
diff -urN a/debian/rules b/debian/rules
--- a/debian/rules	2023-06-20 18:22:34.000000000 +0000
+++ b/debian/rules	2023-08-09 00:19:00.740358977 +0000
@@ -30,6 +30,21 @@
 # Use system LLVM (comment out to use vendored LLVM)
 LLVM_VERSION = 15
 OLD_LLVM_VERSION = 14
+CLANG_RT_ARCH := $(DEB_TARGET_GNU_CPU)
+CLANG_RT_OS := $(word 2,$(subst -, ,$(DEB_TARGET_GNU_TYPE)))
+ifeq (windows,$(CLANG_RT_OS))
+CLANG_RT_OS := wasi
+endif
+ifeq (i386,$(DEB_TARGET_ARCH))
+CLANG_RT_ARCH = i386
+endif
+ifeq (armhf,$(DEB_TARGET_ARCH))
+CLANG_RT_ARCH = armhf
+endif
+export DEB_LLVM_VERSION = $(LLVM_VERSION)
+export DEB_CLANG_RT_ARCH = $(CLANG_RT_ARCH)
+export DEB_CLANG_RT_OS = $(CLANG_RT_OS)
+
 # Make it easier to test against a custom LLVM
 ifneq (,$(LLVM_DESTDIR))
 LLVM_LIBRARY_PATH := $(LLVM_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH):$(LLVM_DESTDIR)/usr/lib
@@ -254,7 +269,7 @@
 
 override_dh_auto_build-arch: debian/dh_auto_build.stamp
 ifeq (true,$(BUILD_WINDOWS))
-	$(RUSTBUILD) build $(RUSTBUILD_FLAGS) \
+	DEB_CLANG_RT_OS=wasi $(RUSTBUILD) build $(RUSTBUILD_FLAGS) \
 	  --host $(DEB_BUILD_RUST_TYPE) \
 	  --target $(WINDOWS_ARCH)-pc-windows-gnu \
 	  library/std
@@ -262,7 +277,7 @@
 
 override_dh_auto_build-indep: debian/dh_auto_build.stamp
 ifeq (true,$(BUILD_WASM))
-	$(RUSTBUILD) build $(RUSTBUILD_FLAGS) \
+	DEB_CLANG_RT_OS=wasi DEB_CLANG_RT_ARCH=i386 $(RUSTBUILD) build $(RUSTBUILD_FLAGS) \
 	  --host $(DEB_BUILD_RUST_TYPE) \
 	  --target wasm32-unknown-unknown,wasm32-wasi \
 	  library/std
@@ -380,7 +395,7 @@
 
 override_dh_auto_install-arch: debian/dh_auto_install.stamp
 ifeq (true,$(BUILD_WINDOWS))
-	DESTDIR=$(DEB_DESTDIR) $(RUSTBUILD) install $(RUSTBUILD_FLAGS) \
+	DEB_CLANG_RT_OS=wasi DESTDIR=$(DEB_DESTDIR) $(RUSTBUILD) install $(RUSTBUILD_FLAGS) \
 	  --host $(DEB_BUILD_RUST_TYPE) \
 	  --target $(WINDOWS_ARCH)-pc-windows-gnu \
 	  library/std
@@ -388,7 +403,7 @@
 
 override_dh_auto_install-indep: debian/dh_auto_install.stamp
 ifeq (true,$(BUILD_WASM))
-	DESTDIR=$(DEB_DESTDIR) $(RUSTBUILD) install $(RUSTBUILD_FLAGS) \
+	DEB_CLANG_RT_OS=wasi DEB_CLANG_RT_ARCH=i386 DESTDIR=$(DEB_DESTDIR) $(RUSTBUILD) install $(RUSTBUILD_FLAGS) \
 	  --host $(DEB_BUILD_RUST_TYPE) \
 	  --target wasm32-unknown-unknown,wasm32-wasi \
 	  library/std

Reply via email to