From 43ece74cf747e278a1ce0b96203a4bc958d1cb12 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Tue, 13 Dec 2022 14:44:10 +0100 Subject: [PATCH 1/2] gui: target 'windows' subsystem for Windows targets --- gui/src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gui/src/main.rs b/gui/src/main.rs index 2246afa2..528c7cd8 100644 --- a/gui/src/main.rs +++ b/gui/src/main.rs @@ -1,3 +1,5 @@ +#![windows_subsystem = "windows"] + use std::{error::Error, path::PathBuf, str::FromStr}; use iced::{executor, Application, Command, Element, Settings, Subscription}; From 89d2e67625b1308d621af0fe15081588459e22b8 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Tue, 13 Dec 2022 14:48:18 +0100 Subject: [PATCH 2/2] Windows reproducible builds using Docker --- .dockerignore | 3 +++ contrib/docker/Dockerfile | 46 ++++++++++++++++++++++++++++++++ contrib/docker/build.sh | 13 +++++++++ contrib/docker/cargo_config.toml | 17 ++++++++++++ contrib/docker/docker-build.sh | 15 +++++++++++ 5 files changed, 94 insertions(+) create mode 100644 .dockerignore create mode 100644 contrib/docker/Dockerfile create mode 100755 contrib/docker/build.sh create mode 100644 contrib/docker/cargo_config.toml create mode 100755 contrib/docker/docker-build.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..3b2df1bb --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +* +!gui/Cargo.* +!contrib/docker/cargo_config.toml diff --git a/contrib/docker/Dockerfile b/contrib/docker/Dockerfile new file mode 100644 index 00000000..ba3a41f1 --- /dev/null +++ b/contrib/docker/Dockerfile @@ -0,0 +1,46 @@ +FROM debian:bullseye + +WORKDIR /liana + +# We try to pin our dependencies to avoid potential sources of non-determinism, but we don't go +# out of our way to pin the whole tree of deps. Instead invest time in getting Guix cross-compilation. +RUN apt update && apt install -y \ + gcc-mingw-w64-x86-64=10.2.1-6+24.2 \ + curl=7.74.0-1.3+deb11u3 \ + gcc=4:10.2.1-1 + +# Download the cargo binary and compiled stdlib from the distributed releases to make sure to build with +# the very same toolchain. We use 1.65.0 because it is unfortunately the MSRV of the GUI. +RUN curl -O "https://static.rust-lang.org/dist/rust-1.65.0-x86_64-unknown-linux-gnu.tar.gz" && \ + echo "8f754fdd5af783fe9020978c64e414cb45f3ad0a6f44d045219bbf2210ca3cb9 rust-1.65.0-x86_64-unknown-linux-gnu.tar.gz" | sha256sum -c && \ + tar -xzf rust-1.65.0-x86_64-unknown-linux-gnu.tar.gz && \ + curl -O "https://static.rust-lang.org/dist/rust-1.65.0-x86_64-pc-windows-gnu.tar.gz" && \ + echo "eaa0d89511739c16d2a6149ed3538ce10596c523c4791b4a378dde762cda77e4 rust-1.65.0-x86_64-pc-windows-gnu.tar.gz" | sha256sum -c && \ + tar -xzf rust-1.65.0-x86_64-pc-windows-gnu.tar.gz && \ + rm -r *.tar.gz + +# Copy the Cargo files to vendor the dependencies. +COPY gui/Cargo.toml gui/Cargo.lock /liana/ + +# We cache the dependencies sources in the image to avoid re-indexing everything from scratch +# at every run. It was useful when debugging the build, it could be removed eventually if we +# think the tradeoff vs the image size wasn't worth it anymore. +RUN /liana/rust-1.65.0-x86_64-unknown-linux-gnu/cargo/bin/cargo vendor + +# Cargo configuration for using the vendored dependencies during the build. +COPY contrib/docker/cargo_config.toml /liana/.cargo/cargo_config.toml + +# For some reason, we can't just set the RUSTFLAGS environment variable to add `-L` for compiling dependencies. +# This doesn't work: RUSTFLAGS="-L /liana/rust-1.65.0-x86_64-pc-windows-gnu/rust-std-x86_64-pc-windows-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/ -L /liana/rust-1.65.0-x86_64-unknown-linux-gnu/rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/" +# As a workaround, we use a wrapped `rustc` binary that always links against the windows stdlib we just downloaded. +# Some issues that seem to be related: +# https://github.com/rust-lang/rust/issues/40717 +# https://github.com/rust-lang/rust/issues/48409 +RUN echo "#!/bin/sh" > rustc_wrapper.sh && \ + echo "/liana/rust-1.65.0-x86_64-unknown-linux-gnu/rustc/bin/rustc \"\$@\" -L /liana/rust-1.65.0-x86_64-pc-windows-gnu/rust-std-x86_64-pc-windows-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/ -L /liana/rust-1.65.0-x86_64-unknown-linux-gnu/rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/" >> rustc_wrapper.sh && \ + chmod +x rustc_wrapper.sh && \ + cat rustc_wrapper.sh && \ + ./rustc_wrapper.sh -vV +ENV RUSTC="/liana/rustc_wrapper.sh" + +CMD ["./docker/build.sh"] diff --git a/contrib/docker/build.sh b/contrib/docker/build.sh new file mode 100755 index 00000000..40a88dfa --- /dev/null +++ b/contrib/docker/build.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +# ================================================================= +# The script ran within the Docker container to build the Liana GUI. +# ================================================================= + + +# Build the GUI for Windows. The Windows Portable Execution (PE) format contains some timestamps. +# Instruct ld to set them to 0. +RUSTFLAGS="-Clink-arg=-Wl,--no-insert-timestamp" /liana/rust-1.65.0-x86_64-unknown-linux-gnu/cargo/bin/cargo rustc --release --target x86_64-pc-windows-gnu + +# Avoid having to get root on the host to remove the target dir. +chmod -R a+rw target/ diff --git a/contrib/docker/cargo_config.toml b/contrib/docker/cargo_config.toml new file mode 100644 index 00000000..366c3a00 --- /dev/null +++ b/contrib/docker/cargo_config.toml @@ -0,0 +1,17 @@ +[source.vendored_sources] +directory = "vendor" + +[source.crates-io] +replace-with = "vendored_sources" + +[source."https://github.com/darosior/rust-miniscript"] +git = "https://github.com/darosior/rust-miniscript" +branch = "multipath_descriptors_on_8.0" +replace-with = "vendored_sources" + +[source."https://github.com/revault/liana"] +git = "https://github.com/revault/liana" +branch = "master" +replace-with = "vendored_sources" + +# TODO: strip debug symbols as is done in Guix to reduce binary size. diff --git a/contrib/docker/docker-build.sh b/contrib/docker/docker-build.sh new file mode 100755 index 00000000..b687f6a2 --- /dev/null +++ b/contrib/docker/docker-build.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env sh + +set -ex + +TARGET_DIR="$PWD/deter_build_target" + +docker build . -t liana_cross_compile -f contrib/docker/Dockerfile +docker run --rm -ti \ + -v "$TARGET_DIR":/liana/target \ + -v "$PWD/contrib/docker":/liana/docker \ + -v "$PWD/gui/src":/liana/src \ + -v "$PWD/gui/static":/liana/static \ + liana_cross_compile + +set +ex