Skip to content

Commit dfe3fdf

Browse files
committed
feat: support all app variants w/ reproducible Guix builds
1 parent 71199dd commit dfe3fdf

4 files changed

Lines changed: 81 additions & 12 deletions

File tree

contrib/guix/guix-build

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ auto_detect_version
3838
compute_source_date_epoch
3939

4040
# Compute commit hash outside the container (source .git is not mounted).
41-
if [ -d "${SOURCE_DIR}/.git" ]; then
41+
if [ -e "${SOURCE_DIR}/.git" ]; then
4242
BUILT_COMMIT_HASH="$(git -C "${SOURCE_DIR}" log -1 --pretty=format:"%H")"
4343
else
4444
BUILT_COMMIT_HASH="0000000000000000000000000000000000000000"
@@ -78,7 +78,7 @@ if [ ! -x "${RUST_DIR}/${RUST_VERSION_DEFAULT}/bin/rustc" ]; then
7878
fi
7979

8080
# Verify source directory.
81-
if [ ! -f "${SOURCE_DIR}/pubspec.yaml" ]; then
81+
if [ ! -f "${SOURCE_DIR}/pubspec.yaml" ] && [ ! -f "${SOURCE_DIR}/scripts/app_config/templates/pubspec.template.yaml" ]; then
8282
die "Source directory does not look like a Stack Wallet checkout: ${SOURCE_DIR}"
8383
fi
8484

@@ -111,6 +111,7 @@ for HOST in $HOSTS; do
111111
--share="${FLUTTER_SDK_DIR}=/sw/flutter-sdk" \
112112
--expose="${RUST_DIR}=/sw/rust" \
113113
--expose="${BASE_CACHE}/native-sources=/sw/native-sources" \
114+
--expose="${BASE_CACHE}/go-cache=/sw/go-cache" \
114115
--no-cwd \
115116
-- env \
116117
HOME="/tmp" \

contrib/guix/libexec/build.sh

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export LC_ALL=C
1616
export TZ=UTC
1717
umask 0022
1818

19+
# Force single codegen unit in Rust release builds for deterministic output.
20+
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
21+
1922
# Disable Dart/Flutter analytics and telemetry.
2023
export CI=true
2124
export FLUTTER_SUPPRESS_ANALYTICS=true
@@ -52,9 +55,17 @@ APP_NAME_ID="${APP_NAME_ID:?APP_NAME_ID not set}"
5255
APP_VERSION="${APP_VERSION:?APP_VERSION not set}"
5356
APP_BUILD_NUMBER="${APP_BUILD_NUMBER:?APP_BUILD_NUMBER not set}"
5457

58+
# Go: offline builds for flutter_mwebd.
59+
export GOMODCACHE="/sw/go-cache"
60+
export GOFLAGS="-buildvcs=false"
61+
export GONOSUMCHECK="*"
62+
export GONOSUMDB="*"
63+
export GOPROXY=off
64+
5565
RUST_VERSION_DEFAULT="${RUST_VERSION_DEFAULT:-1.89.0}"
5666
RUST_VERSION_MWC="${RUST_VERSION_MWC:-1.85.1}"
5767
RUST_VERSION_FROSTDART="${RUST_VERSION_FROSTDART:-1.71.0}"
68+
RUST_VERSION_XELIS="${RUST_VERSION_XELIS:-1.91.0}"
5869

5970
echo "--- [build] Host: ${HOST}"
6071
echo "--- [build] App: ${APP_NAME_ID} v${APP_VERSION}+${APP_BUILD_NUMBER}"
@@ -75,6 +86,10 @@ set_rust_version() {
7586
export CARGO_HOME="${CARGO_CACHE_MOUNT}"
7687
export RUSTUP_HOME="/tmp/fake-rustup"
7788

89+
# Rust 1.91+ build scripts need libgcc_s.so.1 which lives at /lib/ in the
90+
# Guix FHS emulation. Set LD_LIBRARY_PATH so the linker can find it.
91+
export LD_LIBRARY_PATH="/lib:/lib64:/usr/lib"
92+
7893
echo "--- [build] Rust version: $(rustc --version)"
7994
}
8095

@@ -146,7 +161,7 @@ case "\$*" in
146161
echo "${BUILT_COMMIT_HASH:-0000000000000000000000000000000000000000}"
147162
exit 0
148163
;;
149-
*pull*)
164+
*pull*|*fetch*)
150165
exit 0
151166
;;
152167
*clone*)
@@ -346,6 +361,11 @@ source "$BUILD_DIR/scripts/app_config/configure_${APP_NAME_ID}.sh" linux
346361
# Step 5: Linux platform config.
347362
source "$BUILD_DIR/scripts/app_config/platforms/linux/platform_config.sh"
348363

364+
# Step 6: Run prebuild.sh to create stub external_api_keys.dart etc.
365+
pushd "$BUILD_DIR/scripts" > /dev/null
366+
bash prebuild.sh
367+
popd > /dev/null
368+
349369
################
350370
# GCC compat #
351371
################
@@ -428,6 +448,10 @@ case "$APP_NAME_ID" in
428448
setup_cargo_vendor "epiccash" "${CRYPTO_DIR}/flutter_libepiccash/rust"
429449
(
430450
cd "${CRYPTO_DIR}/flutter_libepiccash/scripts/linux"
451+
# GCC 15 in Guix: libstdc++ was built without C99 fenv support,
452+
# so <cfenv> never exposes fesetround/fegetround. Force the
453+
# config macros so the C++ wrapper actually includes <fenv.h>.
454+
export CXXFLAGS="${CXXFLAGS:-} -D_GLIBCXX_HAVE_FENV_H=1 -D_GLIBCXX_USE_C99_FENV=1"
431455
bash build_all.sh
432456
)
433457

@@ -479,16 +503,55 @@ set_rust_version "$RUST_VERSION_DEFAULT"
479503
# Cargokit prep #
480504
################
481505

482-
# Set up cargo vendoring for the tor_ffi_plugin. Cargokit builds tor's Rust
483-
# code during `flutter build linux` via cmake. The vendor config must be in
484-
# place before cmake runs.
485-
for _tor_rust in "${PUB_CACHE_MOUNT}"/git/tor-*/rust; do
486-
if [ -f "$_tor_rust/Cargo.toml" ]; then
487-
echo "--- [build] Setting up cargo vendor for tor_ffi_plugin ..."
488-
setup_cargo_vendor "tor" "$_tor_rust"
506+
# Cargokit plugins (tor_ffi_plugin, xelis_flutter) build Rust code during
507+
# `flutter build linux` via cmake. Cargokit's run_build_tool.sh changes
508+
# directory to a temp folder before invoking cargo. Cargo searches for
509+
# .cargo/config.toml from CWD upwards, so per-workspace configs are not
510+
# found. Solution: give each Cargokit plugin its own CARGO_HOME with the
511+
# correct vendor config. We patch each plugin's run_build_tool.sh to
512+
# export CARGO_HOME before running the Dart build tool.
513+
514+
echo "--- [build] Setting up Cargokit vendor configs for offline Rust builds ..."
515+
516+
# Helper: create a per-plugin CARGO_HOME with vendor config.
517+
setup_cargokit_plugin() {
518+
local plugin_name="$1"
519+
local plugin_dir="$2" # root of the plugin (contains cargokit/, rust/, linux/)
520+
local rust_dir="$plugin_dir/rust"
521+
522+
# Set up workspace-level vendor config (for any direct cargo invocations).
523+
setup_cargo_vendor "$plugin_name" "$rust_dir"
524+
525+
# Create a per-plugin CARGO_HOME with the same config.
526+
local cargo_home="/tmp/cargo-home-${plugin_name}"
527+
mkdir -p "$cargo_home"
528+
cp "$rust_dir/.cargo/config.toml" "$cargo_home/config.toml"
529+
530+
# Patch run_build_tool.sh to export this CARGO_HOME before running Dart.
531+
local rbt="$plugin_dir/cargokit/run_build_tool.sh"
532+
if [ -f "$rbt" ]; then
533+
sed -i "2i export CARGO_HOME=\"${cargo_home}\"" "$rbt"
534+
fi
535+
}
536+
537+
for _tor_dir in "${PUB_CACHE_MOUNT}"/git/tor-*/; do
538+
if [ -f "$_tor_dir/rust/Cargo.toml" ]; then
539+
setup_cargokit_plugin "tor" "$_tor_dir"
489540
break
490541
fi
491542
done
543+
for _xelis_dir in "${PUB_CACHE_MOUNT}"/git/xelis-flutter-ffi-*/ "${PUB_CACHE_MOUNT}"/git/xelis_flutter-*/ "${PUB_CACHE_MOUNT}"/git/xelis-flutter-*/; do
544+
if [ -f "$_xelis_dir/rust/Cargo.toml" ]; then
545+
setup_cargokit_plugin "xelis" "$_xelis_dir"
546+
break
547+
fi
548+
done
549+
550+
# Use the highest Rust version for the flutter build phase.
551+
# Cargokit plugins (tor, xelis) build via cmake during `flutter build linux`.
552+
# Our rustup shim ignores rust-toolchain.toml, so we must set PATH to a
553+
# version that satisfies all plugins. 1.91.0 >= all requirements.
554+
set_rust_version "$RUST_VERSION_XELIS"
492555

493556
################
494557
# Flutter build #

contrib/guix/libexec/prelude.bash

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ export FLUTTER_CHANNEL="stable"
4141
export RUST_VERSION_DEFAULT="1.89.0"
4242
export RUST_VERSION_MWC="1.85.1"
4343
export RUST_VERSION_FROSTDART="1.71.0"
44+
export RUST_VERSION_XELIS="1.91.0"
4445

4546
# All Rust versions we need toolchains for.
46-
export RUST_VERSIONS=("${RUST_VERSION_DEFAULT}" "${RUST_VERSION_MWC}" "${RUST_VERSION_FROSTDART}")
47+
export RUST_VERSIONS=("${RUST_VERSION_DEFAULT}" "${RUST_VERSION_MWC}" "${RUST_VERSION_FROSTDART}" "${RUST_VERSION_XELIS}")
4748

4849
################
4950
# Build config #
@@ -105,7 +106,8 @@ auto_detect_version() {
105106
# Compute SOURCE_DATE_EPOCH from git log.
106107
compute_source_date_epoch() {
107108
if [ -z "${SOURCE_DATE_EPOCH:-}" ]; then
108-
if [ -d "${SOURCE_DIR}/.git" ]; then
109+
# -e handles both regular .git dirs and worktree .git files.
110+
if [ -e "${SOURCE_DIR}/.git" ]; then
109111
SOURCE_DATE_EPOCH="$(git -C "${SOURCE_DIR}" log -1 --format=%ct)"
110112
else
111113
SOURCE_DATE_EPOCH="$(date +%s)"

contrib/guix/manifest.scm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
;; Clang/LLVM (needed by some Rust crates' build.rs)
4747
"clang-toolchain"
4848

49+
;; Go (needed by flutter_mwebd plugin for Litecoin MWEB)
50+
"go"
51+
4952
;; CA certificates (for Rust vendored-openssl verification)
5053
"nss-certs"
5154

0 commit comments

Comments
 (0)