diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index dd76e8301..91da25315 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -21,7 +21,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] - target: [llvm12, wasm32, cross-aarch64] + target: [default, wasm32, cross-aarch64] steps: - name: Checkout @@ -32,6 +32,10 @@ jobs: nix_path: nixpkgs=channel:nixos-22.11 github_access_token: ${{ secrets.GITHUB_TOKEN }} + - name: Check nix flake + run: | + nix flake check + - name: Build barretenberg as ${{ matrix.target }} run: | nix build -L .#${{ matrix.target }} diff --git a/barretenberg-wasm.nix b/barretenberg-wasm.nix new file mode 100644 index 000000000..5c176576e --- /dev/null +++ b/barretenberg-wasm.nix @@ -0,0 +1,35 @@ +{ stdenv, cmake, ninja, binaryen, callPackage }: +let + toolchain_file = ./cpp/cmake/toolchains/wasm32-wasi.cmake; + wasi-sdk = callPackage ./wasi-sdk.nix { }; +in +stdenv.mkDerivation +{ + pname = "barretenberg.wasm"; + version = "0.1.0"; + + src = ./cpp; + + nativeBuildInputs = [ cmake ninja binaryen wasi-sdk ]; + + buildInputs = [ ]; + + cmakeFlags = [ + "-DTESTING=OFF" + "-DBENCHMARKS=OFF" + "-DCMAKE_TOOLCHAIN_FILE=${toolchain_file}" + "-DCMAKE_C_COMPILER=${wasi-sdk}/bin/clang" + "-DCMAKE_CXX_COMPILER=${wasi-sdk}/bin/clang++" + "-DCMAKE_AR=${wasi-sdk}/bin/llvm-ar" + "-DCMAKE_RANLIB=${wasi-sdk}/bin/llvm-ranlib" + "-DCMAKE_SYSROOT=${wasi-sdk}/share/wasi-sysroot" + "-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER" + "-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY" + "-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY" + "-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY" + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + ]; + + enableParallelBuilding = true; +} diff --git a/barretenberg.nix b/barretenberg.nix index fc00242f4..be2fd7c8b 100644 --- a/barretenberg.nix +++ b/barretenberg.nix @@ -1,4 +1,4 @@ -{ overrideCC, stdenv, llvmPackages, cmake, ninja, lib, callPackage, binaryen, gcc11 }: +{ overrideCC, stdenv, llvmPackages, cmake, ninja, lib, callPackage, gcc11 }: let targetPlatform = stdenv.targetPlatform; buildEnv = @@ -18,21 +18,16 @@ buildEnv.mkDerivation src = ./cpp; - nativeBuildInputs = [ cmake ninja ] - ++ optionals targetPlatform.isWasm [ binaryen ]; + nativeBuildInputs = [ cmake ninja ]; - buildInputs = [ ] - ++ optionals (targetPlatform.isDarwin || targetPlatform.isLinux) [ - llvmPackages.openmp - ]; + buildInputs = [ llvmPackages.openmp ]; cmakeFlags = [ "-DTESTING=OFF" "-DBENCHMARKS=OFF" "-DCMAKE_TOOLCHAIN_FILE=${toolchain_file}" - ] - ++ optionals (targetPlatform.isDarwin || targetPlatform.isLinux) - [ "-DCMAKE_BUILD_TYPE=RelWithAssert" ]; + "-DCMAKE_BUILD_TYPE=RelWithAssert" + ]; NIX_CFLAGS_COMPILE = optionals targetPlatform.isDarwin [ " -fno-aligned-allocation" ]; diff --git a/flake.lock b/flake.lock index 4128dfe7e..d0e2bfe5c 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "flake-utils": { "locked": { - "lastModified": 1676283394, - "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=", + "lastModified": 1678901627, + "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=", "owner": "numtide", "repo": "flake-utils", - "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073", + "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6", "type": "github" }, "original": { @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1678230755, - "narHash": "sha256-SFAXgNjNTXzcAideXcP0takfUGVft/VR5CACmYHg+Fc=", + "lastModified": 1680498889, + "narHash": "sha256-4nGFBm+oILOO6DPoKTPxVlfkZSxCOY4W25zSRHESK48=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "a7cc81913bb3cd1ef05ed0ece048b773e1839e51", + "rev": "799d153e4f316143a9db0eb869ecf44d8d4c0356", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 1d4dd4d75..1d34c0fb7 100644 --- a/flake.nix +++ b/flake.nix @@ -9,10 +9,12 @@ outputs = { self, nixpkgs, flake-utils }: let - barretenbergOverlay = self: super: { - # It seems that llvmPackages_11 can't build WASI, so default to llvmPackages_12 - barretenberg = super.callPackage ./barretenberg.nix { - llvmPackages = self.llvmPackages_12; + barretenbergOverlay = final: prev: { + barretenberg = prev.callPackage ./barretenberg.nix { }; + barretenberg-wasm = prev.callPackage ./barretenberg-wasm.nix { }; + barretenberg-transcript00 = prev.fetchurl { + url = "http://aztec-ignition.s3.amazonaws.com/MAIN%20IGNITION/monomial/transcript00.dat"; + sha256 = "sha256-D5SzlCb1pX0aF3QmJPfTFwoy4Z1sXhbyAigUOdvkhpU="; }; }; in @@ -33,10 +35,7 @@ value = pkgs.pkgsCross.aarch64-multiplatform-musl.pkgsLLVM.barretenberg; } ++ optional (pkgs.hostPlatform.isx86_64 && pkgs.hostPlatform.isDarwin) { name = "cross-aarch64"; - value = pkgs.pkgsCross.aarch64-darwin.barretenberg.override { - # llvmPackages_12 seems to fail when we try to cross-compile but llvmPackages_11 works - llvmPackages = pkgs.llvmPackages_11; - }; + value = pkgs.pkgsCross.aarch64-darwin.barretenberg; } ); @@ -53,20 +52,19 @@ in rec { packages = { - llvm11 = pkgs.barretenberg.override { - llvmPackages = pkgs.llvmPackages_11; + llvm11 = pkgs.barretenberg; + llvm12 = pkgs.barretenberg.override { + llvmPackages = pkgs.llvmPackages_12; }; - llvm12 = pkgs.barretenberg; llvm13 = pkgs.barretenberg.override { llvmPackages = pkgs.llvmPackages_13; }; llvm14 = pkgs.barretenberg.override { llvmPackages = pkgs.llvmPackages_14; }; - wasm32 = pkgs.pkgsCross.wasi32.barretenberg; + wasm32 = pkgs.barretenberg-wasm; - # Defaulting to llvm12 so we can ensure consistent shells - default = packages.llvm12; + default = packages.llvm11; } // crossTargets; # Provide legacyPackages with our overlay so we can run @@ -87,6 +85,7 @@ wasm32 = pkgs.mkShell.override { + # TODO: This derivations forces wasi-sdk 12 so the stdenv will have the wrong tools stdenv = packages.wasm32.stdenv; } ({ diff --git a/wasi-sdk.nix b/wasi-sdk.nix new file mode 100644 index 000000000..c630054ba --- /dev/null +++ b/wasi-sdk.nix @@ -0,0 +1,48 @@ +# Copied from https://github.com/ereslibre/nixities/blob/2c60af777fc863f90e6e4eeffcf3465def93a1f3/packages/wasi-sdk/default.nix +# with a fix for the autoPatchelfHook needing libstdc++.so and some refactor +{ lib, pkgs, stdenv }: +let + pname = "wasi-sdk"; + version = "12"; +in +pkgs.stdenv.mkDerivation { + inherit pname version; + + sourceRoot = "${pname}-${version}.0"; + dontBuild = true; + dontConfigure = true; + dontStrip = true; + + nativeBuildInputs = + lib.optional stdenv.isLinux (with pkgs; [ autoPatchelfHook ]); + + # Needed by autoPatchelfHook to have libstdc++ + # see https://discourse.nixos.org/t/autopatchelfhook-not-patching-all-dependencies/14634/6 + buildInputs = + lib.optional stdenv.isLinux [ stdenv.cc.cc.lib ]; + + installPhase = '' + mkdir -p $out/{bin,lib,share} + mv bin/* $out/bin/ + mv lib/* $out/lib/ + mv share/* $out/share/ + ''; + + src = + let + tarball = + if stdenv.hostPlatform.isDarwin then { + suffix = "macos"; + hash = "sha256-juJfnD/eYY/upcV62tOFFSYmeEtra1L7Vj5e2DK/U+8="; + } else { + suffix = "linux"; + hash = "sha256-+kdpTXW/b86Y++eScZMpiyXuA9reJ/ykU9fdUwN4lzo="; + }; + in + + pkgs.fetchurl { + url = + "https://github.com/WebAssembly/${pname}/releases/download/${pname}-${version}/${pname}-${version}.0-${tarball.suffix}.tar.gz"; + hash = tarball.hash; + }; +}