From cccc8ab6fda0e54752936db0d5c80b02a2c34a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Fri, 23 Jan 2026 14:06:30 +0100 Subject: [PATCH] nix: drop unnecessay asert for Android SDK on macOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Newer nixpkgs should have Android SDK for aarch64. Signed-off-by: Jakub SokoĊ‚owski --- Makefile | 13 +++++-- flake.lock | 28 +++++++------- flake.nix | 13 +++---- nix/default.nix | 66 ++++++++++++-------------------- nix/pkgs/android-sdk/compose.nix | 7 +--- nix/shell.nix | 19 ++++----- scripts/build_rln_android.sh | 1 - vendor/zerokit | 2 +- 8 files changed, 63 insertions(+), 86 deletions(-) diff --git a/Makefile b/Makefile index 87bd7bc74..78f4ace7e 100644 --- a/Makefile +++ b/Makefile @@ -151,7 +151,7 @@ NIM_PARAMS := $(NIM_PARAMS) -d:disable_libbacktrace endif # enable experimental exit is dest feature in libp2p mix -NIM_PARAMS := $(NIM_PARAMS) -d:libp2p_mix_experimental_exit_is_dest +NIM_PARAMS := $(NIM_PARAMS) -d:libp2p_mix_experimental_exit_is_dest libbacktrace: + $(MAKE) -C vendor/nim-libbacktrace --no-print-directory BUILD_CXX_LIB=0 @@ -479,8 +479,13 @@ ifndef ANDROID_NDK_HOME endif build-libwaku-for-android-arch: - $(MAKE) rebuild-nat-libs CC=$(ANDROID_TOOLCHAIN_DIR)/bin/$(ANDROID_COMPILER) && \ - ./scripts/build_rln_android.sh $(CURDIR)/build $(LIBRLN_BUILDDIR) $(LIBRLN_VERSION) $(CROSS_TARGET) $(ABIDIR) && \ +ifneq ($(findstring /nix/store,$(LIBRLN_FILE)),) + mkdir -p $(CURDIR)/build/android/$(ABIDIR)/ + cp $(LIBRLN_FILE) $(CURDIR)/build/android/$(ABIDIR)/ +else + ./scripts/build_rln_android.sh $(CURDIR)/build $(LIBRLN_BUILDDIR) $(LIBRLN_VERSION) $(CROSS_TARGET) $(ABIDIR) +endif + $(MAKE) rebuild-nat-libs CC=$(ANDROID_TOOLCHAIN_DIR)/bin/$(ANDROID_COMPILER) CPU=$(CPU) ABIDIR=$(ABIDIR) ANDROID_ARCH=$(ANDROID_ARCH) ANDROID_COMPILER=$(ANDROID_COMPILER) ANDROID_TOOLCHAIN_DIR=$(ANDROID_TOOLCHAIN_DIR) $(ENV_SCRIPT) nim libWakuAndroid $(NIM_PARAMS) waku.nims libwaku-android-arm64: ANDROID_ARCH=aarch64-linux-android @@ -539,7 +544,7 @@ else $(error iOS builds are only supported on macOS) endif -# Build for iOS architecture +# Build for iOS architecture build-libwaku-for-ios-arch: IOS_SDK=$(IOS_SDK) IOS_ARCH=$(IOS_ARCH) IOS_SDK_PATH=$(IOS_SDK_PATH) $(ENV_SCRIPT) nim libWakuIOS $(NIM_PARAMS) waku.nims diff --git a/flake.lock b/flake.lock index 0700e6a43..b927e8807 100644 --- a/flake.lock +++ b/flake.lock @@ -2,17 +2,17 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1740603184, - "narHash": "sha256-t+VaahjQAWyA+Ctn2idyo1yxRIYpaDxMgHkgCNiMJa4=", + "lastModified": 1757590060, + "narHash": "sha256-EWwwdKLMZALkgHFyKW7rmyhxECO74+N+ZO5xTDnY/5c=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "f44bd8ca21e026135061a0a57dcf3d0775b67a49", + "rev": "0ef228213045d2cdb5a169a95d63ded38670b293", "type": "github" }, "original": { "owner": "NixOS", "repo": "nixpkgs", - "rev": "f44bd8ca21e026135061a0a57dcf3d0775b67a49", + "rev": "0ef228213045d2cdb5a169a95d63ded38670b293", "type": "github" } }, @@ -51,18 +51,18 @@ "rust-overlay": "rust-overlay" }, "locked": { - "lastModified": 1749115386, - "narHash": "sha256-UexIE2D7zr6aRajwnKongXwCZCeRZDXOL0kfjhqUFSU=", - "owner": "vacp2p", - "repo": "zerokit", - "rev": "dc0b31752c91e7b4fefc441cfa6a8210ad7dba7b", - "type": "github" + "lastModified": 1762211504, + "narHash": "sha256-SbDoBElFYJ4cYebltxlO2lYnz6qOaDAVY6aNJ5bqHDE=", + "ref": "refs/heads/master", + "rev": "3160d9504d07791f2fc9b610948a6cf9a58ed488", + "revCount": 342, + "type": "git", + "url": "https://github.com/vacp2p/zerokit" }, "original": { - "owner": "vacp2p", - "repo": "zerokit", - "rev": "dc0b31752c91e7b4fefc441cfa6a8210ad7dba7b", - "type": "github" + "rev": "3160d9504d07791f2fc9b610948a6cf9a58ed488", + "type": "git", + "url": "https://github.com/vacp2p/zerokit" } } }, diff --git a/flake.nix b/flake.nix index 1e63584ab..3bec6d786 100644 --- a/flake.nix +++ b/flake.nix @@ -7,9 +7,12 @@ }; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs?rev=f44bd8ca21e026135061a0a57dcf3d0775b67a49"; + # We are pinning the commit because ultimately we want to use same commit across different projects. + # A commit from nixpkgs 24.11 release : https://github.com/NixOS/nixpkgs/tree/release-24.11 + nixpkgs.url = "github:NixOS/nixpkgs/0ef228213045d2cdb5a169a95d63ded38670b293"; + # WARNING: Use 'nix flake update' to match flake.lock with vendor contents! zerokit = { - url = "github:vacp2p/zerokit?rev=dc0b31752c91e7b4fefc441cfa6a8210ad7dba7b"; + url = "git+https://github.com/vacp2p/zerokit?rev=3160d9504d07791f2fc9b610948a6cf9a58ed488"; inputs.nixpkgs.follows = "nixpkgs"; }; }; @@ -58,8 +61,6 @@ inherit stableSystems; src = self; targets = ["libwaku"]; - # We are not able to compile the code with nim-unwrapped-2_0 - useSystemNim = false; zerokitRln = zerokit.packages.${system}.rln; }; @@ -67,12 +68,10 @@ inherit stableSystems; src = self; targets = ["wakucanary"]; - # We are not able to compile the code with nim-unwrapped-2_0 - useSystemNim = false; zerokitRln = zerokit.packages.${system}.rln; }; - default = libwaku-android-arm64; + default = libwaku; }); devShells = forAllSystems (system: { diff --git a/nix/default.nix b/nix/default.nix index b628b669f..b8ca87f94 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,9 +1,8 @@ { - config ? {}, - pkgs ? import { }, + pkgs, src ? ../., targets ? ["libwaku-android-arm64"], - verbosity ? 2, + verbosity ? 1, useSystemNim ? true, quickAndDirty ? true, stableSystems ? [ @@ -19,43 +18,31 @@ assert pkgs.lib.assertMsg ((src.submodules or true) == true) let inherit (pkgs) stdenv lib writeScriptBin callPackage; - revision = lib.substring 0 8 (src.rev or "dirty"); + androidManifest = ""; -in stdenv.mkDerivation rec { + tools = pkgs.callPackage ./tools.nix {}; + version = tools.findKeyValue "^version = \"([a-f0-9.-]+)\"$" ../waku.nimble; + revision = lib.substring 0 8 (src.rev or src.dirtyRev or "00000000"); +in stdenv.mkDerivation { pname = "logos-messaging-nim"; - - version = "1.0.0-${revision}"; + version = "${version}-${revision}"; inherit src; + # Runtime dependencies buildInputs = with pkgs; [ - openssl - gmp - zip + openssl gmp zip ]; # Dependencies that should only exist in the build environment. nativeBuildInputs = let # Fix for Nim compiler calling 'git rev-parse' and 'lsb_release'. fakeGit = writeScriptBin "git" "echo ${version}"; - # Fix for the zerokit package that is built with cargo/rustup/cross. - fakeCargo = writeScriptBin "cargo" "echo ${version}"; - # Fix for the zerokit package that is built with cargo/rustup/cross. - fakeRustup = writeScriptBin "rustup" "echo ${version}"; - # Fix for the zerokit package that is built with cargo/rustup/cross. - fakeCross = writeScriptBin "cross" "echo ${version}"; - in - with pkgs; [ - cmake - which - lsb-release - zerokitRln - nim-unwrapped-2_0 - fakeGit - fakeCargo - fakeRustup - fakeCross + in with pkgs; [ + cmake which zerokitRln nim-unwrapped-2_2 fakeGit + ] ++ lib.optionals stdenv.isDarwin [ + pkgs.darwin.cctools gcc # Necessary for libbacktrace ]; # Environment variables required for Android builds @@ -63,13 +50,13 @@ in stdenv.mkDerivation rec { ANDROID_NDK_HOME="${pkgs.androidPkgs.ndk}"; NIMFLAGS = "-d:disableMarchNative -d:git_revision_override=${revision}"; XDG_CACHE_HOME = "/tmp"; - androidManifest = ""; makeFlags = targets ++ [ "V=${toString verbosity}" "QUICK_AND_DIRTY_COMPILER=${if quickAndDirty then "1" else "0"}" "QUICK_AND_DIRTY_NIMBLE=${if quickAndDirty then "1" else "0"}" "USE_SYSTEM_NIM=${if useSystemNim then "1" else "0"}" + "LIBRLN_FILE=${zerokitRln}/lib/librln.${if abidir != null then "so" else "a"}" ]; postPatch = '' @@ -92,12 +79,11 @@ in stdenv.mkDerivation rec { make nimbus-build-system-nimble-dir ''; - preBuild = '' - ln -s waku.nimble waku.nims - - ${lib.optionalString (!useSystemNim) '' + # For the Nim v2.2.4 built with NBS we added sat and zippy + preBuild = lib.optionalString (!useSystemNim) '' + # FIXME: Remove after nimbus-build-system includes 1cec2ab9. + sed -i '134,137d' vendor/nimbus-build-system/scripts/build_nim.sh pushd vendor/nimbus-build-system/vendor/Nim - mkdir dist mkdir -p dist/nimble/vendor/sat mkdir -p dist/nimble/vendor/checksums @@ -110,9 +96,7 @@ in stdenv.mkDerivation rec { cp -r ${callPackage ./checksums.nix {}}/. dist/nimble/vendor/checksums cp -r ${callPackage ./zippy.nix {}}/. dist/nimble/vendor/zippy chmod 777 -R dist/nimble csources_v2 - popd - ''} ''; installPhase = if abidir != null then '' @@ -122,14 +106,12 @@ in stdenv.mkDerivation rec { cd $out && zip -r libwaku.aar * '' else '' mkdir -p $out/bin $out/include - + # Copy library files - cp build/*.so $out/bin/ 2>/dev/null || true - cp build/*.a $out/bin/ 2>/dev/null || true - - # Copy the compiler-generated header - cp nimcache/debug/libwaku/libwaku.h $out/include/ 2>/dev/null || \ - cp nimcache/release/libwaku/libwaku.h $out/include/ + cp build/* $out/bin/ 2>/dev/null || true + + # Copy the header file + cp library/libwaku.h $out/include/ # Copy Nim's nimbase.h (required by libwaku.h) cp vendor/nimbus-build-system/vendor/Nim/lib/nimbase.h $out/include/ diff --git a/nix/pkgs/android-sdk/compose.nix b/nix/pkgs/android-sdk/compose.nix index c73aaee43..9a8536ddb 100644 --- a/nix/pkgs/android-sdk/compose.nix +++ b/nix/pkgs/android-sdk/compose.nix @@ -5,19 +5,16 @@ { androidenv, lib, stdenv }: -assert lib.assertMsg (stdenv.system != "aarch64-darwin") - "aarch64-darwin not supported for Android SDK. Use: NIXPKGS_SYSTEM_OVERRIDE=x86_64-darwin"; - # The "android-sdk-license" license is accepted # by setting android_sdk.accept_license = true. androidenv.composeAndroidPackages { cmdLineToolsVersion = "9.0"; toolsVersion = "26.1.1"; - platformToolsVersion = "33.0.3"; + platformToolsVersion = "34.0.5"; buildToolsVersions = [ "34.0.0" ]; platformVersions = [ "34" ]; cmakeVersions = [ "3.22.1" ]; - ndkVersion = "25.2.9519653"; + ndkVersion = "27.2.12479018"; includeNDK = true; includeExtras = [ "extras;android;m2repository" diff --git a/nix/shell.nix b/nix/shell.nix index fe0b065b4..3b83ac93d 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -1,16 +1,12 @@ -{ - pkgs ? import { }, -}: -let - optionalDarwinDeps = pkgs.lib.optionals pkgs.stdenv.isDarwin [ - pkgs.libiconv - pkgs.darwin.apple_sdk.frameworks.Security - ]; -in +{ pkgs }: + pkgs.mkShell { inputsFrom = [ pkgs.androidShell - ] ++ optionalDarwinDeps; + ] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ + pkgs.libiconv + pkgs.darwin.apple_sdk.frameworks.Security + ]; buildInputs = with pkgs; [ git @@ -18,7 +14,6 @@ pkgs.mkShell { rustup rustc cmake - nim-unwrapped-2_0 + nim-unwrapped-2_2 ]; - } diff --git a/scripts/build_rln_android.sh b/scripts/build_rln_android.sh index 93a8c47ff..15b81ce9c 100755 --- a/scripts/build_rln_android.sh +++ b/scripts/build_rln_android.sh @@ -25,4 +25,3 @@ cargo clean cross rustc --release --lib --target=${android_arch} --crate-type=cdylib cp ../target/${android_arch}/release/librln.so ${output_dir}/. popd - diff --git a/vendor/zerokit b/vendor/zerokit index a4bb3feb5..70c79fbc9 160000 --- a/vendor/zerokit +++ b/vendor/zerokit @@ -1 +1 @@ -Subproject commit a4bb3feb5054e6fd24827adf204493e6e173437b +Subproject commit 70c79fbc989d4f87d9352b2f4bddcb60ebe55b19