tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

llvm-config and cross-builds

graphics/MesaLib links against libLLVM using parameters like CPPFLAGS
and LDFLAGS obtained from an llvm-specific `llvm-config' executable,
rather than from something more standard like pkg-config.

That's fine for native builds, but for cross builds, it's a problem
because llvm-config is not a shell script -- it's a cross-built
executable, which we can't run at build-time.  What to do?

To get graphics/MesaLib to cross-compile now that it depends on llvm,
I created a horrible hack with TOOLS_CREATE to override llvm-config
during the MesaLib build by a simple shell script with
TOOLS_SCRIPT.llvm-create that answers some known queries, like
`--cppflags' or `--ldflags', in a fixed way that I think is correct at

If anything else uses llvm-config, it'll need the same treatment.

What to do?

1. Just commit this as is because not much else uses llvm-config?

2. Create an under lang/libLLVM to do the same hack for
   any package that needs it?

   (Currently that might be dolphin-emu and xf86-video-vmware, judging
   by lang/libLLVM/ users, but there are also lots of
   lang/llvm/ users that might need the same treatment --
   at some point we'll need to teach pbulk to do cross-compilation and
   run some bulk cross-builds to shake all this out systematically.)

3. Something else?  Any prior art for cross-building programs or
   libraries that link against libLLVM?  Ideally something that can be
   derived automagically from the llvm build, rather than my
   hand-crufted guesses at the right query answers based on what I saw
   Mesa asking for in .work.log?

(Note: This patch also has a hack to pass a TOOLBASE-relative path to
wayland-scanner through, like the hack in the wayland build itself.
Not related to the present inquiry, although if you know a better way
to do this without patching meson build files, I'm all ears!)
From c33c7621a82e3008b008912a66c744aaffb66389 Mon Sep 17 00:00:00 2001
From: Taylor R Campbell <>
Date: Sat, 17 Jun 2023 22:03:43 +0000
Subject: [PATCH] WIP: graphics/MesaLib: Make this cross-compile.

Requires kludging up an `llvm-config' tool that runs at build-time.
The lang/libLLVM package installs an llvm-config tool, but it's
compiled to run on the target system, not on the build system, so it
doesn't work in cross-compiling.
 graphics/MesaLib/Makefile                     |  8 ++++++
 graphics/MesaLib/distinfo                     |  2 ++
 graphics/MesaLib/                   | 27 +++++++++++++++++++
 graphics/MesaLib/patches/    | 19 +++++++++++++
 .../MesaLib/patches/patch-meson__options.txt  | 17 ++++++++++++
 5 files changed, 73 insertions(+)
 create mode 100644 graphics/MesaLib/patches/
 create mode 100644 graphics/MesaLib/patches/patch-meson__options.txt

diff --git a/graphics/MesaLib/Makefile b/graphics/MesaLib/Makefile
index 054e8e723747..5d8d42db4427 100644
--- a/graphics/MesaLib/Makefile
+++ b/graphics/MesaLib/Makefile
@@ -181,6 +181,14 @@ PKGCONFIG_OVERRIDE+=		output/meson-private/osmesa.pc
 PKGCONFIG_OVERRIDE+=		output/meson-private/xatracker.pc
 PKGCONFIG_OVERRIDE+=		output/meson-private/gl.pc
+.include "../../mk/"
+.if ${USE_CROSS_COMPILE:tl} == "yes"
+# wayland-protocols abuses pc_sysrootdir in its .pc files, causing the
+# cross-destdir to be prefixed twice to paths.
 	${MV} ${DESTDIR}${PREFIX}/share/drirc.d/00-mesa-defaults.conf ${DESTDIR}${EGDIR}
 .if ${OPSYS} == "Darwin"
diff --git a/graphics/MesaLib/distinfo b/graphics/MesaLib/distinfo
index 21cb222120b4..6cac04b608c0 100644
--- a/graphics/MesaLib/distinfo
+++ b/graphics/MesaLib/distinfo
@@ -3,6 +3,8 @@ $NetBSD: distinfo,v 1.164 2022/07/07 14:05:25 wiz Exp $
 BLAKE2s (mesa-21.3.9.tar.xz) = e948a37881a088c0df4df880e3d1218b874ed5a8cac951a109249b3648519472
 SHA512 (mesa-21.3.9.tar.xz) = 4cec6f4f50f444fcd327f7c40f8899c2f265e348e121455262b540b1f890a1468bbea59965af0876c548fa97aa0a05a1b23fa6ca7d308bd60328cfdeab757684
 Size (mesa-21.3.9.tar.xz) = 16607716 bytes
+SHA1 ( = acdbb73bde03a297a7c080c33edb317c8d838adc
+SHA1 (patch-meson__options.txt) = af1cb551056b0f85cf12d1226b8cea368b0284de
 SHA1 (patch-src_compiler_builtin__type__macros.h) = e4868011711fb89a293580a12eb603b8e7162336
 SHA1 (patch-src_drm-shim_drm__shim.c) = 6884d31dc3e9d47aac1785589ab289a601e64545
 SHA1 (patch-src_egl_drivers_dri2_platform__drm.c) = 9230fbae2c04246ebca8437ecad694bbae857fbe
diff --git a/graphics/MesaLib/ b/graphics/MesaLib/
index 3b3f48d0f578..a5ea1e4e53c3 100644
--- a/graphics/MesaLib/
+++ b/graphics/MesaLib/
@@ -76,6 +76,32 @@ GALLIUM_DRIVERS+=	r600
 PLIST.radeonsi=		yes
 .  endif
+.  if ${USE_CROSS_COMPILE:tl} == "yes"
+# XXX whattakludge
+LIBLLVM_COMPONENTS=	aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils aggressiveinstcombine all all-targets amdgpu amdgpuasmparser amdgpucodegen amdgpudesc amdgpudisassembler amdgpuinfo amdgpuutils analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter avr avrasmparser avrcodegen avrdesc avrdisassembler avrinfo binaryformat bitreader bitstreamreader bitwriter bpf bpfasmparser bpfcodegen bpfdesc bpfdisassembler bpfinfo cfguard codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfogsym debuginfomsf debuginfopdb demangle dlltooldriver dwarflinker dwp engine executionengine extensions filecheck frontendopenacc frontendopenmp fuzzmutate globalisel hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interfacestub interpreter ipo irreader jitlink lanai lanaiasmparser lanaicodegen lanaidesc lanaidisassembler lanaiinfo libdriver lineeditor linker lto mc mca mcdisassembler mcjit mcparser mips mipsasmparser mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmparser msp430codegen msp430desc msp430disassembler msp430info native nativecodegen nvptx nvptxcodegen nvptxdesc nvptxinfo objcarcopts object objectyaml option orcjit orcshared orctargetprocess passes powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo runtimedyld scalaropts selectiondag sparc sparcasmparser sparccodegen sparcdesc sparcdisassembler sparcinfo support symbolize systemz systemzasmparser systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target textapi transformutils vectorize webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo webassemblyutils windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info xcore xcorecodegen xcoredesc xcoredisassembler xcoreinfo xray
+MESON_CROSS_BINARIES+=		llvm-config
+MESON_CROSS_BINARY.llvm-config=	${TOOLS_DIR}/bin/llvm-config
+TOOLS_CREATE+=			llvm-config
+TOOLS_SCRIPT.llvm-config=						\
+	while [ $$\# -gt 0 ]; do					\
+		case $$1 in						\
+		--components)	echo ${LIBLLVM_COMPONENTS};;		\
+		--cppflags)	echo -I${BUILDLINK_PREFIX.libLLVM:Q}/include;; \
+		--has-rtti)	echo YES;;				\
+		--libdir)	echo ${BUILDLINK_PREFIX.libLLVM:Q}/lib;; \
+		--ldflags)	echo -L${BUILDLINK_PREFIX.libLLVM:Q}/lib	\
+		--libs)		echo -lLLVM-13;; 			\
+		--link-shared)	;; 					\
+		--shared-mode)	echo shared;;				\
+		--version)	echo 13.0.2;;				\
+		--*)		echo unknown option; exit 1;;		\
+		esac;							\
+		shift;							\
+	done
+.  endif
 MESON_ARGS+=		-Dllvm=disabled
@@ -135,6 +161,7 @@ MESON_ARGS+=		-Dgallium-vdpau=false
 .if !empty(PKG_OPTIONS:Mwayland)
+TOOL_DEPENDS+=		${BUILDLINK_API_DEPENDS.wayland:=:../../devel/wayland}
 .  include "../../devel/wayland/"
 .  include "../../devel/wayland-protocols/"
diff --git a/graphics/MesaLib/patches/ b/graphics/MesaLib/patches/
new file mode 100644
index 000000000000..f4830c302d55
--- /dev/null
+++ b/graphics/MesaLib/patches/
@@ -0,0 +1,19 @@
+Add a wayland-scanner option so we can pass the path through from the
+Makefile for cross-builds.
+---	2022-06-08 18:13:35.000000000 +0000
+@@ -2004,7 +2004,11 @@ endif
+ if with_platform_wayland
+   dep_wl_scanner = dependency('wayland-scanner', native: true)
++  if meson.is_cross_build()
++    prog_wl_scanner = find_program(get_option('wayland-scanner'))
++  else
+   prog_wl_scanner = find_program(dep_wl_scanner.get_pkgconfig_variable('wayland_scanner'))
++  endif
+   if dep_wl_scanner.version().version_compare('>= 1.15')
+     wl_scanner_arg = 'private-code'
+   else
diff --git a/graphics/MesaLib/patches/patch-meson__options.txt b/graphics/MesaLib/patches/patch-meson__options.txt
new file mode 100644
index 000000000000..e06c683047fd
--- /dev/null
+++ b/graphics/MesaLib/patches/patch-meson__options.txt
@@ -0,0 +1,17 @@
+Add a wayland-scanner option so we can pass the path through from the
+Makefile for cross-builds.
+--- meson_options.txt.orig	2022-06-08 18:13:35.000000000 +0000
++++ meson_options.txt
+@@ -539,3 +539,9 @@ option(
+   value : false,
+   description : 'Configure LTS build to coexist with Mesa >= 22.0'
+ )
++  'wayland-scanner',
++  type : 'string',
++  value : 'wayland-scanner',
++  description : 'Path to build-time wayland-scanner binary'

Home | Main Index | Thread Index | Old Index