logos-chat/nix/libchat.nix
osmaczko 85c1027645
wip
2026-02-26 18:40:48 +01:00

51 lines
2.1 KiB
Nix

{ lib, stdenv, rust-bin, makeRustPlatform, perl, pkg-config, cmake }:
let
rustToolchain = rust-bin.fromRustupToolchainFile ../vendor/libchat/rust_toolchain.toml;
rPlatform = makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
};
in rPlatform.buildRustPackage {
pname = "libchat";
version = "0.1.0";
src = ../vendor/libchat;
cargoLock = {
lockFile = ../vendor/libchat/Cargo.lock;
outputHashes = {
"chat-proto-0.1.0" = "sha256-aCl80VOIkd/GK3gnmRuFoSAvPBfeE/FKCaNlLt5AbUU=";
};
};
nativeBuildInputs = [ perl pkg-config cmake ];
doCheck = false;
installPhase = ''
runHook preInstall
mkdir -p $out/lib
cp target/*/release/liblibchat.so $out/lib/ 2>/dev/null || true
cp target/*/release/liblibchat.dylib $out/lib/ 2>/dev/null || true
cp target/*/release/liblibchat.a $out/lib/ 2>/dev/null || true
# fallback: non-cross build path
cp target/release/liblibchat.so $out/lib/ 2>/dev/null || true
cp target/release/liblibchat.dylib $out/lib/ 2>/dev/null || true
cp target/release/liblibchat.a $out/lib/ 2>/dev/null || true
${lib.optionalString stdenv.isDarwin ''
# Partial-link liblibchat.a, keeping only its public API symbols exported.
# This hides all Rust std symbols (including _rust_eh_personality) so they
# do not conflict with the copy embedded in librln.a at final link time.
if [ -f "$out/lib/liblibchat.a" ]; then
nm --no-llvm-bc -gjU $out/lib/liblibchat.a 2>/dev/null | \
grep -E '^_(chat_|double_ratchet_|encrypt_result_|ffi_c_string_|installation_key_pair_|ratchet_state_|create_context|installation_name|destroy_context|destroy_string|create_intro_bundle|create_new_private_convo|send_content|handle_payload|destroy_intro_result|destroy_send_content_result|destroy_handle_payload_result|destroy_convo_result)' \
> $TMPDIR/libchat_exports.txt
ld -r -exported_symbols_list $TMPDIR/libchat_exports.txt \
$out/lib/liblibchat.a \
-o $TMPDIR/liblibchat_clean.o
libtool -static -o $out/lib/liblibchat.a $TMPDIR/liblibchat_clean.o
fi
''}
runHook postInstall
'';
}