From 30f071ca1e175c222fd33f4e0a62afe870560825 Mon Sep 17 00:00:00 2001 From: pasta Date: Thu, 24 Sep 2026 21:03:45 -0500 Subject: [PATCH 1/4] build(depends): add a prebuilt Rust toolchain and per-host standard library native_rust stages the prebuilt Rust 1.98.1 compiler and Cargo (the toolchain dashpay/platform pins) for the four supported build hosts, from the rustc and cargo component archives (.tar.xz) rather than the full installer, which also carries docs, clippy, rust-analyzer and the like: 92 MB instead of 382 MB on x86_64 Linux. rust_stdlib stages the standard library for the host, for every default Guix host, and, when the build machine is a different target, the build machine's for build scripts and proc macros; a native build fetches it once. The prebuilt toolchain does not run inside a Guix environment as is, so native_rust stops there with an error saying PLATFORM_GUI is not supported in Guix builds yet. Linux hosts use the glibc (-unknown-linux-gnu) standard library, the one Rust supports for linking into a glibc program. Its libc imports are unversioned and bind to the glibc the program is linked against; every symbol it requires unconditionally is in glibc 2.31 on all five Linux architectures. contrib/devtools/update-rust-hashes.py refreshes the pins and requires every download to match the .sha256 file static.rust-lang.org publishes; --check compares the pins with those files. Nothing uses the packages yet. Co-Authored-By: Claude Opus 5.5 --- contrib/devtools/README.md | 10 +++ contrib/devtools/update-rust-hashes.py | 109 +++++++++++++++++++++++++ depends/packages/native_rust.mk | 71 ++++++++++++++++ depends/packages/rust_stdlib.mk | 89 ++++++++++++++++++++ 4 files changed, 279 insertions(+) create mode 100755 contrib/devtools/update-rust-hashes.py create mode 100644 depends/packages/native_rust.mk create mode 100644 depends/packages/rust_stdlib.mk diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md index 358c238866a3..6bcdf93f6df5 100644 --- a/contrib/devtools/README.md +++ b/contrib/devtools/README.md @@ -203,3 +203,13 @@ Example usage: cd .../src ../contrib/devtools/circular-dependencies.py {*,*/*,*/*/*}.{h,cpp} + +update-rust-hashes.py +===================== + +Refreshes the sha256 pins of the prebuilt Rust toolchain +(`depends/packages/native_rust.mk`) and of the per-host standard libraries +(`depends/packages/rust_stdlib.mk`) after the version in `native_rust.mk` was +changed; each downloaded archive must match the `.sha256` file published next +to it. `--check` compares the pins with the published `.sha256` files instead +of rewriting them. diff --git a/contrib/devtools/update-rust-hashes.py b/contrib/devtools/update-rust-hashes.py new file mode 100755 index 000000000000..894662857fab --- /dev/null +++ b/contrib/devtools/update-rust-hashes.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python3 +# Copyright (c) 2021-2022 The Zcash developers +# Copyright (c) 2026 The Dash Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. +''' +Refresh the sha256 pins of the prebuilt Rust toolchain (native_rust.mk) and +the per-host standard libraries (rust_stdlib.mk) for the version set in +native_rust.mk, or verify them with --check. + +Rewriting downloads every archive from static.rust-lang.org, hashes it locally +and requires the result to match the .sha256 file published next to it. +--check only compares the pins with the published .sha256 files. +''' +import argparse +import hashlib +import http.client +import re +import sys +import urllib.request +from pathlib import Path + +DIST_URL = "https://static.rust-lang.org/dist" +TIMEOUT = 60 # seconds without data before a request fails +PACKAGES_DIR = Path(__file__).resolve().parents[2] / "depends" / "packages" +NATIVE_RUST_MK = PACKAGES_DIR / "native_rust.mk" +RUST_STDLIB_MK = PACKAGES_DIR / "rust_stdlib.mk" + + +def pins(content: str, kind: str) -> dict: + """Return {id: value} for every `$(package)__:=` line.""" + return dict(re.findall(rf"^\$\(package\)_{kind}_(\w+):=(\S+)$", content, re.MULTILINE)) + + +def published_sha256(url: str) -> str: + """Return the hash in the ` ` line of `.sha256`.""" + with urllib.request.urlopen(f"{url}.sha256", timeout=TIMEOUT) as response: + return response.read().decode().split()[0] + + +def sha256_of(url: str, attempts: int = 3) -> str: + for _ in range(attempts): + hasher = hashlib.sha256() + received = 0 + try: + with urllib.request.urlopen(url, timeout=TIMEOUT) as response: + length = response.headers["Content-Length"] + while chunk := response.read(1 << 20): + hasher.update(chunk) + received += len(chunk) + except (http.client.IncompleteRead, OSError) as error: + print(f"warning: {url}: {error}", file=sys.stderr) + continue + if length is None or received == int(length): + return hasher.hexdigest() + print(f"warning: {url}: download ended after {received} of {length} bytes", file=sys.stderr) + sys.exit(f"error: {url}: no complete download in {attempts} attempts") + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument("--check", action="store_true", help="verify the pinned hashes instead of rewriting them") + args = parser.parse_args() + + native = NATIVE_RUST_MK.read_text(encoding="utf-8") + stdlib = RUST_STDLIB_MK.read_text(encoding="utf-8") + version_pin = re.search(r"^\$\(package\)_version:=(\S+)$", native, re.MULTILINE) + if version_pin is None: + sys.exit(f"error: no version pin in {NATIVE_RUST_MK}") + version = version_pin.group(1) + + archives = [] # (makefile, pin kind, pin id, archive name) + for build_id, target in pins(native, "build_target").items(): + for component in ("rustc", "cargo"): + archives.append((NATIVE_RUST_MK, f"{component}_sha256_hash", build_id, f"{component}-{version}-{target}.tar.xz")) + for host_id, target in pins(stdlib, "target").items(): + archives.append((RUST_STDLIB_MK, "sha256_hash", host_id, f"rust-std-{version}-{target}.tar.xz")) + + contents = {NATIVE_RUST_MK: native, RUST_STDLIB_MK: stdlib} + stale = [] + for makefile, kind, pin_id, archive in archives: + pinned = pins(contents[makefile], kind).get(pin_id) + if pinned is None: + sys.exit(f"error: {makefile} has no {kind}_{pin_id} pin") + url = f"{DIST_URL}/{archive}" + actual = published_sha256(url) + if not args.check: + downloaded = sha256_of(url) + if downloaded != actual: + sys.exit(f"error: {archive} hashes to {downloaded}, but its published .sha256 says {actual}") + print(f"{actual} {archive}") + if actual != pinned: + stale.append(archive) + contents[makefile] = re.sub(rf"^(\$\(package\)_{kind}_{pin_id}:=)\S*$", + rf"\g<1>{actual}", contents[makefile], flags=re.MULTILINE) + + if args.check: + for archive in stale: + print(f"error: pinned hash for {archive} does not match", file=sys.stderr) + return 1 if stale else 0 + + for makefile, content in contents.items(): + makefile.write_text(content, encoding="utf-8") + print(f"Updated {len(stale)} of {len(archives)} pins for Rust {version}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/depends/packages/native_rust.mk b/depends/packages/native_rust.mk new file mode 100644 index 000000000000..a80797c2520f --- /dev/null +++ b/depends/packages/native_rust.mk @@ -0,0 +1,71 @@ +# Copyright (c) 2016-2025 The Zcash developers +# Copyright (c) 2026 The Dash Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +# The rustc and cargo components of the prebuilt Rust toolchain. rust_stdlib +# installs the standard libraries next to them. To update the Rust compiler, +# change the version below and then run the script +# ./contrib/devtools/update-rust-hashes.py + +package:=native_rust +$(package)_version:=1.98.1 +$(package)_download_path:=https://static.rust-lang.org/dist + +# Linux (ARMv8) +$(package)_build_target_aarch64_linux:=aarch64-unknown-linux-gnu +$(package)_rustc_sha256_hash_aarch64_linux:=89fb83041993b48816514815606f53a5264729b8b449671a6b291e6f0ae74f40 +$(package)_cargo_sha256_hash_aarch64_linux:=c09425a7f300af148c0bdfded0e7d5f1fe7c075b2b9674e8935afa769297b2f6 + +# Linux (x86_64) +$(package)_build_target_x86_64_linux:=x86_64-unknown-linux-gnu +$(package)_rustc_sha256_hash_x86_64_linux:=e974f036b28565f37c0f3bd92ddefa809bee16c04f9dcf07b9ed96e05aaaf7c4 +$(package)_cargo_sha256_hash_x86_64_linux:=ea1de9f9e23107d97ee2b41a72c552f34064a593da503789218387aee59f3ba4 + +# macOS (ARMv8) +$(package)_build_target_aarch64_darwin:=aarch64-apple-darwin +$(package)_rustc_sha256_hash_aarch64_darwin:=738e3f60114b20550fcf4f8a57c9cea0544239f214709f45594ff3fde327f577 +$(package)_cargo_sha256_hash_aarch64_darwin:=de51d4fade4f31ad8ec405261cc96bedc000d905f98980027610d6e288dbe21b + +# macOS (x86_64) +$(package)_build_target_x86_64_darwin:=x86_64-apple-darwin +$(package)_rustc_sha256_hash_x86_64_darwin:=641c301bd19c3cead114cbb61919c5ed2475ce53e2d011fe0c990e16c5a1b04b +$(package)_cargo_sha256_hash_x86_64_darwin:=74b1282253c31fb89926d51d57e47a06c6cd26c93657de72edf622a4ab66396f + +# The Rust target triple of the build machine. +$(package)_build_target:=$($(package)_build_target_$(build_arch)_$(build_os)) + +ifeq ($($(package)_build_target),) +$(error native_rust has no prebuilt Rust $($(package)_version) for $(build_arch)-$(build_os)) +endif + +$(package)_file_name:=rustc-$($(package)_version)-$($(package)_build_target).tar.xz +$(package)_sha256_hash:=$($(package)_rustc_sha256_hash_$(build_arch)_$(build_os)) +$(package)_cargo_file_name:=cargo-$($(package)_version)-$($(package)_build_target).tar.xz +$(package)_cargo_sha256_hash:=$($(package)_cargo_sha256_hash_$(build_arch)_$(build_os)) +$(package)_fetched_id:=$($(package)_cargo_sha256_hash) +$(package)_extra_sources:=$($(package)_cargo_file_name) + +# The prebuilt toolchain cannot run inside a Guix environment as is. +ifneq ($(GUIX_ENVIRONMENT),) +$(error native_rust: PLATFORM_GUI is not supported in Guix builds yet) +endif + +define $(package)_fetch_cmds +$(call fetch_file,$(package),$($(package)_download_path),$($(package)_file_name),$($(package)_file_name),$($(package)_sha256_hash)) && \ +$(call fetch_file,$(package),$($(package)_download_path),$($(package)_cargo_file_name),$($(package)_cargo_file_name),$($(package)_cargo_sha256_hash)) +endef + +define $(package)_extract_cmds + echo "$($(package)_sha256_hash) $($(package)_source)" > .$($(package)_file_name).hash && \ + echo "$($(package)_cargo_sha256_hash) $($(package)_source_dir)/$($(package)_cargo_file_name)" >> .$($(package)_file_name).hash && \ + $(build_SHA256SUM) -c .$($(package)_file_name).hash && \ + $(build_TAR) --no-same-owner --strip-components=1 -xf $($(package)_source) && \ + $(build_TAR) --no-same-owner --strip-components=1 -xf $($(package)_source_dir)/$($(package)_cargo_file_name) +endef + +define $(package)_stage_cmds + mkdir -p $($(package)_staging_prefix_dir)/bin $($(package)_staging_prefix_dir)/lib && \ + cp cargo/bin/cargo rustc/bin/rustc $($(package)_staging_prefix_dir)/bin/ && \ + cp -R rustc/lib/. $($(package)_staging_prefix_dir)/lib/ +endef diff --git a/depends/packages/rust_stdlib.mk b/depends/packages/rust_stdlib.mk new file mode 100644 index 000000000000..fccbf2fb288d --- /dev/null +++ b/depends/packages/rust_stdlib.mk @@ -0,0 +1,89 @@ +# Copyright (c) 2016-2025 The Zcash developers +# Copyright (c) 2026 The Dash Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +# Precompiled Rust standard libraries for the host and, when it differs, the +# build machine, installed next to the native_rust compiler. The version +# follows native_rust.mk; update both with +# ./contrib/devtools/update-rust-hashes.py + +package:=rust_stdlib +$(package)_version:=$(native_rust_version) +$(package)_download_path:=$(native_rust_download_path) + +# Every host in contrib/guix/guix-build's default HOSTS has an entry. Linux +# hosts use the glibc (-unknown-linux-gnu) standard library, the one Rust +# supports for linking into a glibc program. Its libc imports are unversioned +# in the archive and bind at link time to the glibc the program is linked +# against; every symbol it requires unconditionally exists in glibc 2.31 on +# all five Linux architectures (the rest are weak and looked up at run time). + +# Linux (x86_64) +$(package)_target_x86_64_linux:=x86_64-unknown-linux-gnu +$(package)_sha256_hash_x86_64_linux:=fa3ff450172a16c026944030230c5069947af93c728d9179971d44e5e0cfb561 + +# Linux (ARMv8) +$(package)_target_aarch64_linux:=aarch64-unknown-linux-gnu +$(package)_sha256_hash_aarch64_linux:=9bf796a6ec5b004813ebd0b650775a7c6a4f3aae97ad362ae294798dca4f3b23 + +# Linux (RISC-V 64) +$(package)_target_riscv64_linux:=riscv64gc-unknown-linux-gnu +$(package)_sha256_hash_riscv64_linux:=bcbd81e49d72e6907c92ce7d1ba5b25b02bbd85f94cb21567c931aad1d3e3ab7 + +# Linux (ARMv7, hard float) +$(package)_target_arm_linux:=armv7-unknown-linux-gnueabihf +$(package)_sha256_hash_arm_linux:=0685de03c96ae65212b519d98116ad581c7ef46ca24acad1364895b7907d71be + +# Linux (POWER, big endian) +$(package)_target_powerpc64_linux:=powerpc64-unknown-linux-gnu +$(package)_sha256_hash_powerpc64_linux:=f23c066e7bba9d2216e41b6add0cb429c7cb7f90b449918c5370fbcb88b0dd88 + +# Windows (x86_64) +$(package)_target_x86_64_mingw32:=x86_64-pc-windows-gnu +$(package)_sha256_hash_x86_64_mingw32:=5bb599a541fcb9c0edc00e512570f60d2262623f1e2a19a44cce3a7a97208788 + +# macOS (x86_64) +$(package)_target_x86_64_darwin:=x86_64-apple-darwin +$(package)_sha256_hash_x86_64_darwin:=48b9835058a8baa4ff5e4387f3772c572a017a2b13393c46e151615c54e322e9 + +# macOS (ARMv8) +$(package)_target_aarch64_darwin:=aarch64-apple-darwin +$(package)_sha256_hash_aarch64_darwin:=2de831ef563ce772519a4d18ba2659f0f7428d497ef66dad24b5a35e8f8cd177 + +$(package)_target:=$($(package)_target_$(host_arch)_$(host_os)) +$(package)_sha256_hash:=$($(package)_sha256_hash_$(host_arch)_$(host_os)) + +ifeq ($($(package)_target),) +$(error rust_stdlib has no Rust standard library for $(host)) +endif + +$(package)_file_name:=rust-std-$($(package)_version)-$($(package)_target).tar.xz + +# Build scripts and proc macros need the build machine's standard library; +# when it is not the host's, it comes as a second archive. +ifneq ($(build_arch)_$(build_os),$(host_arch)_$(host_os)) +$(package)_build_target:=$($(package)_target_$(build_arch)_$(build_os)) +$(package)_build_file_name:=rust-std-$($(package)_version)-$($(package)_build_target).tar.xz +$(package)_build_sha256_hash:=$($(package)_sha256_hash_$(build_arch)_$(build_os)) +$(package)_extra_sources:=$($(package)_build_file_name) +$(package)_fetched_id:=$($(package)_build_sha256_hash) + +define $(package)_fetch_cmds +$(call fetch_file,$(package),$($(package)_download_path),$($(package)_file_name),$($(package)_file_name),$($(package)_sha256_hash)) && \ +$(call fetch_file,$(package),$($(package)_download_path),$($(package)_build_file_name),$($(package)_build_file_name),$($(package)_build_sha256_hash)) +endef + +define $(package)_extract_cmds + echo "$($(package)_sha256_hash) $($(package)_source)" > .$($(package)_file_name).hash && \ + echo "$($(package)_build_sha256_hash) $($(package)_source_dir)/$($(package)_build_file_name)" >> .$($(package)_file_name).hash && \ + $(build_SHA256SUM) -c .$($(package)_file_name).hash && \ + $(build_TAR) --no-same-owner --strip-components=1 -xf $($(package)_source) && \ + $(build_TAR) --no-same-owner --strip-components=1 -xf $($(package)_source_dir)/$($(package)_build_file_name) +endef +endif + +define $(package)_stage_cmds + mkdir -p $($(package)_staging_dir)$(build_prefix)/lib/rustlib && \ + $(foreach target,$($(package)_target) $($(package)_build_target),cp -R rust-std-$(target)/lib/rustlib/$(target) $($(package)_staging_dir)$(build_prefix)/lib/rustlib/ && ) true +endef From 3a4de8ad2f29ef9b4c3e715e084986dd1d75dfd4 Mon Sep 17 00:00:00 2001 From: pasta Date: Thu, 24 Sep 2026 21:03:58 -0500 Subject: [PATCH 2/4] build(depends): build dash-sdk-cxx behind a PLATFORM_GUI knob PLATFORM_GUI=1 adds native_rust, rust_stdlib, prebuilt protoc 32.0 (native_protobuf) and platform_cxx, which builds dash-sdk-cxx, the C++ binding of the Dash Platform SDK (packages/rs-sdk-cxx of dashpay/platform), and installs libdash_sdk_cxx.a, its headers (dash/sdk/ffi.h, dash/sdk/callbacks.h, rust/cxx.h) and dash_sdk_cxx.pc. The knob follows MULTIPROCESS: default package sets are unchanged, and config.site sets --enable-platform-gui to auto, which configure keeps on only when the GUI and the wallet are built. Combining it with NO_QT or NO_WALLET is an error, since the binding is for the GUI wallet only. depends/README.md and doc/dependencies.md describe it as an opt-in developer build: Guix refuses it, release binaries are built without it, CI builds and tests it on x86_64 Linux only, and its Rust and protoc are pinned prebuilt binaries. The README names the hosts it is not available for: powerpc64-linux-gnu, and hosts rust_stdlib.mk has no entry for, such as powerpc64le-linux-gnu. platform_cxx is built with cargo --frozen --offline from two sha256-pinned archives, the Platform source tarball at the pinned commit and a crate bundle; depends never vendors crates. Both archives must be on the depends sources mirror before this is merged. funcs.mk names a package's download stamp after its version and primary sha256 only. A new optional $(package)_fetched_id adds to that name. native_rust (its cargo archive), rust_stdlib (in cross builds, the build machine's standard library) and platform_cxx (the crate bundle) set it to the hash of their second archive, so that the archive is fetched again when it changes while the version and primary hash stay the same. Otherwise a stale archive and stamp, as the sources cache can restore them, pass the fetch step and fail only at extraction. Every other package's stamp name is unchanged. contrib/devtools/platform-bundle.sh produces the bundle reproducibly from a commit: Platform's own Cargo configuration removed, workspace trimmed to the crate, Cargo.lock pruned to it, cargo vendor --locked --versioned-dirs, crates outside the build closure reduced to their manifests, the Tenderdash source archive for the tag the lock pins together with TENDERDASH_COMMITISH set to that tag, and tar and gzip with fixed metadata. It prints the pins for platform_cxx.mk. Only the bundle's Cargo configuration is used: Cargo runs from / with --config, its home is private, and variables that would change the build (wrappers, CARGO_BUILD_*, CARGO_PROFILE_*, CARGO_TARGET_*, per-target variables named after either triple, in either spelling, the generic CC/CFLAGS/AR and HOST_*/TARGET_* fallbacks cc-rs reads, TENDERDASH_*) are unset. The depends compilers and flags are then set in Cargo's own environment. The release profile is pinned to Platform's (Cargo's default, panic=unwind). The depends host compiler links the crate and compiles its C and C++, the build compiler links build scripts and proc macros, and the build directory is remapped out of the objects. The build refuses a dependency graph that reaches the trusted context provider, a general-purpose HTTP client or a system TLS library, matched by exact crate name. ureq stays allowed: it is only tenderdash-proto- compiler's archive downloader, which never runs because the bundle carries the archive and Cargo is offline. The system libraries the archive needs are a vetted per-OS list in platform_cxx.mk, which dash_sdk_cxx.pc passes on. The crate is built with cargo rustc --crate-type staticlib and --print=native-static-libs, and check-native-libs.sh fails the build if rustc reports a library that is neither vetted nor in the commented ignore set (the toolchain's C and C++ runtimes; glibc's -lutil and -lrt, which symbol-check.py does not allow and the standard library does not use; macOS system defaults). At dashpay/platform dc4dc8e80ef8, the pin before fb463c282ea0, rustc 1.98.1 reports for aarch64-apple-darwin: -lc++ -framework Security -framework CoreFoundation -liconv -lSystem -lc -lm On mingw-w64 rustc also reports -lwindows.0.52.0, the import library windows-targets 0.52 bundles (socket2 0.5, through hyper-util). It is ignored: every function it names is in the vetted mingw-w64 import libraries, and the link fails loudly if a later pin needs one that is not. The mingw-w64 list is not within symbol-check.py's allowed libraries (ntdll.dll, and the DLLs raw-dylib imports add, which rustc never reports); Guix refuses PLATFORM_GUI, so symbol-check.py never sees these builds. PLATFORM_GUI is refused on powerpc64-linux-gnu before anything is fetched: Rust links linux-gnu targets with its bundled rust-lld, which rejects big-endian POWER's ELFv1 objects, and the options to use the depends linker instead are unstable there. Co-Authored-By: Claude Opus 5.5 --- contrib/devtools/README.md | 16 ++ contrib/devtools/platform-bundle.sh | 207 ++++++++++++++ depends/Makefile | 11 + depends/README.md | 5 + depends/config.site.in | 4 + depends/funcs.mk | 2 +- depends/packages.md | 7 + depends/packages/native_protobuf.mk | 43 +++ depends/packages/packages.mk | 3 + depends/packages/platform_cxx.mk | 252 ++++++++++++++++++ depends/patches/platform_cxx/build-linker.sh | 8 + .../patches/platform_cxx/check-native-libs.sh | 42 +++ depends/patches/platform_cxx/rustc-linker.sh | 10 + doc/dependencies.md | 11 + 14 files changed, 620 insertions(+), 1 deletion(-) create mode 100755 contrib/devtools/platform-bundle.sh create mode 100644 depends/packages/native_protobuf.mk create mode 100644 depends/packages/platform_cxx.mk create mode 100755 depends/patches/platform_cxx/build-linker.sh create mode 100755 depends/patches/platform_cxx/check-native-libs.sh create mode 100755 depends/patches/platform_cxx/rustc-linker.sh diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md index 6bcdf93f6df5..bc9fc492d819 100644 --- a/contrib/devtools/README.md +++ b/contrib/devtools/README.md @@ -213,3 +213,19 @@ Refreshes the sha256 pins of the prebuilt Rust toolchain changed; each downloaded archive must match the `.sha256` file published next to it. `--check` compares the pins with the published `.sha256` files instead of rewriting them. + +platform-bundle.sh +================== + +Produces the crate bundle from which `depends/packages/platform_cxx.mk` builds +`dash-sdk-cxx` (the C++ binding of the Dash Platform SDK) for a given +`dashpay/platform` commit, and prints the hashes to pin in `platform_cxx.mk`. +The bundle includes the Tenderdash source archive for the tag the commit's +`Cargo.lock` pins, so the two cannot disagree. Requires the Cargo version pinned in `native_rust.mk`, +GNU tar, GNU gzip (set `TAR` and `GZIP_PROG` if they are installed under other +names) and a `TMPDIR` with no `.cargo/config.toml` in any parent directory. +The output is reproducible: rerunning it for the same commit yields the same +bundle hash on any machine. The Platform tarball and the bundle are then +uploaded to the depends sources mirror. + + contrib/devtools/platform-bundle.sh diff --git a/contrib/devtools/platform-bundle.sh b/contrib/devtools/platform-bundle.sh new file mode 100755 index 000000000000..c16b93910434 --- /dev/null +++ b/contrib/devtools/platform-bundle.sh @@ -0,0 +1,207 @@ +#!/usr/bin/env bash +# Copyright (c) 2026 The Dash Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +export LC_ALL=C +set -euo pipefail + +# Produces the crate bundle that depends/packages/platform_cxx.mk builds +# dash-sdk-cxx from, for a given dashpay/platform commit. +# +# The bundle holds a Cargo workspace trimmed to packages/rs-sdk-cxx, the +# commit's Cargo.lock pruned to that workspace (entries are only removed, never +# changed), every locked crate vendored with `cargo vendor --locked +# --versioned-dirs`, the Tenderdash source archive tenderdash-proto's build +# script generates its protobuf code from (tenderdash/tenderdash-.zip, for +# the rs-tenderdash-abci tag the lock pins), and a .cargo/config.toml that +# replaces all crate sources with the vendored directory and sets +# TENDERDASH_COMMITISH to that same tag. Vendored crates outside the build +# closure of dash-sdk-cxx (dev-dependencies and crates only other +# workspace members use) are reduced to their manifest and empty target files: +# Cargo needs them to resolve the lock, never to build. The archive is written +# with a fixed file order, owner, mode and mtime, so the same commit yields the +# same sha256 on every machine that uses the pinned Rust version, GNU tar and +# GNU gzip (and as long as GitHub serves the same Tenderdash zip). +# +# This is the only step that downloads crates. The maintainer bumping the +# pin runs it, updates the hashes in platform_cxx.mk from its output, and +# uploads the Platform tarball and the bundle to the depends sources mirror; +# reviewers rerun it to reproduce the hash. + +usage() { + echo "Usage: $0 " >&2 + echo >&2 + echo "Writes platform-.tar.gz and dash-sdk-cxx-crates-.tar.gz to" >&2 + echo "SOURCES_PATH (default: depends/sources), and keeps the downloaded" >&2 + echo "tenderdash-.zip there." >&2 + exit 1 +} + +[ $# -eq 1 ] || usage +COMMIT="$1" +[[ "$COMMIT" =~ ^[0-9a-f]{40}$ ]] || { echo "error: expected a full 40-character commit hash" >&2; exit 1; } + +TOPDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +SOURCES_PATH="${SOURCES_PATH:-$TOPDIR/depends/sources}" +mkdir -p "$SOURCES_PATH" +# The script changes directory below; a relative path must not follow it. +SOURCES_PATH="$(cd "$SOURCES_PATH" && pwd)" +# shellcheck disable=SC2016 +RUST_VERSION="$(sed -n 's/^\$(package)_version:=//p' "$TOPDIR/depends/packages/native_rust.mk")" +CARGO="${CARGO:-cargo}" +TAR="${TAR:-tar}" +GZIP_PROG="${GZIP_PROG:-gzip}" + +# cargo vendor output (normalized manifests) depends on the Cargo version. +export RUSTUP_TOOLCHAIN="${RUSTUP_TOOLCHAIN:-$RUST_VERSION}" +case "$("$CARGO" --version)" in + "cargo $RUST_VERSION "*) ;; + *) echo "error: $CARGO is not Cargo $RUST_VERSION (the version pinned in native_rust.mk)" >&2; exit 1 ;; +esac +case "$("$TAR" --version)" in + *"GNU tar"*) ;; + *) echo "error: $TAR is not GNU tar; set TAR" >&2; exit 1 ;; +esac +case "$("$GZIP_PROG" --version)" in + *"Free Software Foundation"*) ;; + *) echo "error: $GZIP_PROG is not GNU gzip; set GZIP_PROG" >&2; exit 1 ;; +esac + +WORKDIR="$(mktemp -d "${TMPDIR:-/tmp}/platform-bundle.XXXXXX")" +trap 'rm -rf "$WORKDIR"' EXIT +# Cargo looks for configuration above the physical directory it runs in. +WORKDIR="$(cd "$WORKDIR" && pwd -P)" +# A private Cargo home keeps the cached registries and the Cargo home's +# config.toml out of the bundle. Cargo also reads .cargo/config.toml from every +# parent of the directory it runs in, so the work directory must have none +# (TMPDIR under a home directory with ~/.cargo/config.toml fails here). +export CARGO_HOME="$WORKDIR/cargo-home" +dir="$WORKDIR" +while :; do + dir="$(dirname "$dir")" + for config in "$dir/.cargo/config" "$dir/.cargo/config.toml"; do + if [ -e "$config" ]; then + echo "error: $config would configure Cargo; set TMPDIR to a directory outside its tree" >&2 + exit 1 + fi + done + [ "$dir" != / ] || break +done + +# Downloads $1 to SOURCES_PATH/$2, unless a copy there passes the integrity +# test $3 (a partial or corrupt one is downloaded again). +fetch() { + local url="$1" file="$2" test="$3" + if [ -f "$SOURCES_PATH/$file" ] && $test "$SOURCES_PATH/$file" 2> /dev/null; then + return + fi + rm -f "$SOURCES_PATH/$file" + curl --location --fail --silent --show-error --retry 3 -o "$SOURCES_PATH/$file.temp" "$url" + $test "$SOURCES_PATH/$file.temp" + mv "$SOURCES_PATH/$file.temp" "$SOURCES_PATH/$file" +} + +gzip_test() { + "$GZIP_PROG" -t "$1" +} + +zip_test() { + python3 -c 'import sys, zipfile; sys.exit(zipfile.ZipFile(sys.argv[1]).testzip() is not None)' "$1" +} + +sha256() { + if command -v sha256sum >/dev/null; then + sha256sum "$1" | cut -d' ' -f1 + else + shasum -a 256 "$1" | cut -d' ' -f1 + fi +} + +# Prints "name version source" for every [[package]] of a Cargo.lock. +lock_entries() { + awk '/^\[\[package\]\]$/ { if (name) print name, version, source; name = version = source = "" } + /^name = / { name = $3 } + /^version = / { version = $3 } + /^source = / { source = $3 } + END { if (name) print name, version, source }' "$1" | sort +} + +PLATFORM_ARCHIVE="platform-$COMMIT.tar.gz" +fetch "https://github.com/dashpay/platform/archive/$COMMIT.tar.gz" "$PLATFORM_ARCHIVE" gzip_test + +SRC="$WORKDIR/src" +mkdir -p "$SRC" +"$TAR" --strip-components=1 -xzf "$SOURCES_PATH/$PLATFORM_ARCHIVE" -C "$SRC" +cd "$SRC" + +# Platform's own Cargo configuration is not shipped; the lock is pruned and +# vendored without it, as depends builds it. +rm -rf .cargo + +# Trim the workspace to the one crate depends builds and prune the lock to it. +cp Cargo.lock "$WORKDIR/Cargo.lock.pinned" +awk '/^members = \[/ { print "members = [\"packages/rs-sdk-cxx\"]"; skip = !/\]/; next } + skip && /^\]/ { skip = 0; next } + !skip' Cargo.toml > "$WORKDIR/Cargo.toml" +mv "$WORKDIR/Cargo.toml" Cargo.toml +"$CARGO" metadata --format-version 1 > /dev/null +if lock_entries Cargo.lock | comm -13 <(lock_entries "$WORKDIR/Cargo.lock.pinned") - | grep .; then + echo "error: trimming the workspace changed the locked packages above" >&2 + exit 1 +fi + +TENDERDASH_TAG="$(awk '/^name = "tenderdash-proto"$/ { found = 1 } + found && /^source = / { print; exit }' Cargo.lock | + sed -n 's|.*/rs-tenderdash-abci?tag=\(v[^#]*\)#.*|\1|p')" +[ -n "$TENDERDASH_TAG" ] || { echo "error: no tagged tenderdash-proto entry in Cargo.lock" >&2; exit 1; } +TENDERDASH_ARCHIVE="tenderdash-$TENDERDASH_TAG.zip" +fetch "https://github.com/dashpay/tenderdash/archive/$TENDERDASH_TAG.zip" "$TENDERDASH_ARCHIVE" zip_test +mkdir tenderdash +cp "$SOURCES_PATH/$TENDERDASH_ARCHIVE" tenderdash/ + +mkdir .cargo +{ + echo "# Generated by contrib/devtools/platform-bundle.sh for dashpay/platform@$COMMIT" + "$CARGO" vendor --locked --versioned-dirs vendor + echo + echo "[env]" + echo "TENDERDASH_COMMITISH = \"$TENDERDASH_TAG\"" +} > "$WORKDIR/config.toml" +grep -qx 'directory = "vendor"' "$WORKDIR/config.toml" || { echo "error: cargo vendor printed no source replacement" >&2; exit 1; } +mv "$WORKDIR/config.toml" .cargo/config.toml +# From here on every crate must come from vendor/, never from the Cargo home. +rm -rf "$CARGO_HOME" + +closure() { + "$CARGO" tree --frozen -p dash-sdk-cxx -e normal,build --target all --prefix none --format '{p}' | + awk '{ sub(/^v/, "", $2); print $1 "-" $2 }' | sort -u +} +closure > "$WORKDIR/closure" +for dir in vendor/*/; do + dir="${dir%/}" + grep -qxF "${dir#vendor/}" "$WORKDIR/closure" && continue + checksum="$(sed -En 's/.*"package":(null|"[0-9a-f]*")}$/\1/p' "$dir/.cargo-checksum.json")" + find "$dir" ! -type d ! -name '*.rs' ! -path "$dir/Cargo.toml" -delete + find "$dir" -type f -name '*.rs' -print0 | while IFS= read -r -d '' file; do : > "$file"; done + find "$dir" -type d -empty -delete + printf '{"files":{},"package":%s}' "$checksum" > "$dir/.cargo-checksum.json" +done +closure | cmp -s - "$WORKDIR/closure" || { echo "error: the build closure changed after pruning" >&2; exit 1; } + +BUNDLE="dash-sdk-cxx-crates-$COMMIT.tar.gz" +"$TAR" --create --format=gnu --sort=name --mtime=@0 --owner=0 --group=0 --numeric-owner \ + --mode='u+rw,go+r-w,a+X' Cargo.toml Cargo.lock .cargo/config.toml tenderdash vendor | + "$GZIP_PROG" -9n > "$SOURCES_PATH/$BUNDLE.temp" +mv "$SOURCES_PATH/$BUNDLE.temp" "$SOURCES_PATH/$BUNDLE" + +cat < .$($(package)_file_name).hash && \ + $(build_SHA256SUM) -c .$($(package)_file_name).hash && \ + python3 -m zipfile -e $($(package)_source) . +endef + +define $(package)_stage_cmds + mkdir -p $($(package)_staging_prefix_dir)/bin $($(package)_staging_prefix_dir)/include && \ + cp bin/protoc $($(package)_staging_prefix_dir)/bin/ && \ + chmod 0755 $($(package)_staging_prefix_dir)/bin/protoc && \ + cp -R include/google $($(package)_staging_prefix_dir)/include/ +endef diff --git a/depends/packages/packages.mk b/depends/packages/packages.mk index 59232930eb38..e3299ea041ff 100644 --- a/depends/packages/packages.mk +++ b/depends/packages/packages.mk @@ -24,4 +24,7 @@ natpmp_packages=libnatpmp multiprocess_packages = libmultiprocess capnp multiprocess_native_packages = native_libmultiprocess native_capnp +platform_packages = rust_stdlib platform_cxx +platform_native_packages = native_rust native_protobuf + usdt_linux_packages=systemtap diff --git a/depends/packages/platform_cxx.mk b/depends/packages/platform_cxx.mk new file mode 100644 index 000000000000..9498834235c1 --- /dev/null +++ b/depends/packages/platform_cxx.mk @@ -0,0 +1,252 @@ +# Copyright (c) 2026 The Dash Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +# dash-sdk-cxx, the C++ binding of the Dash Platform SDK (packages/rs-sdk-cxx +# of dashpay/platform), built from two sha256-pinned archives: the Platform +# source tarball at the pinned commit, and the crate bundle that +# contrib/devtools/platform-bundle.sh produces for that commit (trimmed +# workspace, pruned Cargo.lock, vendored crates, the Tenderdash sources +# tenderdash-proto generates its protobuf code from, Cargo configuration). +# Cargo runs with --frozen and never touches the network. +# +# Both archives must be on the depends sources mirror (FALLBACK_DOWNLOAD_PATH) +# before this is merged. The bundle has no upstream URL, and GitHub does not +# promise stable bytes for the archive endpoint the tarball comes from. +# Whoever bumps the pin runs platform-bundle.sh, which prints the lines to +# update here, and uploads both. Until then, a bundle the script wrote to +# SOURCES_PATH is used as is; its hash is checked on extraction either way. + +package=platform_cxx +$(package)_version=fb463c282ea09adf93dd5d256fc9471969f7a46f +$(package)_download_path=https://github.com/dashpay/platform/archive +$(package)_download_file=$($(package)_version).tar.gz +$(package)_file_name=platform-$($(package)_version).tar.gz +$(package)_sha256_hash=8ccb913069ce8d96a32443e98e44e85c331694727cc37c321364711ddaa04039 +$(package)_crates_file_name=dash-sdk-cxx-crates-$($(package)_version).tar.gz +$(package)_crates_sha256_hash=da47a0ca89ed023f357a70e19d097f42bd4fe76221ee7bfd1c4eca0102b5f70e +$(package)_fetched_id=$($(package)_crates_sha256_hash) +$(package)_extra_sources=$($(package)_crates_file_name) +$(package)_dependencies=native_rust rust_stdlib native_protobuf +$(package)_patches=rustc-linker.sh build-linker.sh check-native-libs.sh + +# Rust links linux-gnu targets with its bundled rust-lld, which rejects the +# ELFv1 objects of big-endian POWER ("ABI version 1 is not supported"); the +# options to link with the depends linker instead are unstable on that target. +ifeq ($(host_arch)_$(host_os),powerpc64_linux) +$(error platform_cxx: PLATFORM_GUI is not supported on $(host): Rust $(native_rust_version) cannot link big-endian POWER (ELFv1)) +endif + +# The system libraries the archive needs, which dash_sdk_cxx.pc passes on +# to configure. The build fails if rustc reports one (--print=native-static-libs) +# that is neither here nor in the ignored list below. The Linux and macOS +# lists are within contrib/guix/symbol-check.py's allowed libraries. The +# mingw-w64 one is not: ntdll.dll is not allowed, and the DLLs that raw-dylib +# imports add (api-ms-win-core-synch-l1-2-0.dll, bcryptprimitives.dll, +# crypt32.dll) are never reported by rustc. Guix refuses PLATFORM_GUI, so +# symbol-check.py does not see these builds. +$(package)_native_libs_linux=-lpthread -ldl -lm +$(package)_native_libs_darwin=-framework Security -framework CoreFoundation +$(package)_native_libs_mingw32=-lbcrypt -ladvapi32 -lkernel32 -lntdll -luserenv -lws2_32 -ldbghelp + +# Libraries rustc reports that are deliberately not passed on: +# - the C++ runtime the cxx bridge needs, which the C++ link of dash-qt +# already has: -lstdc++, and -lc++ on macOS; +# - the toolchain's own C runtime, which every link already has: -lc, +# -lgcc_s, -lgcc_eh and -lgcc, and on mingw-w64 -lmsvcrt, -lmingwex, +# -lmingw32 and -l:libpthread.a; +# - glibc's -lutil and -lrt: symbol-check.py does not allow them, and the +# glibc standard library imports nothing from them (every symbol it uses +# from glibc 2.31 is in libc, libpthread, libdl or libm); +# - macOS's -liconv, -lSystem, -lc and -lm, which the macOS linker adds anyway; +# - on mingw-w64, -lwindows.0.52.0, the import library windows-targets 0.52 +# bundles (socket2 0.5, through hyper-util): every function it names is in +# the mingw-w64 import libraries vetted above, and dash-qt links without it. +$(package)_native_libs_ignored_linux=-lstdc++ -lc -lgcc_s -lgcc_eh -lgcc -lutil -lrt +$(package)_native_libs_ignored_darwin=-lc++ -liconv -lSystem -lc -lm +$(package)_native_libs_ignored_mingw32=-lstdc++ -lmsvcrt -lmingwex -lmingw32 -lgcc_eh -lgcc -l:libpthread.a -lwindows.0.52.0 + +define $(package)_fetch_cmds +$(call fetch_file,$(package),$($(package)_download_path),$($(package)_download_file),$($(package)_file_name),$($(package)_sha256_hash)) && \ +( echo "$($(package)_crates_sha256_hash) $($(package)_source_dir)/$($(package)_crates_file_name)" | $(build_SHA256SUM) -c >/dev/null 2>&1 || \ + ( rm -f $($(package)_source_dir)/$($(package)_crates_file_name) && \ + $(call fetch_file_inner,$(package),$(FALLBACK_DOWNLOAD_PATH),$($(package)_crates_file_name),$($(package)_crates_file_name),$($(package)_crates_sha256_hash)) ) ) +endef + +# Only packages/ is needed from the Platform tarball; the bundle supplies the +# workspace manifest, lock and Cargo configuration. +define $(package)_extract_cmds + echo "$($(package)_sha256_hash) $($(package)_source)" > .$($(package)_file_name).hash && \ + echo "$($(package)_crates_sha256_hash) $($(package)_source_dir)/$($(package)_crates_file_name)" >> .$($(package)_file_name).hash && \ + $(build_SHA256SUM) -c .$($(package)_file_name).hash && \ + $(build_TAR) --no-same-owner --strip-components=1 -xf $($(package)_source) platform-$($(package)_version)/packages && \ + $(build_TAR) --no-same-owner -xf $($(package)_source_dir)/$($(package)_crates_file_name) +endef + +$(package)_rust_target=$(rust_stdlib_target) +$(package)_cc_target=$(subst -,_,$($(package)_rust_target)) +$(package)_build_linker_var:=CARGO_TARGET_$(shell echo $(native_rust_build_target) | tr a-z- A-Z_)_LINKER + +# Only the bundle's .cargo/config.toml configures Cargo: +# - Cargo reads .cargo/config.toml in the directory it runs in and in every +# parent, whatever --manifest-path says, so it runs from / and is given the +# bundle's file with --config. Configuration above the depends tree, such as +# ~/.cargo/config.toml when the tree is under a home directory, is therefore +# never read, and the build works wherever the tree is; preprocess fails if +# / itself has one. +# - The Cargo home is private and empty. +# - Environment variables that would change the build are removed: +# RUSTC_WORKSPACE_WRAPPER, RUSTC_BOOTSTRAP, CARGO_ENCODED_RUSTFLAGS, +# __CARGO_DEFAULT_LIB_METADATA, and all CARGO_BUILD_*, CARGO_PROFILE_*, +# CARGO_TARGET_* and CARGO_UNSTABLE_* ones, and every variable named after +# the host's or the build machine's Rust triple in either spelling (such as +# CC_x86_64-unknown-linux-gnu, CFLAGS_x86_64_unknown_linux_gnu or +# CXXSTDLIB_aarch64_unknown_linux_gnu); every TENDERDASH_ +# variable, among them TENDERDASH_COMMITISH, which the bundle's +# configuration sets to the tag of the Tenderdash archive it carries, and +# TENDERDASH_DIR and TENDERDASH_PROTO_OUT_DIR, which would let +# tenderdash-proto's build script take protobuf sources from outside the +# bundle; and the generic compiler variables cc-rs and cxx-build fall back +# to when no per-target one is set (CC, CFLAGS, HOST_CFLAGS, TARGET_CC, +# CRATE_CC_NO_DEFAULTS, CXXSTDLIB and the like), which would otherwise +# reach the C and C++ that build scripts compile for the build machine. +# The compilers and flags cc-rs is meant to use are set afterwards in +# Cargo's own environment, which env applies after these removals. +# CXXSTDLIB stays unset rather than empty: empty would link no C++ library. +# - The release profile is pinned to Platform's, which is Cargo's default: +# opt-level 3, no debug info, no LTO, 16 codegen units, no incremental +# compilation, and unwinding panics (the crate refuses panic=abort). Nothing +# Cargo links here is installed (build scripts, the cdylib dash-sdk also +# declares), so nothing is stripped; on macOS that would need rust-objcopy +# and an LLVM library native_rust does not stage. +$(package)_unset_env:=RUSTC_WORKSPACE_WRAPPER RUSTC_BOOTSTRAP CARGO_ENCODED_RUSTFLAGS __CARGO_DEFAULT_LIB_METADATA +$(package)_unset_env+=$(sort TENDERDASH_DIR TENDERDASH_COMMITISH TENDERDASH_PROTO_OUT_DIR $(filter TENDERDASH_%,$(.VARIABLES))) +$(package)_unset_env+=$(filter CARGO_BUILD_% CARGO_PROFILE_% CARGO_TARGET_% CARGO_UNSTABLE_%,$(.VARIABLES)) +$(package)_unset_env+=$(filter $(foreach t,$(rust_stdlib_target) $(native_rust_build_target),%_$(t) %_$(subst -,_,$(t))),$(.VARIABLES)) +$(package)_unset_env+=CC CXX AR ARFLAGS RANLIB RANLIBFLAGS CFLAGS CXXFLAGS CRATE_CC_NO_DEFAULTS CXXSTDLIB +$(package)_unset_env+=TARGET_CC TARGET_CXX TARGET_AR TARGET_ARFLAGS TARGET_RANLIB TARGET_RANLIBFLAGS TARGET_CFLAGS TARGET_CXXFLAGS TARGET_CXXSTDLIB +$(package)_unset_env+=HOST_AR HOST_ARFLAGS HOST_RANLIB HOST_RANLIBFLAGS HOST_CFLAGS HOST_CXXFLAGS HOST_CXXSTDLIB +$(package)_profile_env:=CARGO_PROFILE_RELEASE_OPT_LEVEL=3 CARGO_PROFILE_RELEASE_DEBUG=false +$(package)_profile_env+=CARGO_PROFILE_RELEASE_LTO=false CARGO_PROFILE_RELEASE_CODEGEN_UNITS=16 +$(package)_profile_env+=CARGO_PROFILE_RELEASE_PANIC=unwind CARGO_PROFILE_RELEASE_INCREMENTAL=false +$(package)_profile_env+=CARGO_PROFILE_RELEASE_STRIP=false CARGO_INCREMENTAL=0 + +# RUSTFLAGS takes the place of Platform's .cargo/config.toml, which the bundle +# does not carry. Of what that file sets, --cfg tokio_unstable only enables +# tokio APIs (runtime metrics, task hooks, io-uring) that nothing in +# dash-sdk-cxx's dependency graph uses, target-feature=-crt-static only +# changes musl targets (glibc targets link the C runtime dynamically anyway), +# and target-cpu=x86-64 and -lstdc++ are the defaults or only matter for +# executables; none of them is set here. +# +# For the host, the depends compiler links (through rustc-linker.sh), the C and +# C++ sources in the crate closure (ring, blst, blake3, secp256k1, the cxx +# bridge) are compiled with the depends compiler and flags, and the build +# directory is remapped out of both the Rust and the C objects. Build scripts +# and proc macros run on the build machine; build-linker.sh links them with the +# depends build compiler, which also compiles any C they need (CC_ and HOST_CC; when the build and host triples are the same, the host's +# CC_ wins and the host and build compilers are the same machine's). +# +# For windows-gnu, rustc creates the import libraries of raw-dylib imports +# (windows-link, which the Rust standard library and windows-sys use) with +# the mingw-w64 dlltool. +define $(package)_set_vars +$(package)_cargo_env = CARGO_HOME=$$($(package)_build_dir)/.cargo-home +$(package)_cargo_env += CARGO_TARGET_DIR=$$($(package)_build_dir)/target +$(package)_cargo_env += $($(package)_profile_env) +$(package)_cargo_env += $($(package)_build_linker_var)=$$($(package)_build_dir)/build-linker.sh +$(package)_cargo_env += CC_$($(package)_cc_target)="$$($(package)_cc)" CXX_$($(package)_cc_target)="$$($(package)_cxx)" +$(package)_cargo_env += AR_$($(package)_cc_target)="$$($(package)_ar)" +$(package)_cargo_env += CFLAGS_$($(package)_cc_target)="$$($(package)_cppflags) $$($(package)_cflags) -ffile-prefix-map=$(BASEDIR)=/build" +$(package)_cargo_env += CXXFLAGS_$($(package)_cc_target)="$$($(package)_cppflags) $$($(package)_cxxflags) -ffile-prefix-map=$(BASEDIR)=/build" +$(package)_cargo_env += HOST_CC="$(build_CC)" HOST_CXX="$(build_CXX)" +ifneq ($(native_rust_build_target),$($(package)_rust_target)) +$(package)_cargo_env += CC_$(subst -,_,$(native_rust_build_target))="$(build_CC)" CXX_$(subst -,_,$(native_rust_build_target))="$(build_CXX)" +endif +$(package)_cargo = cd / && env $$(addprefix -u ,$$($(package)_unset_env)) $$($(package)_cargo_env) \ + cargo --config $$($(package)_build_dir)/.cargo/config.toml +$(package)_rustflags = -C linker=$$($(package)_build_dir)/rustc-linker.sh --remap-path-prefix=$(BASEDIR)=/build +$(package)_rustflags_mingw32 = -C dlltool=$(host_toolchain)dlltool +$(package)_build_env += RUSTC="$(build_prefix)/bin/rustc" RUSTC_WRAPPER= +$(package)_build_env += RUSTFLAGS="$$($(package)_rustflags) $$($(package)_rustflags_$(host_os))" +$(package)_build_env += DEPENDS_CC="$$($(package)_cc)" DEPENDS_LDFLAGS="$$($(package)_ldflags)" +$(package)_build_env += DEPENDS_BUILD_CC="$(build_CC)" +$(package)_build_env += PROTOC="$(build_prefix)/bin/protoc" PROTOC_INCLUDE="$(build_prefix)/include" +ifeq ($(host_os),darwin) +$(package)_build_env += MACOSX_DEPLOYMENT_TARGET=$(OSX_MIN_VERSION) +ifneq ($(build_os),darwin) +$(package)_build_env += SDKROOT="$(OSX_SDK)" +endif +endif +endef + +# tenderdash-proto's build script extracts its sources from +# tenderdash-$$TENDERDASH_COMMITISH.zip in its cache directory +# (CARGO_TARGET_DIR) and would download the archive if it were missing; the +# bundle's configuration sets the tag of the archive the bundle carries. +define $(package)_preprocess_cmds + for config in /.cargo/config /.cargo/config.toml; do \ + if test -e $$$$config; then echo "$$$$config would configure Cargo; remove it" >&2; exit 1; fi; \ + done && \ + cp $($(package)_patch_dir)/rustc-linker.sh $($(package)_patch_dir)/build-linker.sh . && \ + chmod +x rustc-linker.sh build-linker.sh && \ + tag=$$$$(sed -n 's/^TENDERDASH_COMMITISH = "\(.*\)"$$$$/\1/p' .cargo/config.toml) && \ + if ! test -f "tenderdash/tenderdash-$$$$tag.zip"; then \ + echo "the crate bundle has no Tenderdash archive for TENDERDASH_COMMITISH \"$$$$tag\"" >&2; exit 1; \ + fi && \ + mkdir -p target && \ + cp "tenderdash/tenderdash-$$$$tag.zip" target/ +endef + +# The build fails if the dependency graph (normal and build dependencies, both +# of which Cargo compiles) reaches a trusted third-party context provider, a +# general-purpose HTTP client or a system TLS library (OpenSSL, native-tls): +# every trust input comes from Core. ureq is allowed: it is only +# tenderdash-proto-compiler's archive downloader, which never runs because the +# bundle supplies the archive and Cargo is offline. The graph goes to a file +# first, so that a failing cargo tree fails the build. +# +# The crate is built as a static library only, with rustc printing the system +# libraries the archive needs; check-native-libs.sh compares them with the +# vetted and ignored lists above. The build log goes to a file as well, and +# the exit status to another, since a pipeline has the status of tee. +$(package)_forbidden_crates:=rs-sdk-trusted-context-provider|reqwest|isahc|attohttpc|surf|curl|curl-sys +$(package)_forbidden_crates:=$($(package)_forbidden_crates)|openssl|openssl-sys|native-tls|tokio-native-tls|hyper-tls + +define $(package)_build_cmds + ( $($(package)_cargo) tree --frozen --manifest-path $($(package)_build_dir)/Cargo.toml \ + -p dash-sdk-cxx -e normal,build --target $($(package)_rust_target) --prefix none --format '{p}' ) > cargo-tree.txt && \ + if grep -E '^($($(package)_forbidden_crates)) v[0-9]' cargo-tree.txt; then \ + echo "dash-sdk-cxx depends on a forbidden crate" >&2; exit 1; \ + fi && \ + ( ( $($(package)_cargo) rustc --frozen --offline --release --color never --manifest-path $($(package)_build_dir)/Cargo.toml \ + -p dash-sdk-cxx --lib --crate-type staticlib --target $($(package)_rust_target) \ + -- --print=native-static-libs ); echo $$$$? > cargo-rustc.status ) 2>&1 | tee cargo-rustc.log && \ + test "$$$$(cat cargo-rustc.status)" = 0 && \ + sh $($(package)_patch_dir)/check-native-libs.sh cargo-rustc.log \ + "$($(package)_native_libs_$(host_os))" "$($(package)_native_libs_ignored_$(host_os))" +endef + +# The crate's build script stages the generated bridge header dash/sdk/ffi.h, +# dash/sdk/callbacks.h and the cxx runtime header rust/cxx.h under +# target//release/include; that tree, the static archive and +# dash_sdk_cxx.pc are the installed interface. The +# .pc file locates the prefix from its own directory. +define $(package)_stage_cmds + mkdir -p $($(package)_staging_prefix_dir)/include $($(package)_staging_prefix_dir)/lib/pkgconfig && \ + cp -R target/$($(package)_rust_target)/release/include/. $($(package)_staging_prefix_dir)/include/ && \ + cp target/$($(package)_rust_target)/release/libdash_sdk_cxx.a $($(package)_staging_prefix_dir)/lib/ && \ + printf '%s\n' \ + 'prefix=$$$${pcfiledir}/../..' \ + 'exec_prefix=$$$${prefix}' \ + 'libdir=$$$${prefix}/lib' \ + 'includedir=$$$${prefix}/include' \ + '' \ + 'Name: dash_sdk_cxx' \ + 'Description: C++ binding of the Dash Platform SDK' \ + 'Version: $($(package)_version)' \ + 'Cflags: -I$$$${includedir}' \ + 'Libs: -L$$$${libdir} -ldash_sdk_cxx $($(package)_native_libs_$(host_os))' \ + > $($(package)_staging_prefix_dir)/lib/pkgconfig/dash_sdk_cxx.pc +endef diff --git a/depends/patches/platform_cxx/build-linker.sh b/depends/patches/platform_cxx/build-linker.sh new file mode 100755 index 000000000000..da7d04b6a9cc --- /dev/null +++ b/depends/patches/platform_cxx/build-linker.sh @@ -0,0 +1,8 @@ +#!/bin/sh +export LC_ALL=C +set -f +# Links build scripts and proc macros, which run on the build machine, with the +# depends build compiler. rustc's `-C linker=` takes a single executable, but +# DEPENDS_BUILD_CC is a command line (on macOS with an -isysroot flag). +# shellcheck disable=SC2086 +exec $DEPENDS_BUILD_CC "$@" diff --git a/depends/patches/platform_cxx/check-native-libs.sh b/depends/patches/platform_cxx/check-native-libs.sh new file mode 100755 index 000000000000..51d1bad850f3 --- /dev/null +++ b/depends/patches/platform_cxx/check-native-libs.sh @@ -0,0 +1,42 @@ +#!/bin/sh +export LC_ALL=C +set -f +# Usage: check-native-libs.sh +# +# Fails unless every system library rustc reports for the static archive (the +# "native-static-libs" note in the build log) is vetted or ignored, so that +# whoever bumps the Platform pin or the Rust toolchain notices a new one. +log=$1 +vetted=$2 +ignored=$3 + +libs=$(sed -n 's/^note: native-static-libs: //p' "$log") +if test -z "$libs"; then + echo "rustc reported no native-static-libs in $log" >&2 + exit 1 +fi +echo "rustc native-static-libs: $libs" + +unvetted= +framework= +for word in $libs; do + if test "$word" = -framework; then + framework=yes + continue + fi + lib=$word + if test -n "$framework"; then + lib="-framework $word" + framework= + fi + case " $vetted $ignored " in + *" $lib "*) ;; + *) unvetted="$unvetted $lib" ;; + esac +done + +if test -n "$unvetted"; then + echo "rustc reports system libraries platform_cxx.mk has not vetted:$unvetted" >&2 + echo "Check each against contrib/guix/symbol-check.py, then add it to platform_cxx_native_libs_, or with the reason to platform_cxx_native_libs_ignored_." >&2 + exit 1 +fi diff --git a/depends/patches/platform_cxx/rustc-linker.sh b/depends/patches/platform_cxx/rustc-linker.sh new file mode 100755 index 000000000000..db2063792520 --- /dev/null +++ b/depends/patches/platform_cxx/rustc-linker.sh @@ -0,0 +1,10 @@ +#!/bin/sh +export LC_ALL=C +set -f +# rustc's `-C linker=` takes a single executable, but the depends compiler is +# a command line (target and sysroot flags, under Guix an `env -u ...` prefix). +# platform_cxx.mk passes that command in DEPENDS_CC and the link flags in +# DEPENDS_LDFLAGS; word splitting them here keeps every part, and set -f keeps +# a flag with a glob character from being expanded. +# shellcheck disable=SC2086 +exec $DEPENDS_CC $DEPENDS_LDFLAGS "$@" diff --git a/doc/dependencies.md b/doc/dependencies.md index eaf67114fd32..1c22b551fbf0 100644 --- a/doc/dependencies.md +++ b/doc/dependencies.md @@ -36,6 +36,17 @@ You can find installation instructions in the `build-*.md` file for your platfor | [qrencode](../depends/packages/qrencode.mk) | [link](https://fukuchi.org/works/qrencode/) | [4.1.1](https://github.com/bitcoin/bitcoin/pull/27312) | | No | | [Qt](../depends/packages/qt.mk) | [link](https://download.qt.io/official_releases/qt/) | [5.15.18](https://github.com/dashpay/dash/pull/6949) | [5.11.3](https://github.com/bitcoin/bitcoin/pull/24132) | No | +### Dash Platform GUI (`--enable-platform-gui`, depends `PLATFORM_GUI=1` only) +`--enable-platform-gui` is an opt-in developer build. Official release binaries are built without it (Guix refuses +`PLATFORM_GUI`), and CI builds and tests it on x86_64 Linux only. Rust and protoc are pinned prebuilt binaries verified +by SHA256. + +| Dependency | Releases | Version used | Minimum required | Runtime | +| --- | --- | --- | --- | --- | +| [Rust](../depends/packages/native_rust.mk) (compiler and standard library) | [link](https://forge.rust-lang.org/infra/other-installation-methods.html#standalone-installers) | 1.98.1 | 1.98.1 | No | +| [protoc](../depends/packages/native_protobuf.mk) (build tool) | [link](https://github.com/protocolbuffers/protobuf/releases) | 32.0 | 25.0 | No | +| [dash-sdk-cxx](../depends/packages/platform_cxx.mk) (Dash Platform SDK C++ binding) | [link](https://github.com/dashpay/platform) | commit [fb463c2...](https://github.com/dashpay/platform/tree/fb463c282ea09adf93dd5d256fc9471969f7a46f) | | No | + ### Networking | Dependency | Releases | Version used | Minimum required | Runtime | | --- | --- | --- | --- | --- | From 2525537b28ee0056b5693f8a410bdedc9128ded6 Mon Sep 17 00:00:00 2001 From: pasta Date: Thu, 24 Sep 2026 10:39:48 -0500 Subject: [PATCH 3/4] build: add --enable-platform-gui The option (default no) requires the GUI and the wallet, and checks that a program using dash-sdk-cxx, the C++ binding of the Dash Platform SDK, links: it includes dash/sdk/ffi.h and creates and shuts down a dash_sdk::PlatformClient. depends built with PLATFORM_GUI=1 sets it to auto, which becomes yes when the GUI and the wallet are built and no otherwise, so --enable-fuzz, --without-gui or --disable-wallet still configure against those depends. PLATFORM_CXX_CFLAGS and PLATFORM_CXX_LIBS come from dash_sdk_cxx.pc through PKG_CHECK_MODULES, and can be overridden as usual: the include directory, the library, and the vetted system libraries from the depends .pc. depends checks those libraries against rustc's --print=native-static-libs. The option defines ENABLE_PLATFORM_GUI and the automake conditional of the same name, under which PLATFORM_CXX_LIBS is added to the link of dash-qt, test_dash and test_dash-qt only; dashd and the other binaries never link it, and nothing references the binding yet. Co-Authored-By: Claude Opus 5.5 --- configure.ac | 52 +++++++++++++++++++++++++++++++++++++ src/Makefile.qt.include | 3 +++ src/Makefile.qttest.include | 3 +++ src/Makefile.test.include | 3 +++ 4 files changed, 61 insertions(+) diff --git a/configure.ac b/configure.ac index 4ce746a94410..85f43f177da7 100644 --- a/configure.ac +++ b/configure.ac @@ -307,6 +307,12 @@ if test "$enable_miner" = "yes"; then AC_DEFINE(ENABLE_MINER, 1, [Define this symbol if in-wallet miner should be enabled]) fi +AC_ARG_ENABLE([platform-gui], + [AS_HELP_STRING([--enable-platform-gui], + [enable Dash Platform (usernames, DashPay contacts) in the GUI; requires the GUI, the wallet and the Dash Platform SDK's C++ binding (dash-sdk-cxx) built by depends with PLATFORM_GUI=1 (default is no)])], + [enable_platform_gui=$enableval], + [enable_platform_gui=no]) + dnl Enable different -fsanitize options AC_ARG_WITH([sanitizers], [AS_HELP_STRING([--with-sanitizers], @@ -1927,6 +1933,51 @@ if test "$build_bitcoin_wallet$build_bitcoin_cli$build_bitcoin_tx$build_bitcoin_ AC_MSG_ERROR([No targets! Please specify at least one of: --with-utils --with-libs --with-daemon --with-gui --enable-fuzz(-binary) --enable-bench or --enable-tests]) fi +dnl dash-sdk-cxx, the C++ binding of the Dash Platform SDK, is a Rust static +dnl library linked into dash-qt, test_dash and test_dash-qt only. depends +dnl installs dash_sdk_cxx.pc, whose Libs are the library and the vetted system +dnl libraries it needs; depends checks those against rustc's +dnl --print=native-static-libs. depends built with PLATFORM_GUI=1 sets "auto", +dnl which turns into "no" when the GUI or the wallet is off. +if test "$enable_platform_gui" = "auto"; then + if test "$bitcoin_enable_qt" = "yes" && test "$enable_wallet" = "yes"; then + enable_platform_gui=yes + else + AC_MSG_NOTICE([the GUI or the wallet is disabled, so Dash Platform support is not built]) + enable_platform_gui=no + fi +fi +if test "$enable_platform_gui" = "yes"; then + if test "$bitcoin_enable_qt" != "yes"; then + AC_MSG_ERROR([--enable-platform-gui requires the GUI]) + fi + if test "$enable_wallet" != "yes"; then + AC_MSG_ERROR([--enable-platform-gui requires the wallet]) + fi + PKG_CHECK_MODULES([PLATFORM_CXX], [dash_sdk_cxx], [], + [AC_MSG_ERROR([--enable-platform-gui requires dash-sdk-cxx (build depends with PLATFORM_GUI=1)])]) + TEMP_CPPFLAGS="$CPPFLAGS" + TEMP_LIBS="$LIBS" + CPPFLAGS="$CPPFLAGS $PLATFORM_CXX_CFLAGS" + LIBS="$PLATFORM_CXX_LIBS $LIBS" + AC_LANG_PUSH([C++]) + AC_MSG_CHECKING([whether a program using dash-sdk-cxx links]) + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ + #include + ]], [[ + rust::Box client{dash_sdk::new_platform_client(dash_sdk::Config{}, nullptr)}; + client->shutdown(); + ]])], + [AC_MSG_RESULT([yes])], + [AC_MSG_RESULT([no]) + AC_MSG_ERROR([a program using dash-sdk-cxx does not link; see config.log])]) + AC_LANG_POP([C++]) + CPPFLAGS="$TEMP_CPPFLAGS" + LIBS="$TEMP_LIBS" + AC_DEFINE([ENABLE_PLATFORM_GUI], [1], [Define this symbol to enable Dash Platform support in the GUI]) +fi +AM_CONDITIONAL([ENABLE_PLATFORM_GUI], [test "$enable_platform_gui" = "yes"]) + AM_CONDITIONAL([TARGET_DARWIN], [test "$TARGET_OS" = "darwin"]) AM_CONDITIONAL([BUILD_DARWIN], [test "$BUILD_OS" = "darwin"]) AM_CONDITIONAL([TARGET_LINUX], [test "$TARGET_OS" = "linux"]) @@ -2118,6 +2169,7 @@ echo " debug enabled = $enable_debug" echo " stacktraces = $enable_stacktraces" echo " crash hooks = $enable_crashhooks" echo " miner enabled = $enable_miner" +echo " platform gui = $enable_platform_gui" echo " werror = $enable_werror" echo echo " target os = $host_os" diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 9dc7d11ba75f..58a43732676f 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -487,6 +487,9 @@ endif if ENABLE_ZMQ bitcoin_qt_ldadd += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS) endif +if ENABLE_PLATFORM_GUI +bitcoin_qt_ldadd += $(PLATFORM_CXX_LIBS) +endif bitcoin_qt_ldadd += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBDASHBLS) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ $(BACKTRACE_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(SQLITE_LIBS) $(LIBSECP256K1) \ $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(GMP_LIBS) diff --git a/src/Makefile.qttest.include b/src/Makefile.qttest.include index 4690c07a5ea0..f7d1615836d6 100644 --- a/src/Makefile.qttest.include +++ b/src/Makefile.qttest.include @@ -87,6 +87,9 @@ endif if ENABLE_ZMQ qt_test_test_dash_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS) endif +if ENABLE_PLATFORM_GUI +qt_test_test_dash_qt_LDADD += $(PLATFORM_CXX_LIBS) +endif qt_test_test_dash_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBDASHBLS) $(LIBUNIVALUE) $(LIBLEVELDB) \ $(LIBMEMENV) $(BACKTRACE_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) \ $(QR_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(SQLITE_LIBS) $(LIBSECP256K1) \ diff --git a/src/Makefile.test.include b/src/Makefile.test.include index efc9a88fcfc3..ed165f6ef2e6 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -284,6 +284,9 @@ if ENABLE_WALLET test_test_dash_LDADD += $(LIBBITCOIN_WALLET) test_test_dash_CPPFLAGS += $(BDB_CPPFLAGS) endif +if ENABLE_PLATFORM_GUI +test_test_dash_LDADD += $(PLATFORM_CXX_LIBS) +endif test_test_dash_LDADD += $(LIBBITCOIN_NODE) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) \ $(LIBDASHBLS) $(LIBLEVELDB) $(LIBMEMENV) $(BACKTRACE_LIBS) $(LIBSECP256K1) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS) $(MINISKETCH_LIBS) test_test_dash_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) From bfe078a835a7b53b33dcd53e407a668f64541cb0 Mon Sep 17 00:00:00 2001 From: pasta Date: Thu, 24 Sep 2026 10:39:48 -0500 Subject: [PATCH 4/4] ci: build linux64 against depends with PLATFORM_GUI=1 A new linux64_platform_gui depends target builds depends with PLATFORM_GUI=1, and linux64 builds against it instead of the shared x86_64-pc-linux-gnu depends (as linux64_tsan builds against linux64_multiprocess's), so its dash-qt, test_dash and test_dash-qt are built with --enable-platform-gui (enabled through config.site) without adding a separate build and test job. linux64 is the only x86_64 job left with the wallet and the GUI and no sanitizers; linux64_asan and linux64_fuzz keep the plain depends. The new depends job is in the fast tier with the linux64 build it feeds. Its cache check runs on that x86_64 runner too. Pull request CI runs develop's workflows with the pull request's ci/ scripts, and a pull request based before this target existed has no matrix entry for it, so its HOST is guessed from the machine. Checked on the ARM runner other depends jobs use, that HOST would not match the build runner's, and the pull request would lose linux64 until rebased; on x86_64 it builds the plain depends, as before. contrib/devtools/check-no-rust.py then fails the linux64 build if dashd, dash-cli, dash-tx, dash-util, dash-wallet, bench_dash or the fuzz binary contain cxx bridge, Rust runtime or Rust standard library symbols, or no symbols at all: dash-sdk-cxx is for dash-qt, test_dash and test_dash-qt only. The source cache also gets the x86_64 Linux sources of the new depends job: the Rust toolchain, protoc, standard library and Platform archives. Its runner may be ARM, and the toolchain and protoc archives are chosen by the build machine, so download-one is given BUILD and HOST directly; download-linux would not pass BUILD to its sub-make. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/build.yml | 26 ++++++-- .github/workflows/cache-depends-sources.yml | 7 ++ ci/README.md | 2 +- ci/dash/build_src.sh | 4 ++ ci/dash/matrix.sh | 2 + ci/test/00_setup_env_native_platform_gui.sh | 12 ++++ .../00_setup_env_native_previous_releases.sh | 3 + contrib/devtools/README.md | 8 +++ contrib/devtools/check-no-rust.py | 64 +++++++++++++++++++ 9 files changed, 121 insertions(+), 7 deletions(-) create mode 100755 ci/test/00_setup_env_native_platform_gui.sh create mode 100755 contrib/devtools/check-no-rust.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e30687d774d5..2859ebeae497 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -232,7 +232,6 @@ jobs: uses: ./.github/workflows/build-depends.yml needs: [check-skip, container, cache-sources] if: | - vars.SKIP_LINUX64 == '' || vars.SKIP_LINUX64_ASAN == '' || vars.SKIP_LINUX64_FUZZ == '' with: @@ -271,6 +270,21 @@ jobs: runs-on-build: ${{ needs.check-skip.outputs['runner-build'] }} runs-on-check: ${{ needs.check-skip.outputs['runner-check-skip'] }} + depends-linux64_platform_gui: + name: x86_64-pc-linux-gnu_platform_gui + uses: ./.github/workflows/build-depends.yml + needs: [check-skip, container, cache-sources] + if: ${{ vars.SKIP_LINUX64 == '' }} + with: + build-target: linux64_platform_gui + container-path: ${{ needs.container.outputs.path }} + base-image-digest: ${{ needs.check-skip.outputs.base-image-digest }} + runs-on: ${{ needs.check-skip.outputs['runner-amd64'] }} + runs-on-build: ${{ needs.check-skip.outputs['runner-fast'] }} + # A pull request based before this target existed has no matrix entry + # for it, so its HOST is guessed from the machine: check on x86_64 too. + runs-on-check: ${{ needs.check-skip.outputs['runner-fast'] }} + depends-mac: name: x86_64-apple-darwin uses: ./.github/workflows/build-depends.yml @@ -332,15 +346,15 @@ jobs: src-linux64: name: linux64-build uses: ./.github/workflows/build-src.yml - needs: [check-skip, container, depends-linux64] + needs: [check-skip, container, depends-linux64_platform_gui] if: ${{ vars.SKIP_LINUX64 == '' }} with: build-target: linux64 container-path: ${{ needs.container.outputs.path }} - depends-key: ${{ needs.depends-linux64.outputs.key }} - depends-host: ${{ needs.depends-linux64.outputs.host }} - depends-dep-opts: ${{ needs.depends-linux64.outputs.dep-opts }} - depends-artifact: ${{ needs.depends-linux64.outputs.built-artifact }} + depends-key: ${{ needs.depends-linux64_platform_gui.outputs.key }} + depends-host: ${{ needs.depends-linux64_platform_gui.outputs.host }} + depends-dep-opts: ${{ needs.depends-linux64_platform_gui.outputs.dep-opts }} + depends-artifact: ${{ needs.depends-linux64_platform_gui.outputs.built-artifact }} runs-on: ${{ needs.check-skip.outputs['runner-fast'] }} secrets: *remote-ccache-auth diff --git a/.github/workflows/cache-depends-sources.yml b/.github/workflows/cache-depends-sources.yml index 18d8a80b9b36..281b1a40a78f 100644 --- a/.github/workflows/cache-depends-sources.yml +++ b/.github/workflows/cache-depends-sources.yml @@ -43,3 +43,10 @@ jobs: - name: Download sources if: steps.cache-check.outputs.cache-hit != 'true' run: make -C depends download + + # The linux64_platform_gui depends job runs on x86_64, but this runner + # may not: name the build machine, since the Rust toolchain and protoc + # archives are chosen by it. download-linux would not pass BUILD on. + - name: Download Platform GUI sources for x86_64 Linux + if: steps.cache-check.outputs.cache-hit != 'true' + run: make -C depends download-one PLATFORM_GUI=1 BUILD=x86_64-pc-linux-gnu HOST=x86_64-unknown-linux-gnu diff --git a/ci/README.md b/ci/README.md index d06a2b8f98fa..bd39f44827f8 100644 --- a/ci/README.md +++ b/ci/README.md @@ -33,7 +33,7 @@ and steps, so required checks are unchanged. | Tier | Jobs | Label variable | | --- | --- | --- | -| fast | lint, cppcheck, cache-sources, the amd64 pull request container builds and manifests, and the `linux64` depends, build and test | `RUNNER_SELFHOSTED_FAST` | +| fast | lint, cppcheck, cache-sources, the amd64 pull request container builds and manifests, the `linux64` and `linux64_platform_gui` depends, and the `linux64` build and test | `RUNNER_SELFHOSTED_FAST` | | build | every other amd64 depends, build and test job (`aarch64-linux`, `linux64_asan`, `linux64_fuzz`, `linux64_nowallet`, `mac`, `win64`) | `RUNNER_SELFHOSTED_BUILD` | Each tier picks the first of these that applies: diff --git a/ci/dash/build_src.sh b/ci/dash/build_src.sh index 2184966c28eb..6934b71399e8 100755 --- a/ci/dash/build_src.sh +++ b/ci/dash/build_src.sh @@ -54,6 +54,10 @@ if [ "${RUN_STDLIB_PATH_CHECK}" = "true" ]; then make -C src --jobs=1 check-stdlib-paths fi +if [ "${RUN_CHECK_NO_RUST}" = "true" ]; then + "${BASE_ROOT_DIR}/contrib/devtools/check-no-rust.py" src/dashd src/dash-cli src/dash-tx src/dash-util src/dash-wallet src/bench/bench_dash src/test/fuzz/fuzz +fi + if [ -n "$USE_VALGRIND" ]; then echo "valgrind in USE!" "${BASE_ROOT_DIR}/ci/test/wrap-valgrind.sh" diff --git a/ci/dash/matrix.sh b/ci/dash/matrix.sh index 04c39965191f..b689f73756be 100755 --- a/ci/dash/matrix.sh +++ b/ci/dash/matrix.sh @@ -30,6 +30,8 @@ elif [ "$BUILD_TARGET" = "linux64_multiprocess" ]; then source ./ci/test/00_setup_env_native_multiprocess.sh elif [ "$BUILD_TARGET" = "linux64_nowallet" ]; then source ./ci/test/00_setup_env_native_nowallet_libbitcoinkernel.sh +elif [ "$BUILD_TARGET" = "linux64_platform_gui" ]; then + source ./ci/test/00_setup_env_native_platform_gui.sh elif [ "$BUILD_TARGET" = "linux64_tsan" ]; then source ./ci/test/00_setup_env_native_tsan.sh elif [ "$BUILD_TARGET" = "linux64_valgrind" ]; then diff --git a/ci/test/00_setup_env_native_platform_gui.sh b/ci/test/00_setup_env_native_platform_gui.sh new file mode 100755 index 000000000000..950e935c8b1a --- /dev/null +++ b/ci/test/00_setup_env_native_platform_gui.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2026 The Dash Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +export LC_ALL=C.UTF-8 + +# Depends with dash-sdk-cxx (PLATFORM_GUI=1); linux64 builds against it. +export CONTAINER_NAME=ci_native_platform_gui +export HOST=x86_64-pc-linux-gnu +export DEP_OPTS="PLATFORM_GUI=1" diff --git a/ci/test/00_setup_env_native_previous_releases.sh b/ci/test/00_setup_env_native_previous_releases.sh index 6038c5fdf943..f0fa020ebbbf 100755 --- a/ci/test/00_setup_env_native_previous_releases.sh +++ b/ci/test/00_setup_env_native_previous_releases.sh @@ -9,6 +9,8 @@ export LC_ALL=C.UTF-8 export CONTAINER_NAME=ci_native_previous_releases export HOST=x86_64-pc-linux-gnu export PACKAGES="python3-zmq" +# CI builds linux64 against the linux64_platform_gui depends: set its depends +# options in 00_setup_env_native_platform_gui.sh, not here. export DEP_OPTS="" export TEST_RUNNER_EXTRA="--previous-releases --coverage --extended --exclude feature_pruning,feature_dbcrash" # Run extended tests so that coverage does not fail, but exclude the very slow dbcrash export RUN_UNIT_TESTS_SEQUENTIAL="true" @@ -17,3 +19,4 @@ export GOAL="install" export DOWNLOAD_PREVIOUS_RELEASES="true" export BITCOIN_CONFIG="--enable-zmq --with-libs=no --enable-reduce-exports CPPFLAGS='-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE -DDEBUG_LOCKORDER -DDEBUG_LOCKCONTENTION' LDFLAGS=-static-libstdc++ CC=gcc-14 CXX=g++-14" export RUN_STDLIB_PATH_CHECK=true +export RUN_CHECK_NO_RUST="true" diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md index bc9fc492d819..ea370f3caace 100644 --- a/contrib/devtools/README.md +++ b/contrib/devtools/README.md @@ -229,3 +229,11 @@ bundle hash on any machine. The Platform tarball and the bundle are then uploaded to the depends sources mirror. contrib/devtools/platform-bundle.sh + +check-no-rust.py +================ + +Fails if any of the given executables contain Rust code. Run by the +`linux64` CI job, which builds against depends with `PLATFORM_GUI=1`, on +`dashd`, the command-line tools, `bench_dash` and the fuzz binary, which must +never link `dash-sdk-cxx`. diff --git a/contrib/devtools/check-no-rust.py b/contrib/devtools/check-no-rust.py new file mode 100755 index 000000000000..f68b40761018 --- /dev/null +++ b/contrib/devtools/check-no-rust.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +# Copyright (c) 2026 The Dash Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. +''' +Check that executables do not link Rust code. + +dash-sdk-cxx, the Dash Platform SDK binding (--enable-platform-gui), is for +dash-qt, test_dash and test_dash-qt only; dashd, the command-line tools, +bench_dash and the fuzz binary must not contain any of it. +A binary fails if its symbol table has cxx bridge, Rust runtime or Rust +standard library symbols, or has no symbols at all (a stripped binary cannot +be checked). + +Example usage: + + contrib/devtools/check-no-rust.py src/dashd src/dash-cli src/dash-tx src/dash-util src/dash-wallet src/bench/bench_dash src/test/fuzz/fuzz +''' +import re +import subprocess +import sys + +from utils import determine_wellknown_cmd + +# cxx bridge symbols carry "cxxbridge1$". Rust code is either legacy-mangled +# under a crate namespace (rust, std, core, alloc) or v0-mangled ("_R" +# followed by a path tag and a crate root "Cs_"), which C and +# C++ symbols never match. The allocator shim, the panic handler and the +# unwinding personality are plain C names every Rust program links. +RUST_SYMBOL = re.compile( + r'cxxbridge1\$' + r'|_ZN(4rust|3std|4core|5alloc)[0-9]' + r'|\b_?_R[A-Za-z0-9_]*?Cs[A-Za-z0-9]*_[0-9]' + r'|\b_?(__rust_alloc|rust_begin_unwind|rust_eh_personality)' +) + + +def rust_symbols(nm, path): + result = subprocess.run(nm + [path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=False) + if result.returncode != 0: + sys.exit(f'{path}: {result.stderr.strip()}') + lines = result.stdout.splitlines() + if not lines: + sys.exit(f'{path}: no symbols, so it cannot be checked (stripped?)') + return [line for line in lines if RUST_SYMBOL.search(line)] + + +def main(): + if len(sys.argv) < 2: + sys.exit(__doc__) + nm = determine_wellknown_cmd('NM', 'nm') + failed = False + for path in sys.argv[1:]: + found = rust_symbols(nm, path) + if found: + failed = True + print(f'{path}: links Rust code, for example:') + for line in found[:5]: + print(f' {line}') + sys.exit(1 if failed else 0) + + +if __name__ == '__main__': + main()