logos-chat/nix/rust_bundle.nix
osmaczko 274e5c060f
feat: statically link libchat and rln via rust-bundle
Add rust-bundle, a single staticlib crate that depends on both libchat
and rln as rlibs. This ensures rustc links Rust std exactly once,
eliminating duplicate symbol errors on all platforms. Nim targets link
against liblogos_chat_bundle.a; Nix uses a bundleDrv instead of
separate libchat and rln derivations.

Reference: https://doc.rust-lang.org/reference/linkage.html#mixed-rust-and-foreign-codebases
2026-03-01 17:07:04 +01:00

35 lines
946 B
Nix

{ lib, stdenv, rust-bin, makeRustPlatform, perl, pkg-config, cmake, src }:
let
rustToolchain = rust-bin.fromRustupToolchainFile (src + "/vendor/libchat/rust_toolchain.toml");
rPlatform = makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
};
in rPlatform.buildRustPackage {
pname = "logoschat_rust_bundle";
version = "0.1.0";
inherit src;
cargoRoot = "rust-bundle";
cargoLock = {
lockFile = src + "/rust-bundle/Cargo.lock";
outputHashes = {
"chat-proto-0.1.0" = "sha256-aCl80VOIkd/GK3gnmRuFoSAvPBfeE/FKCaNlLt5AbUU=";
};
};
nativeBuildInputs = [ perl pkg-config cmake ];
doCheck = false;
buildAndTestSubdir = "rust-bundle";
installPhase = ''
runHook preInstall
mkdir -p $out/lib
find "$CARGO_TARGET_DIR" -name "liblogoschat_rust_bundle.a" -path "*/release/*" -exec cp {} $out/lib/ \;
test -f $out/lib/liblogoschat_rust_bundle.a
runHook postInstall
'';
}