diff --git a/Makefile b/Makefile index 55ed376..6d4a096 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,13 @@ ifneq (,$(findstring MINGW,$(detected_OS))) detected_OS := Windows endif +# liblibchat and librln are both Rust staticlibs that embed Rust std, +# resulting in duplicate symbol errors at link time. To mitigate that, +# --allow-multiple-definition is added. +ifeq ($(detected_OS),Linux) + LDFLAGS := --passL:-Wl,--allow-multiple-definition +endif + ########## ## Main ## ########## @@ -104,7 +111,10 @@ build-libchat: .PHONY: tests tests: | build-waku-librln build-waku-nat build-libchat logos_chat.nims echo -e $(BUILD_MSG) "build/$@" && \ - $(ENV_SCRIPT) nim tests $(NIM_PARAMS) logos_chat.nims + $(ENV_SCRIPT) nim tests $(NIM_PARAMS) \ + --passL:vendor/libchat/target/release/liblibchat.a \ + $(LDFLAGS) \ + logos_chat.nims ########## @@ -114,7 +124,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 tui bot_echo pingpong: | build-waku-librln build-waku-nat build-libchat logos_chat.nims echo -e $(BUILD_MSG) "build/$@" && \ - $(ENV_SCRIPT) nim $@ $(NIM_PARAMS) --path:src logos_chat.nims + $(ENV_SCRIPT) nim $@ $(NIM_PARAMS) \ + --passL:vendor/libchat/target/release/liblibchat.a \ + $(LDFLAGS) \ + --path:src logos_chat.nims ########### ## Library ## @@ -134,7 +147,10 @@ LIBLOGOSCHAT := build/liblogoschat.$(LIBLOGOSCHAT_EXT) .PHONY: liblogoschat liblogoschat: | build-waku-librln build-waku-nat build-libchat logos_chat.nims echo -e $(BUILD_MSG) "$(LIBLOGOSCHAT)" && \ - $(ENV_SCRIPT) nim liblogoschat $(NIM_PARAMS) --path:src logos_chat.nims && \ + $(ENV_SCRIPT) nim liblogoschat $(NIM_PARAMS) \ + --passL:vendor/libchat/target/release/liblibchat.a \ + $(LDFLAGS) \ + --path:src logos_chat.nims && \ echo -e "\n\x1B[92mLibrary built successfully:\x1B[39m" && \ echo " $(shell pwd)/$(LIBLOGOSCHAT)" diff --git a/flake.nix b/flake.nix index 160f089..9858867 100644 --- a/flake.nix +++ b/flake.nix @@ -25,11 +25,11 @@ overlays = [ rust-overlay.overlays.default ]; }; libchatDrv = pkgs.callPackage ./nix/libchat.nix {}; - librln = pkgs.callPackage ./nix/librln.nix {}; + librlnDrv = pkgs.callPackage ./nix/librln.nix {}; in { packages.default = pkgs.callPackage ./nix/default.nix { src = self; - inherit libchatDrv librln; + inherit libchatDrv librlnDrv; }; devShells.default = pkgs.callPackage ./nix/shell.nix { inherit libchatDrv; diff --git a/nix/default.nix b/nix/default.nix index 4ebf73b..e0de975 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -2,7 +2,7 @@ openssl, miniupnpc, libnatpmp, src, # logos-chat source (self from flake, with submodules=1) libchatDrv, # result of libchat.nix - librln }: # result of librln.nix + librlnDrv }: # result of librln.nix # NOTE: this build requires git submodules to be present in src. # When fetching from GitHub use '?submodules=1#', e.g.: @@ -14,21 +14,20 @@ assert lib.assertMsg ((src.submodules or false) == true) let revision = lib.substring 0 8 (src.rev or "dirty"); - libExt = if stdenv.isDarwin then "dylib" else "so"; - libchatPath = "${libchatDrv}/lib/liblibchat.${libExt}"; in stdenv.mkDerivation { pname = "liblogoschat"; version = "0.1.0"; inherit src; NIMFLAGS = lib.concatStringsSep " " [ - "--passL:vendor/nwaku/librln_v0.7.0.a" + "--passL:${libchatDrv}/lib/liblibchat.a" + "--passL:${librlnDrv}/lib/librln_v0.7.0.a" "--passL:-lm" "-d:miniupnpcUseSystemLibs" "-d:libnatpmpUseSystemLibs" "--passL:-lminiupnpc" "--passL:-lnatpmp" - "-d:CONVERSATIONS_LIB:${libchatPath}" + (lib.optionalString (!stdenv.isDarwin) "--passL:-Wl,--allow-multiple-definition") "-d:git_version=${revision}" ]; @@ -62,8 +61,6 @@ in stdenv.mkDerivation { ''; preBuild = '' - # Place pre-built librln where the Nim linker expects it - cp ${librln}/lib/librln_v0.7.0.a vendor/nwaku/librln_v0.7.0.a mkdir -p build ''; diff --git a/nix/shell.nix b/nix/shell.nix index ea5a5e8..036ee35 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -10,8 +10,7 @@ in pkgs.mkShell { ]; shellHook = '' - export CONVERSATIONS_LIB="${libchatDrv}/lib/liblibchat.${libExt}" - echo "logos-chat dev shell. CONVERSATIONS_LIB=$CONVERSATIONS_LIB" + echo "logos-chat dev shell." echo "Build: make liblogoschat" echo "Nix build: nix build '.?submodules=1#'" ''; diff --git a/vendor/libchat b/vendor/libchat index 960bb19..681c17c 160000 --- a/vendor/libchat +++ b/vendor/libchat @@ -1 +1 @@ -Subproject commit 960bb195a13657a09fa2df66262b3b2ced738f30 +Subproject commit 681c17ccaecd7a171c46cc96ff61d1d3db7fd7a9