From 307519076aecf6ccedf98b9aae4737b052b5b4f3 Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Fri, 6 Feb 2026 18:28:22 +0000 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 --- .github/workflows/ci-nix.yml | 48 +++++++++++++++++++++++++ Makefile | 60 +++++++++++++++++++++++++++++--- flake.lock | 28 +++++++-------- flake.nix | 9 ++--- nix/default.nix | 56 ++++++++++------------------- nix/pkgs/android-sdk/compose.nix | 7 ++-- nix/shell.nix | 19 ++++------ scripts/build_rln_android.sh | 1 - 8 files changed, 147 insertions(+), 81 deletions(-) create mode 100644 .github/workflows/ci-nix.yml diff --git a/.github/workflows/ci-nix.yml b/.github/workflows/ci-nix.yml new file mode 100644 index 000000000..8fc7ac985 --- /dev/null +++ b/.github/workflows/ci-nix.yml @@ -0,0 +1,48 @@ +name: ci / nix +permissions: + contents: read + pull-requests: read + checks: write +on: + pull_request: + branches: [master] + +jobs: + build: + strategy: + fail-fast: false + matrix: + system: + - aarch64-darwin + - x86_64-linux + nixpkg: + - libwaku + - libwaku-android-arm64 + - wakucanary + + exclude: + # Android SDK limitation + - system: aarch64-darwin + nixpkg: libwaku-android-arm64 + + include: + - system: aarch64-darwin + runs_on: [self-hosted, macOS, ARM64] + + - system: x86_64-linux + runs_on: [self-hosted, Linux, X64] + + name: '${{ matrix.system }} / ${{ matrix.nixpkg }}' + runs-on: ${{ matrix.runs_on }} + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: 'Run Nix build for {{ matrix.nixpkg }}' + shell: bash + run: nix build -L '.?submodules=1#${{ matrix.nixpkg }}' + + - name: 'Show result contents' + shell: bash + run: find result -type f diff --git a/Makefile b/Makefile index 464d6877c..c7ac7d58c 100644 --- a/Makefile +++ b/Makefile @@ -147,7 +147,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 @@ -186,9 +186,9 @@ LIBRLN_BUILDDIR := $(CURDIR)/vendor/zerokit LIBRLN_VERSION := v0.9.0 ifeq ($(detected_OS),Windows) -LIBRLN_FILE := rln.lib +LIBRLN_FILE ?= rln.lib else -LIBRLN_FILE := librln_$(LIBRLN_VERSION).a +LIBRLN_FILE ?= librln_$(LIBRLN_VERSION).a endif $(LIBRLN_FILE): @@ -466,8 +466,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 @@ -504,6 +509,51 @@ libwaku-android: # It's likely this architecture is not used so we might just not support it. # $(MAKE) libwaku-android-arm +################# +## iOS Bindings # +################# +.PHONY: libwaku-ios-precheck \ + libwaku-ios-device \ + libwaku-ios-simulator \ + libwaku-ios + +IOS_DEPLOYMENT_TARGET ?= 18.0 + +# Get SDK paths dynamically using xcrun +define get_ios_sdk_path +$(shell xcrun --sdk $(1) --show-sdk-path 2>/dev/null) +endef + +libwaku-ios-precheck: +ifeq ($(detected_OS),Darwin) + @command -v xcrun >/dev/null 2>&1 || { echo "Error: Xcode command line tools not installed"; exit 1; } +else + $(error iOS builds are only supported on macOS) +endif + +# 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 + +# iOS device (arm64) +libwaku-ios-device: IOS_ARCH=arm64 +libwaku-ios-device: IOS_SDK=iphoneos +libwaku-ios-device: IOS_SDK_PATH=$(call get_ios_sdk_path,iphoneos) +libwaku-ios-device: | libwaku-ios-precheck build deps + $(MAKE) build-libwaku-for-ios-arch IOS_ARCH=$(IOS_ARCH) IOS_SDK=$(IOS_SDK) IOS_SDK_PATH=$(IOS_SDK_PATH) + +# iOS simulator (arm64 - Apple Silicon Macs) +libwaku-ios-simulator: IOS_ARCH=arm64 +libwaku-ios-simulator: IOS_SDK=iphonesimulator +libwaku-ios-simulator: IOS_SDK_PATH=$(call get_ios_sdk_path,iphonesimulator) +libwaku-ios-simulator: | libwaku-ios-precheck build deps + $(MAKE) build-libwaku-for-ios-arch IOS_ARCH=$(IOS_ARCH) IOS_SDK=$(IOS_SDK) IOS_SDK_PATH=$(IOS_SDK_PATH) + +# Build all iOS targets +libwaku-ios: + $(MAKE) libwaku-ios-device + $(MAKE) libwaku-ios-simulator + cwaku_example: | build libwaku echo -e $(BUILD_MSG) "build/$@" && \ cc -o "build/$@" \ 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 3427ff6ac..88229a826 100644 --- a/flake.nix +++ b/flake.nix @@ -10,8 +10,9 @@ # 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: Remember to update commit and use 'nix flake update' to update flake.lock. zerokit = { - url = "github:vacp2p/zerokit?rev=dc0b31752c91e7b4fefc441cfa6a8210ad7dba7b"; + url = "git+https://github.com/vacp2p/zerokit?rev=3160d9504d07791f2fc9b610948a6cf9a58ed488"; inputs.nixpkgs.follows = "nixpkgs"; }; }; @@ -60,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; }; @@ -69,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 73838a4a1..d77862e8f 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,14 +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}/target/release/librln.a" + "LIBRLN_FILE=${zerokitRln}/lib/librln.${if abidir != null then "so" else "a"}" ]; configurePhase = '' @@ -80,12 +66,8 @@ in stdenv.mkDerivation rec { ''; # For the Nim v2.2.4 built with NBS we added sat and zippy - preBuild = '' - ln -s waku.nimble waku.nims - - ${lib.optionalString (!useSystemNim) '' + preBuild = lib.optionalString (!useSystemNim) '' pushd vendor/nimbus-build-system/vendor/Nim - mkdir dist mkdir -p dist/nimble/vendor/sat mkdir -p dist/nimble/vendor/checksums @@ -98,9 +80,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 '' @@ -110,10 +90,10 @@ in stdenv.mkDerivation rec { cd $out && zip -r libwaku.aar * '' else '' mkdir -p $out/bin $out/include - + # Copy library files cp build/* $out/bin/ 2>/dev/null || true - + # Copy the header file cp library/libwaku.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 -