mirror of
https://github.com/logos-messaging/logos-chat.git
synced 2026-05-21 20:09:30 +00:00
wip
This commit is contained in:
parent
85c1027645
commit
92dd2c8093
70
Makefile
70
Makefile
@ -28,22 +28,6 @@ ifneq (,$(findstring MINGW,$(detected_OS)))
|
|||||||
detected_OS := Windows
|
detected_OS := Windows
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# liblibchat and librln are both Rust staticlibs that embed Rust std,
|
|
||||||
# resulting in duplicate symbol errors at link time.
|
|
||||||
# On Linux, --allow-multiple-definition suppresses the error.
|
|
||||||
# On Darwin, Apple ld does not support that flag; instead we partial-link
|
|
||||||
# liblibchat.a with ld -r, keeping only its public API symbols exported so
|
|
||||||
# that all Rust std internals (including _rust_eh_personality) are hidden
|
|
||||||
# and cannot conflict with the copy embedded in librln.a.
|
|
||||||
ifeq ($(detected_OS),Linux)
|
|
||||||
LDFLAGS := --passL:-Wl,--allow-multiple-definition
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(detected_OS),Darwin)
|
|
||||||
LIBCHAT_A := build/liblibchat_clean.a
|
|
||||||
else
|
|
||||||
LIBCHAT_A := vendor/libchat/target/release/liblibchat.a
|
|
||||||
endif
|
|
||||||
|
|
||||||
##########
|
##########
|
||||||
## Main ##
|
## Main ##
|
||||||
@ -90,50 +74,30 @@ NIM_PARAMS := $(NIM_PARAMS) -d:git_version=\"$(GIT_VERSION)\"
|
|||||||
##################
|
##################
|
||||||
## Dependencies ##
|
## Dependencies ##
|
||||||
##################
|
##################
|
||||||
.PHONY: build-waku-librln
|
|
||||||
|
|
||||||
LIBRLN_VERSION := v0.7.0
|
RUST_BUNDLE_LIB := rust-bundle/target/release/lib_rust_bundle.a
|
||||||
|
|
||||||
ifeq ($(detected_OS),Windows)
|
# libchat and rln each embed Rust std when built as staticlibs; linking both
|
||||||
LIBRLN_FILE := rln.lib
|
# causes duplicate-symbol errors. rust-bundle/ links them as rlibs so std
|
||||||
else
|
# is emitted once. [1]
|
||||||
LIBRLN_FILE := librln_$(LIBRLN_VERSION).a
|
# [1] https://doc.rust-lang.org/reference/linkage.html
|
||||||
endif
|
.PHONY: build-rust-bundle
|
||||||
|
build-rust-bundle:
|
||||||
|
@echo "Building Rust bundle (libchat + rln)"
|
||||||
build-waku-librln:
|
|
||||||
@echo "Start building waku librln"
|
|
||||||
$(MAKE) -C vendor/nwaku librln
|
$(MAKE) -C vendor/nwaku librln
|
||||||
$(eval NIM_PARAMS += --passL:./vendor/nwaku/${LIBRLN_FILE} --passL:-lm)
|
cargo build --release --manifest-path rust-bundle/Cargo.toml
|
||||||
@echo "Completed building librln"
|
@echo "Bundle library: $(RUST_BUNDLE_LIB)"
|
||||||
|
|
||||||
build-waku-nat:
|
build-waku-nat:
|
||||||
@echo "Start building waku nat-libs"
|
@echo "Start building waku nat-libs"
|
||||||
$(MAKE) -C vendor/nwaku nat-libs
|
$(MAKE) -C vendor/nwaku nat-libs
|
||||||
@echo "Completed building nat-libs"
|
@echo "Completed building nat-libs"
|
||||||
|
|
||||||
.PHONY: build-libchat
|
|
||||||
build-libchat:
|
|
||||||
@echo "Start building libchat"
|
|
||||||
cd vendor/libchat && cargo build --release
|
|
||||||
ifeq ($(detected_OS),Darwin)
|
|
||||||
@mkdir -p build
|
|
||||||
@nm --no-llvm-bc -gjU vendor/libchat/target/release/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)' \
|
|
||||||
> build/libchat_exports.txt
|
|
||||||
@ld -r -exported_symbols_list build/libchat_exports.txt \
|
|
||||||
vendor/libchat/target/release/liblibchat.a \
|
|
||||||
-o build/liblibchat_clean.o
|
|
||||||
@libtool -static -o $(LIBCHAT_A) build/liblibchat_clean.o
|
|
||||||
endif
|
|
||||||
@echo "Completed building libchat"
|
|
||||||
|
|
||||||
.PHONY: tests
|
.PHONY: tests
|
||||||
tests: | build-waku-librln build-waku-nat build-libchat logos_chat.nims
|
tests: | build-rust-bundle build-waku-nat logos_chat.nims
|
||||||
echo -e $(BUILD_MSG) "build/$@" && \
|
echo -e $(BUILD_MSG) "build/$@" && \
|
||||||
$(ENV_SCRIPT) nim tests $(NIM_PARAMS) \
|
$(ENV_SCRIPT) nim tests $(NIM_PARAMS) \
|
||||||
--passL:$(LIBCHAT_A) \
|
--passL:$(RUST_BUNDLE_LIB) --passL:-lm \
|
||||||
$(LDFLAGS) \
|
|
||||||
logos_chat.nims
|
logos_chat.nims
|
||||||
|
|
||||||
|
|
||||||
@ -142,11 +106,10 @@ tests: | build-waku-librln build-waku-nat build-libchat logos_chat.nims
|
|||||||
##########
|
##########
|
||||||
|
|
||||||
# Ensure there is a nimble task with a name that matches the target
|
# Ensure there is a nimble task with a name that matches the target
|
||||||
tui bot_echo pingpong: | build-waku-librln build-waku-nat build-libchat logos_chat.nims
|
tui bot_echo pingpong: | build-rust-bundle build-waku-nat logos_chat.nims
|
||||||
echo -e $(BUILD_MSG) "build/$@" && \
|
echo -e $(BUILD_MSG) "build/$@" && \
|
||||||
$(ENV_SCRIPT) nim $@ $(NIM_PARAMS) \
|
$(ENV_SCRIPT) nim $@ $(NIM_PARAMS) \
|
||||||
--passL:$(LIBCHAT_A) \
|
--passL:$(RUST_BUNDLE_LIB) --passL:-lm \
|
||||||
$(LDFLAGS) \
|
|
||||||
--path:src logos_chat.nims
|
--path:src logos_chat.nims
|
||||||
|
|
||||||
###########
|
###########
|
||||||
@ -165,11 +128,10 @@ endif
|
|||||||
LIBLOGOSCHAT := build/liblogoschat.$(LIBLOGOSCHAT_EXT)
|
LIBLOGOSCHAT := build/liblogoschat.$(LIBLOGOSCHAT_EXT)
|
||||||
|
|
||||||
.PHONY: liblogoschat
|
.PHONY: liblogoschat
|
||||||
liblogoschat: | build-waku-librln build-waku-nat build-libchat logos_chat.nims
|
liblogoschat: | build-rust-bundle build-waku-nat logos_chat.nims
|
||||||
echo -e $(BUILD_MSG) "$(LIBLOGOSCHAT)" && \
|
echo -e $(BUILD_MSG) "$(LIBLOGOSCHAT)" && \
|
||||||
$(ENV_SCRIPT) nim liblogoschat $(NIM_PARAMS) \
|
$(ENV_SCRIPT) nim liblogoschat $(NIM_PARAMS) \
|
||||||
--passL:$(LIBCHAT_A) \
|
--passL:$(RUST_BUNDLE_LIB) --passL:-lm \
|
||||||
$(LDFLAGS) \
|
|
||||||
--path:src logos_chat.nims && \
|
--path:src logos_chat.nims && \
|
||||||
echo -e "\n\x1B[92mLibrary built successfully:\x1B[39m" && \
|
echo -e "\n\x1B[92mLibrary built successfully:\x1B[39m" && \
|
||||||
echo " $(shell pwd)/$(LIBLOGOSCHAT)"
|
echo " $(shell pwd)/$(LIBLOGOSCHAT)"
|
||||||
|
|||||||
@ -25,11 +25,11 @@
|
|||||||
overlays = [ rust-overlay.overlays.default ];
|
overlays = [ rust-overlay.overlays.default ];
|
||||||
};
|
};
|
||||||
libchatDrv = pkgs.callPackage ./nix/libchat.nix {};
|
libchatDrv = pkgs.callPackage ./nix/libchat.nix {};
|
||||||
librlnDrv = pkgs.callPackage ./nix/librln.nix {};
|
rustBundleDrv = pkgs.callPackage ./nix/bundle.nix { src = self; };
|
||||||
in {
|
in {
|
||||||
packages.default = pkgs.callPackage ./nix/default.nix {
|
packages.default = pkgs.callPackage ./nix/default.nix {
|
||||||
src = self;
|
src = self;
|
||||||
inherit libchatDrv librlnDrv;
|
inherit rustBundleDrv;
|
||||||
};
|
};
|
||||||
devShells.default = pkgs.callPackage ./nix/shell.nix {
|
devShells.default = pkgs.callPackage ./nix/shell.nix {
|
||||||
inherit libchatDrv;
|
inherit libchatDrv;
|
||||||
|
|||||||
34
nix/bundle.nix
Normal file
34
nix/bundle.nix
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
{ 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 = "rust-bundle";
|
||||||
|
version = "0.1.0";
|
||||||
|
inherit src;
|
||||||
|
cargoRoot = "rust-bundle";
|
||||||
|
|
||||||
|
cargoLock = {
|
||||||
|
lockFile = src + "/rust-bundle/Cargo.lock";
|
||||||
|
# Add outputHashes here for any git/non-registry deps that appear in
|
||||||
|
# rust-bundle/Cargo.lock (run `nix build` once; it will report missing hashes).
|
||||||
|
outputHashes = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
nativeBuildInputs = [ perl pkg-config cmake ];
|
||||||
|
doCheck = false;
|
||||||
|
|
||||||
|
buildAndTestSubdir = "rust-bundle";
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
runHook preInstall
|
||||||
|
mkdir -p $out/lib
|
||||||
|
cp rust-bundle/target/*/release/lib_rust_bundle.a $out/lib/ 2>/dev/null || true
|
||||||
|
cp rust-bundle/target/release/lib_rust_bundle.a $out/lib/ 2>/dev/null || true
|
||||||
|
runHook postInstall
|
||||||
|
'';
|
||||||
|
}
|
||||||
@ -1,8 +1,7 @@
|
|||||||
{ lib, stdenv, nim, which, pkg-config, writeScriptBin,
|
{ lib, stdenv, nim, which, pkg-config, writeScriptBin,
|
||||||
openssl, miniupnpc, libnatpmp,
|
openssl, miniupnpc, libnatpmp,
|
||||||
src, # logos-chat source (self from flake, with submodules=1)
|
src, # logos-chat source (self from flake, with submodules=1)
|
||||||
libchatDrv, # result of libchat.nix
|
rustBundleDrv }: # result of bundle.nix
|
||||||
librlnDrv }: # result of librln.nix
|
|
||||||
|
|
||||||
# NOTE: this build requires git submodules to be present in src.
|
# NOTE: this build requires git submodules to be present in src.
|
||||||
# When fetching from GitHub use '?submodules=1#', e.g.:
|
# When fetching from GitHub use '?submodules=1#', e.g.:
|
||||||
@ -20,14 +19,12 @@ in stdenv.mkDerivation {
|
|||||||
inherit src;
|
inherit src;
|
||||||
|
|
||||||
NIMFLAGS = lib.concatStringsSep " " [
|
NIMFLAGS = lib.concatStringsSep " " [
|
||||||
"--passL:${libchatDrv}/lib/liblibchat.a"
|
"--passL:${rustBundleDrv}/lib/lib_rust_bundle.a"
|
||||||
"--passL:${librlnDrv}/lib/librln_v0.7.0.a"
|
|
||||||
"--passL:-lm"
|
"--passL:-lm"
|
||||||
"-d:miniupnpcUseSystemLibs"
|
"-d:miniupnpcUseSystemLibs"
|
||||||
"-d:libnatpmpUseSystemLibs"
|
"-d:libnatpmpUseSystemLibs"
|
||||||
"--passL:-lminiupnpc"
|
"--passL:-lminiupnpc"
|
||||||
"--passL:-lnatpmp"
|
"--passL:-lnatpmp"
|
||||||
(lib.optionalString (!stdenv.isDarwin) "--passL:-Wl,--allow-multiple-definition")
|
|
||||||
"-d:git_version=${revision}"
|
"-d:git_version=${revision}"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
{ lib, stdenv, rust-bin, makeRustPlatform, perl, pkg-config, cmake }:
|
{ rust-bin, makeRustPlatform, perl, pkg-config, cmake }:
|
||||||
|
|
||||||
let
|
let
|
||||||
rustToolchain = rust-bin.fromRustupToolchainFile ../vendor/libchat/rust_toolchain.toml;
|
rustToolchain = rust-bin.fromRustupToolchainFile ../vendor/libchat/rust_toolchain.toml;
|
||||||
@ -31,20 +31,6 @@ in rPlatform.buildRustPackage {
|
|||||||
cp target/release/liblibchat.so $out/lib/ 2>/dev/null || true
|
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.dylib $out/lib/ 2>/dev/null || true
|
||||||
cp target/release/liblibchat.a $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
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|||||||
15
rust-bundle/Cargo.toml
Normal file
15
rust-bundle/Cargo.toml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[package]
|
||||||
|
name = "rust-bundle"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "rust_bundle"
|
||||||
|
crate-type = ["staticlib"]
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
panic = "abort"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
libchat = { path = "../vendor/libchat/conversations" }
|
||||||
|
rln = { path = "../vendor/nwaku/vendor/zerokit/rln", features = ["arkzkey"] }
|
||||||
4
rust-bundle/src/lib.rs
Normal file
4
rust-bundle/src/lib.rs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// Force both rlibs into this staticlib.
|
||||||
|
// Their #[no_mangle] pub extern "C" symbols are exported from lib_rust_bundle.a.
|
||||||
|
extern crate libchat;
|
||||||
|
extern crate rln;
|
||||||
Loading…
x
Reference in New Issue
Block a user