classes/meson: Add optional rust definitions
PATCH 1/1 classes/meson: Add optional rust definitions
Adds the rust tools to the cross and native files if present so that projects that use both rust and meson can build
Signed-off-by Joshua Watt <[email protected]>
--- meta/classes/meson.bbclass | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
meta/classes/meson.bbclass +8 -1
@@ -36,8 +36,13 @@ MESON_CROSS_FILE = "" MESON_CROSS_FILE:class-target = "--cross-file ${WORKDIR}/meson.cross" MESON_CROSS_FILE:class-nativesdk = "--cross-file ${WORKDIR}/meson.cross" +def optional_tool(name, var, d): + if not d.getVar(var): + return "" + return "%s = %s" % (name, meson_array(var, d)) + addtask write_config before do_configure -do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS" +do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS RUSTC" do_write_config() { # This needs to be Py to split the args into single-element lists cat >${WORKDIR}/meson.cross <<EOF
@@ -54,6 +59,7 @@ llvm-config = 'llvm-config${LLVMVERSION}' cups-config = 'cups-config' g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper' g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper' +${@optional_tool('rust', 'RUSTC', d)} [built-in options] c_args = ${@meson_array('CFLAGS', d)}
@@ -88,6 +94,7 @@ strip = ${@meson_array('BUILD_STRIP', d)} readelf = ${@meson_array('BUILD_READELF', d)} objcopy = ${@meson_array('BUILD_OBJCOPY', d)} pkgconfig = 'pkg-config-native' +${@optional_tool('rust', 'RUSTC', d)} [built-in options] c_args = ${@meson_array('BUILD_CFLAGS', d)}
Signature · 1 line
2.33.0
PATCH v2 1/1 classes/meson: Add optional rust definitions
Adds the rust tools to the cross and native files if present so that projects that use both rust and meson can build
Signed-off-by Joshua Watt <[email protected]>
---
V2: Fixes so that cross-compiling works correctly by passing --target and RUSTFLAGS
meta/classes/meson.bbclass | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
meta/classes/meson.bbclass +10 -1
@@ -36,8 +36,15 @@ MESON_CROSS_FILE = "" MESON_CROSS_FILE:class-target = "--cross-file ${WORKDIR}/meson.cross" MESON_CROSS_FILE:class-nativesdk = "--cross-file ${WORKDIR}/meson.cross" +def rust_tool(d, target_var): + rustc = d.getVar('RUSTC') + if not rustc: + return "" + cmd = [rustc, "--target", d.getVar(target_var)] + d.getVar("RUSTFLAGS").split() + return "rust = %s" % repr(cmd) + addtask write_config before do_configure -do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS" +do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS RUSTC RUSTFLAGS" do_write_config() { # This needs to be Py to split the args into single-element lists cat >${WORKDIR}/meson.cross <<EOF
@@ -54,6 +61,7 @@ llvm-config = 'llvm-config${LLVMVERSION}' cups-config = 'cups-config' g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper' g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper' +${@rust_tool(d, "HOST_SYS")} [built-in options] c_args = ${@meson_array('CFLAGS', d)}
@@ -88,6 +96,7 @@ strip = ${@meson_array('BUILD_STRIP', d)} readelf = ${@meson_array('BUILD_READELF', d)} objcopy = ${@meson_array('BUILD_OBJCOPY', d)} pkgconfig = 'pkg-config-native' +${@rust_tool(d, "BUILD_SYS")} [built-in options] c_args = ${@meson_array('BUILD_CFLAGS', d)}
Signature · 1 line
2.33.0