[packages/meson] add patch to filter out --target for rust proc-macro crate

atler atler at pld-linux.org
Wed Oct 11 21:19:17 CEST 2023


commit f2046c6dbfa2aee1b32d8ff60d4a04c6365e4a6a
Author: Jan Palus <atler at pld-linux.org>
Date:   Wed Oct 11 21:04:56 2023 +0200

    add patch to filter out --target for rust proc-macro crate
    
    proc-macro is used directly by a host compiler so during its compilation
    target should match host triplet see:
    
    https://github.com/rust-lang/rust/issues/116562
    
    the easiest way to achieve this is to skip --target entirely as by
    default it will produce artifact matching host.
    
    since meson upstream prefers to use full blown cross-compilation for
    tiers without host tools:
    
    https://github.com/mesonbuild/meson/issues/12353
    
    let's patch meson ourselves for convinience to avoid it

 meson.spec                              |  2 ++
 rust-proc-macro-filter-out-target.patch | 52 +++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)
---
diff --git a/meson.spec b/meson.spec
index 9093a48..588d09f 100644
--- a/meson.spec
+++ b/meson.spec
@@ -9,6 +9,7 @@ Group:		Development/Tools
 Source0:	https://github.com/mesonbuild/meson/releases/download/%{version}/%{name}-%{version}.tar.gz
 # Source0-md5:	702bfd8b0648521322d3f145a8fc70ea
 Patch0:		%{name}-gtkdocdir.patch
+Patch1:		rust-proc-macro-filter-out-target.patch
 URL:		https://mesonbuild.com/
 BuildRequires:	ninja >= 1.8.2
 BuildRequires:	python3 >= 1:3.7
@@ -54,6 +55,7 @@ Mesona.
 %prep
 %setup -q
 %patch0 -p1
+%patch1 -p1
 
 %{__sed} -i -e '1s,/usr/bin/env python3,%{__python3},' \
 	meson.py
diff --git a/rust-proc-macro-filter-out-target.patch b/rust-proc-macro-filter-out-target.patch
new file mode 100644
index 0000000..11d97b4
--- /dev/null
+++ b/rust-proc-macro-filter-out-target.patch
@@ -0,0 +1,52 @@
+From ace34a0d5e4d27f0eb4e0b6f756e10dfd04e1ff9 Mon Sep 17 00:00:00 2001
+From: Jan Palus <jpalus at fastmail.com>
+Date: Wed, 11 Oct 2023 19:40:48 +0200
+Subject: [PATCH] rust: filter out --target for proc-macro crate
+
+proc-macro is used directly by a host compiler so during its compilation
+target should match host triplet see:
+
+https://github.com/rust-lang/rust/issues/116562
+
+the easiest way to achieve this is to skip --target entirely as by
+default it will produce artifact matching host.
+
+since meson upstream prefers to use full blown cross-compilation for
+tiers without host tools:
+
+https://github.com/mesonbuild/meson/issues/12353
+
+let's patch meson ourselves for convinience to avoid it
+---
+ mesonbuild/backend/backends.py | 15 +++++++++++++++
+ 1 file changed, 15 insertions(+)
+
+diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
+index 73741a441..191db485d 100644
+--- a/mesonbuild/backend/backends.py
++++ b/mesonbuild/backend/backends.py
+@@ -1064,6 +1064,21 @@ class Backend:
+             for lt in chain(target.link_targets, target.link_whole_targets):
+                 priv_dir = self.get_target_private_dir(lt)
+                 commands += compiler.get_include_args(priv_dir, False)
++        # filter out --target arguments for host only proc-macro crate
++        if compiler.language == 'rust' and hasattr(target, 'rust_crate_type') and target.rust_crate_type == 'proc-macro':
++            target_commands = []
++            target_arg = False
++            for (i, v) in enumerate(commands):
++                if target_arg:
++                    target_commands.append(i)
++                    target_arg = False
++                elif v == '--target':
++                    target_commands.append(i)
++                    target_arg = True
++                elif v.startswith('--target='):
++                    target_commands.append(i)
++            for i in reversed(target_commands):
++                del commands[i]
+         return commands
+ 
+     def build_target_link_arguments(self, compiler: 'Compiler', deps: T.List[build.Target]) -> T.List[str]:
+-- 
+2.42.0
+
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/meson.git/commitdiff/f2046c6dbfa2aee1b32d8ff60d4a04c6365e4a6a



More information about the pld-cvs-commit mailing list