From 4037785362f3f7c9e6f662c65a525c26cb4bf5c4 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Wed, 26 Jul 2023 09:52:12 +0800 Subject: [PATCH] Fix for native dep compilation (#2226) * Fix for native dep compilation * Fix lints * Really fix lints --- configure.ac | 10 +++++++++- lib/Makefile.am | 10 ++++++++++ make.sh | 28 +++++++++++++++------------- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 41be5443158..83be49fd29d 100644 --- a/configure.ac +++ b/configure.ac @@ -1377,14 +1377,21 @@ AC_SUBST(PROTOC_INCLUDE_DIR) dnl If the host and build triplets are the same, we keep this empty if test x$host = x$build; then RUST_TARGET= + RUST_HOST= else - RUST_TARGET=`TARGET="$host" $ac_abs_confdir/make.sh get_rust_target` + RUST_HOST=`$ac_abs_confdir/make.sh get_rust_triplet "$build"` + if test $? != 0; then + AC_MSG_ERROR("unsupported build system") + fi + RUST_TARGET=`$ac_abs_confdir/make.sh get_rust_triplet "$host"` if test $? != 0; then AC_MSG_ERROR("unsupported host target") fi fi AC_SUBST(RUST_TARGET) +AC_SUBST(RUST_HOST) AM_CONDITIONAL([HAVE_RUST_TARGET], [test x$RUST_TARGET != x]) +AM_CONDITIONAL([HAVE_RUST_HOST], [test x$RUST_HOST != x]) AC_CONFIG_FILES([Makefile src/Makefile lib/Makefile test/config.ini]) AC_CONFIG_FILES([contrib/devtools/split-debug.sh],[chmod +x contrib/devtools/split-debug.sh]) @@ -1473,6 +1480,7 @@ echo " CXXFLAGS = $DEBUG_CXXFLAGS $HARDENED_CXXFLAGS $WARN_CXXFLAGS echo " LDFLAGS = $PTHREAD_CFLAGS $HARDENED_LDFLAGS $GPROF_LDFLAGS $LDFLAGS" echo " ARFLAGS = $ARFLAGS" echo " CARGO = $CARGO" +echo " RUST_HOST = $RUST_HOST" echo " RUST_TARGET = $RUST_TARGET" echo " ENABLE_DEBUG = $ENABLE_DEBUG" echo diff --git a/lib/Makefile.am b/lib/Makefile.am index b7469b426d8..c8d9998910d 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -31,6 +31,14 @@ CARGO_EXTRA_ARGS ?= $(if $(subst $(build),,$(host)),,--all-targets) # Export compiler flags export CC CXX CFLAGS CXXFLAGS CPPFLAGS LDFLAGS AR NM RANLIB +# Set the native compilers +if HAVE_RUST_HOST +export CC_$(RUST_HOST)=gcc +export CXX_$(RUST_HOST)=g++ +export CFLAGS_$(RUST_HOST)= +export CXXFLAGS_$(RUST_HOST)= +endif + # Export compiler support export PKG_CONFIG_PATH PKGCONFIG_LIBDIR PYTHONPATH # Export protoc vars @@ -39,6 +47,8 @@ export PROTOC PROTOC_INCLUDE_DIR # Ensure nested autotools calls by cargo don't end up in unexpected places unexport DESTDIR +export RUST_BACKTRACE=1 + .PHONY: all: build diff --git a/make.sh b/make.sh index 5dc9137c2f9..c95f844d76c 100755 --- a/make.sh +++ b/make.sh @@ -601,7 +601,8 @@ clean_pkg_local_py_deps() { pkg_setup_rust() { local rust_target - rust_target=$(get_rust_target) + # shellcheck disable=SC2119 + rust_target=$(get_rust_triplet) rustup target add "${rust_target}" } @@ -999,24 +1000,25 @@ ci_setup_deps_test() { pkg_local_install_py_deps } -get_rust_target() { +# shellcheck disable=SC2120 +get_rust_triplet() { # Note: https://github.com/llvm/llvm-project/blob/master/llvm/lib/TargetParser/Triple.cpp # The function is called in 2 places: # 1. When setting up Rust, which TARGET is passed from the environment # 2. In configure, which sets TARGET with the additional unknown vendor part in the triplet # Thus, we normalize across both to source the correct rust target. - local target=${TARGET} - local rust_target - case $target in - x86_64-pc-linux-gnu) rust_target=x86_64-unknown-linux-gnu;; - aarch64-linux-gnu|aarch64-unknown-linux-gnu) rust_target=aarch64-unknown-linux-gnu;; - arm-linux-gnueabihf|arm-unknown-linux-gnueabihf) rust_target=armv7-unknown-linux-gnueabihf;; - x86_64-apple-darwin) rust_target=x86_64-apple-darwin;; - aarch64-apple-darwin) rust_target=aarch64-apple-darwin;; - x86_64-w64-mingw32) rust_target=x86_64-pc-windows-gnu;; - *) echo "error: unsupported target: ${target}"; exit 1;; + local triplet=${1:-${TARGET}} + local result + case $triplet in + x86_64-pc-linux-gnu) result=x86_64-unknown-linux-gnu;; + aarch64-linux-gnu|aarch64-unknown-linux-gnu) result=aarch64-unknown-linux-gnu;; + arm-linux-gnueabihf|arm-unknown-linux-gnueabihf) result=armv7-unknown-linux-gnueabihf;; + x86_64-apple-darwin) result=x86_64-apple-darwin;; + aarch64-apple-darwin) result=aarch64-apple-darwin;; + x86_64-w64-mingw32) result=x86_64-pc-windows-gnu;; + *) echo "error: unsupported triplet: ${triplet}"; exit 1;; esac - echo "$rust_target" + echo "$result" } _sign() {