From 041d8ce3ebfc5cf533e08119f31801571cc05b76 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Sat, 17 Aug 2024 18:32:47 +0200 Subject: [PATCH] guix: aarch64-linux-gnu Rust FFI cross-compilation [WIP] --- contrib/guix/cargo.scm | 2 ++ contrib/guix/guix-build | 9 +++++++++ contrib/guix/libexec/build.sh | 24 ++++++++++++++++++++++++ contrib/guix/libexec/config.toml | 32 ++++++++++++++++++++++++++++++++ contrib/guix/manifest.scm | 6 ++++++ 5 files changed, 73 insertions(+) create mode 100644 contrib/guix/libexec/config.toml diff --git a/contrib/guix/cargo.scm b/contrib/guix/cargo.scm index 89b616eb15b..05e13793c4f 100644 --- a/contrib/guix/cargo.scm +++ b/contrib/guix/cargo.scm @@ -2,6 +2,7 @@ (gnu packages bash) ((gnu packages certs) #:select (nss-certs)) (gnu packages rust) + ((gnu packages version-control) #:select (git-minimal)) ((gnu packages tls) #:select (openssl))) (packages->manifest @@ -12,4 +13,5 @@ nss-certs openssl rust + git-minimal (list rust "cargo")))) \ No newline at end of file diff --git a/contrib/guix/guix-build b/contrib/guix/guix-build index 757f4171710..486342f5a51 100755 --- a/contrib/guix/guix-build +++ b/contrib/guix/guix-build @@ -373,6 +373,12 @@ EOF --share="$PWD"=/monero \ -- bash -c "cd /monero/src/fcmp_pp/fcmp_pp_rust && cargo fetch && + cd /monero && + rm -rf /monero/rust && + rustc -vV && + git clone https://github.com/rust-lang/rust && + cd rust && + git checkout 7cf61ebde7b22796c69757901dd346d0fe70bd97 && rm -rf /monero/cargo && mv /home/user/.cargo /monero/cargo" @@ -441,10 +447,13 @@ EOF # Please read the README.md in the same directory as this file for # more information. # + # TODO: don't pass --network + # # shellcheck disable=SC2086,SC2031 time-machine environment --manifest="${PWD}/contrib/guix/manifest.scm" \ --container \ --pure \ + --network \ --no-cwd \ --share="$PWD"=/monero \ --share="$PWD/cargo"=/home/user/.cargo \ diff --git a/contrib/guix/libexec/build.sh b/contrib/guix/libexec/build.sh index 828059af978..373458ef9bf 100644 --- a/contrib/guix/libexec/build.sh +++ b/contrib/guix/libexec/build.sh @@ -49,6 +49,30 @@ DISTNAME="monero-${HOST}-${VERSION}" # Use a fixed timestamp for depends builds so hashes match across commits that don't make changes to the build system export SOURCE_DATE_EPOCH=1397818193 +##################### +# Rust Setup # +##################### + +cd rust + +# TODO: generate for target +cp ../contrib/guix/libexec/config.toml . + +# TODO: crti.o not found, don't hardcode this +export CROSS_LIBRARY_PATH="/gnu/store/f8x57r7v1lw5v9c8hnbhdv24m466970y-glibc-cross-aarch64-linux-gnu-2.27/lib" + +# TODO: do we really need to build a new rustc here? +# TODO: fetch deps in cargo container +python3 ./x.py -j16 build library/std + +# TODO: don't build docs and other stuff we're not going to use +python3 ./x.py install + +# TODO: move to environment setup +export RUSTC="/usr/local/bin/rustc" + +cd .. + ##################### # Environment Setup # ##################### diff --git a/contrib/guix/libexec/config.toml b/contrib/guix/libexec/config.toml new file mode 100644 index 00000000000..0b21a6a69a0 --- /dev/null +++ b/contrib/guix/libexec/config.toml @@ -0,0 +1,32 @@ +[llvm] + +download-ci-llvm = false + +[build] + +target = ["x86_64-unknown-linux-gnu", "aarch64-unknown-linux-gnu"] + +cargo = "/home/user/.guix-profile/bin/cargo" + +rustc = "/home/user/.guix-profile/bin/rustc" + +[install] + +[rust] + +[target.x86_64-unknown-linux-gnu] + +cc = "/home/user/.guix-profile/bin/gcc" + +cxx = "/home/user/.guix-profile/bin/g++" + +ar = "/home/user/.guix-profile/bin/ar" + +linker = "/home/user/.guix-profile/bin/gcc" + +llvm-config = "/home/user/.guix-profile/bin/llvm-config" + +[target.aarch64-unknown-linux-gnu] + +llvm-config = "/home/user/.guix-profile/bin/llvm-config" +[dist] diff --git a/contrib/guix/manifest.scm b/contrib/guix/manifest.scm index b4fd7adf8bc..84d33d5f435 100644 --- a/contrib/guix/manifest.scm +++ b/contrib/guix/manifest.scm @@ -29,6 +29,8 @@ (guix git-download) ((guix licenses) #:prefix license:) (guix packages) + (gnu packages text-editors) + (gnu packages certs) ((guix utils) #:select (substitute-keyword-arguments))) (define-syntax-rule (search-our-patches file-name ...) @@ -259,6 +261,9 @@ chain for " target " development.")) python-minimal ;; Git git-minimal + ;; TODO: remove this + nano + nss-certs ) (let ((target (getenv "HOST"))) (cond ((string-suffix? "-mingw32" target) @@ -269,6 +274,7 @@ chain for " target " development.")) (make-mingw-pthreads-cross-toolchain target))) ((string-contains target "-linux-gnu") (list + clang-toolchain-17 gcc-toolchain-12 (list gcc-toolchain-12 "static") (make-monero-cross-toolchain target)))