From 1309b2c51a3cb0a99187402b77c26173649be81b Mon Sep 17 00:00:00 2001 From: Soares Chen Date: Sat, 7 Sep 2024 09:39:27 +0200 Subject: [PATCH] Add support for MacOS build on Nix (#74) * Add support for MacOS build on Nix * Add Apple libraries into nix develop shell * Try to fix Cairo Nix build * Remove unneeded changes --- ...iro-contracts.yml => cairo-contracts.yaml} | 0 .../{light-client.yml => light-client.yaml} | 0 .github/workflows/macos.yaml | 31 +++++++++++++++++++ flake.lock | 6 ++-- flake.nix | 8 +++-- nix/cairo.nix | 8 ++++- nix/scarb.nix | 4 +++ nix/snforge.nix | 6 +++- nix/starknet-devnet.nix | 6 +++- 9 files changed, 61 insertions(+), 8 deletions(-) rename .github/workflows/{cairo-contracts.yml => cairo-contracts.yaml} (100%) rename .github/workflows/{light-client.yml => light-client.yaml} (100%) create mode 100644 .github/workflows/macos.yaml diff --git a/.github/workflows/cairo-contracts.yml b/.github/workflows/cairo-contracts.yaml similarity index 100% rename from .github/workflows/cairo-contracts.yml rename to .github/workflows/cairo-contracts.yaml diff --git a/.github/workflows/light-client.yml b/.github/workflows/light-client.yaml similarity index 100% rename from .github/workflows/light-client.yml rename to .github/workflows/light-client.yaml diff --git a/.github/workflows/macos.yaml b/.github/workflows/macos.yaml new file mode 100644 index 00000000..fa887a4f --- /dev/null +++ b/.github/workflows/macos.yaml @@ -0,0 +1,31 @@ +name: MacOS Build +on: + pull_request: {} + push: + tags: + - v[0-9]+.* + branches: + - "release/*" + - main + +jobs: + test-contracts: + name: Build MacOS Nix dependencies + runs-on: macos-14 + timeout-minutes: 60 + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@V27 + with: + extra_nix_config: | + experimental-features = nix-command flakes + - uses: cachix/cachix-action@v15 + with: + name: ibc-starknet + extraPullNames: hermes-sdk,cosmos-nix + authToken: ${{ secrets.CACHIX_AUTH_TOKEN }} + + - name: Run Nix build + run: | + sudo rm -rf /opt/homebrew + nix develop -c true diff --git a/flake.lock b/flake.lock index af719169..9ff220ae 100644 --- a/flake.lock +++ b/flake.lock @@ -1493,11 +1493,11 @@ }, "nixpkgs_6": { "locked": { - "lastModified": 1725194671, - "narHash": "sha256-tLGCFEFTB5TaOKkpfw3iYT9dnk4awTP/q4w+ROpMfuw=", + "lastModified": 1725534445, + "narHash": "sha256-Yd0FK9SkWy+ZPuNqUgmVPXokxDgMJoGuNpMEtkfcf84=", "owner": "nixos", "repo": "nixpkgs", - "rev": "b833ff01a0d694b910daca6e2ff4a3f26dee478c", + "rev": "9bb1e7571aadf31ddb4af77fc64b2d59580f9a39", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 968a1546..6cb3ff74 100644 --- a/flake.nix +++ b/flake.nix @@ -108,7 +108,6 @@ tools = { inherit (nixpkgs) - pkg-config protobuf cargo-nextest taplo @@ -118,7 +117,12 @@ nixfmt = nixpkgs.nixfmt-rfc-style; }; - shell-deps = (builtins.attrValues starknet-pkgs) ++ (builtins.attrValues tools); + mac-deps = nixpkgs.lib.optional nixpkgs.stdenv.isDarwin [ + nixpkgs.libiconv + nixpkgs.darwin.apple_sdk.frameworks.SystemConfiguration + ]; + + shell-deps = (builtins.attrValues starknet-pkgs) ++ (builtins.attrValues tools) ++ mac-deps; in { packages = { diff --git a/nix/cairo.nix b/nix/cairo.nix index b1ab994d..51f7923d 100644 --- a/nix/cairo.nix +++ b/nix/cairo.nix @@ -13,7 +13,13 @@ let OPENSSL_NO_VENDOR = 1; PKG_CONFIG_PATH = "${nixpkgs.openssl.dev}/lib/pkgconfig"; - nativeBuildInputs = [ nixpkgs.pkg-config ]; + nativeBuildInputs = [ + nixpkgs.pkg-config + ]; + + buildInputs = nixpkgs.lib.optionals nixpkgs.stdenv.isDarwin [ + nixpkgs.darwin.apple_sdk.frameworks.SystemConfiguration + ]; }; in cairo diff --git a/nix/scarb.nix b/nix/scarb.nix index 0cbf81cc..00367b97 100644 --- a/nix/scarb.nix +++ b/nix/scarb.nix @@ -15,6 +15,10 @@ let cargoHash = "sha256-cAEwCX1zGJu4+ufdVSqBbksa1FLZWVNt2TLZ5JlGISk="; SCARB_CORELIB_LOCAL_PATH = cairo-src + "/corelib"; + + buildInputs = nixpkgs.lib.optionals nixpkgs.stdenv.isDarwin [ + nixpkgs.darwin.apple_sdk.frameworks.SystemConfiguration + ]; }; in cairo diff --git a/nix/snforge.nix b/nix/snforge.nix index b8c4a3be..76a81613 100644 --- a/nix/snforge.nix +++ b/nix/snforge.nix @@ -14,12 +14,16 @@ let }; }; + doCheck = false; + OPENSSL_NO_VENDOR = 1; PKG_CONFIG_PATH = "${nixpkgs.openssl.dev}/lib/pkgconfig"; nativeBuildInputs = [ nixpkgs.pkg-config ]; - doCheck = false; + buildInputs = nixpkgs.lib.optionals nixpkgs.stdenv.isDarwin [ + nixpkgs.darwin.apple_sdk.frameworks.SystemConfiguration + ]; }; in snforge diff --git a/nix/starknet-devnet.nix b/nix/starknet-devnet.nix index 21f28595..84f8f1c7 100644 --- a/nix/starknet-devnet.nix +++ b/nix/starknet-devnet.nix @@ -17,12 +17,16 @@ let lockFile = starknet-devnet-src + "/Cargo.lock"; }; + doCheck = false; + OPENSSL_NO_VENDOR = 1; PKG_CONFIG_PATH = "${nixpkgs.openssl.dev}/lib/pkgconfig"; nativeBuildInputs = [ nixpkgs.pkg-config ]; - doCheck = false; + buildInputs = nixpkgs.lib.optionals nixpkgs.stdenv.isDarwin [ + nixpkgs.darwin.apple_sdk.frameworks.SystemConfiguration + ]; }; in starknet-devnet