From 54e77b6f9bf76b508c001df89502e17d111d9700 Mon Sep 17 00:00:00 2001 From: Michael Schmid Date: Sun, 3 May 2026 22:47:50 -0400 Subject: [PATCH] Make non-glibc Linux cross-compilation work Three small changes that let mujina-miner cross-compile for aarch64-unknown-linux-musl (and other non-glibc Linux targets) so it can be deployed to mining hardware that ships with musl userspace -- e.g. the Amlogic A113D control board on Antminer S19 series. - Switch reqwest to rustls-tls. Default features pull in native-tls, which transitively requires openssl-sys; cross-building openssl-sys to musl is painful and unnecessary when reqwest can use rustls. - Gate udev and tracing-journald to target_env = "gnu". Both link against glibc-only system libraries (libudev, libsystemd) that have no good musl story. The existing fallback module in src/transport/usb.rs already covers the no-udev case as a stub, so musl Linux falls into the same "USB hashboard discovery unsupported" path as Windows etc. -- fine for the CPU backend and any non-USB board. - Same gate change in src/tracing.rs: the journald init path requires tracing-journald, so it has to follow the same cfg. Tested by cross-compiling mujina-minerd from macOS to aarch64-unknown-linux-musl and running on an Antminer S19j Pro control board (kernel aarch64, userspace armhf, musl static binary runs fine via the 64-bit kernel) with MUJINA_USB_DISABLE=1 and the CPU backend. Build prereqs on macOS: rustup target add aarch64-unknown-linux-musl brew install messense/macos-cross-toolchains/aarch64-unknown-linux-musl Then: CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-unknown-linux-musl-gcc \ CC_aarch64_unknown_linux_musl=aarch64-unknown-linux-musl-gcc \ cargo build --release --target aarch64-unknown-linux-musl --bin mujina-minerd --- Cargo.toml | 2 +- mujina-miner/Cargo.toml | 2 +- mujina-miner/src/tracing.rs | 4 ++-- mujina-miner/src/transport/usb.rs | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7276abb1..ceee26a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ nix = { version = "0.29", features = ["fs", "ioctl", "term"] } num-traits = "0.2" parking_lot = "0.12" regex = "1.10" -reqwest = { version = "0.12", features = ["json"] } +reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls", "charset", "http2"] } rustix = { version = "0.38", features = ["fs", "termios"] } slotmap = "1.0" udev = "0.9" diff --git a/mujina-miner/Cargo.toml b/mujina-miner/Cargo.toml index 1cb651a9..ebd43c65 100644 --- a/mujina-miner/Cargo.toml +++ b/mujina-miner/Cargo.toml @@ -49,7 +49,7 @@ ruint = "1.17.0" core-foundation = { workspace = true } io-kit-sys = { workspace = true } -[target.'cfg(target_os = "linux")'.dependencies] +[target.'cfg(all(target_os = "linux", target_env = "gnu"))'.dependencies] tracing-journald = { workspace = true } udev = { workspace = true } diff --git a/mujina-miner/src/tracing.rs b/mujina-miner/src/tracing.rs index 42333f0e..271beaac 100644 --- a/mujina-miner/src/tracing.rs +++ b/mujina-miner/src/tracing.rs @@ -53,7 +53,7 @@ fn build_env_filter() -> EnvFilter { filter_str.parse().unwrap() } -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", target_env = "gnu"))] mod journald { use std::env; use std::io; @@ -127,7 +127,7 @@ mod journald { } } -#[cfg(not(target_os = "linux"))] +#[cfg(not(all(target_os = "linux", target_env = "gnu")))] mod journald { pub fn try_init() -> bool { false diff --git a/mujina-miner/src/transport/usb.rs b/mujina-miner/src/transport/usb.rs index 6b4cf076..d7e7cf9f 100644 --- a/mujina-miner/src/transport/usb.rs +++ b/mujina-miner/src/transport/usb.rs @@ -25,9 +25,9 @@ use super::TransportEvent as OuterTransportEvent; // Platform-specific serial port discovery, aliased to a common name // so call sites are platform-independent. -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", target_env = "gnu"))] mod linux; -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", target_env = "gnu"))] use linux as platform; #[cfg(target_os = "macos")] @@ -39,7 +39,7 @@ use macos as platform; // miner still compiles (e.g., for CPU mining). If this is ever // called, something has gone wrong because a board matched a USB // device on a platform where we can't find its serial ports. -#[cfg(not(any(target_os = "linux", target_os = "macos")))] +#[cfg(not(any(all(target_os = "linux", target_env = "gnu"), target_os = "macos")))] mod platform { use anyhow::{Result, bail}; use nusb::DeviceInfo;