Skip to content

Commit

Permalink
guix: aarch64-linux-gnu Rust FFI cross-compilation [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
tobtoht committed Aug 17, 2024
1 parent 29823d8 commit 041d8ce
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
2 changes: 2 additions & 0 deletions contrib/guix/cargo.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,4 +13,5 @@
nss-certs
openssl
rust
git-minimal
(list rust "cargo"))))
9 changes: 9 additions & 0 deletions contrib/guix/guix-build
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 \
Expand Down
24 changes: 24 additions & 0 deletions contrib/guix/libexec/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
#####################
Expand Down
32 changes: 32 additions & 0 deletions contrib/guix/libexec/config.toml
Original file line number Diff line number Diff line change
@@ -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]
6 changes: 6 additions & 0 deletions contrib/guix/manifest.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...)
Expand Down Expand Up @@ -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)
Expand All @@ -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)))
Expand Down

0 comments on commit 041d8ce

Please sign in to comment.