Skip to content

Commit

Permalink
Merge pull request #1 from noir-lang/phated/nix-cmake-targets
Browse files Browse the repository at this point in the history
Cmake changes/fixes and some nix changes
  • Loading branch information
kobyhallx authored Jan 30, 2023
2 parents aa0cb62 + 0359d1b commit 1a58bef
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 130 deletions.
9 changes: 5 additions & 4 deletions barretenberg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# barretenberg
# copyright 2019 Spilsbury Holdings Ltd

cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.24)

include(cmake/toolchain.cmake)

Expand All @@ -15,18 +15,19 @@ option(DISABLE_ADX "Disable ADX assembly variant" OFF)
option(MULTITHREADING "Enable multi-threading" ON)
option(TESTING "Build tests" ON)
option(BENCHMARKS "Build benchmarks" ON)
option(NIX_VENDORED_LIBS "Use NIX provided LIBS" OFF)

if(ARM)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
message(STATUS "Compiling for ARM.")
set(ARM ON)
set(DISABLE_ASM ON)
set(DISABLE_ADX ON)
set(RUN_HAVE_STD_REGEX 0)
set(RUN_HAVE_POSIX_REGEX 0)
endif()

if(WASM)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "wasm32")
message(STATUS "Compiling for WebAssembly.")
set(WASM ON)
set(DISABLE_ASM ON)
set(MULTITHREADING OFF)
set(BENCHMARKS OFF)
Expand Down
5 changes: 2 additions & 3 deletions barretenberg/barretenberg.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ in llvmPackages.stdenv.mkDerivation rec {
leveldb
];

cmakeFlags = [ "-DNIX_VENDORED_LIBS=ON" "-DTESTING=OFF" "-DBENCHMARKS=OFF" ]
cmakeFlags = [ "-DTESTING=OFF" "-DBENCHMARKS=OFF" "-DTOOLCHAIN=${targetPlatform.system}" ]
++ optionals (targetPlatform.isDarwin || targetPlatform.isLinux)
[ "-DCMAKE_BUILD_TYPE=RelWithAssert" ]
++ optionals targetPlatform.isWasm [ "-DTOOLCHAIN=wasm-linux-clang" ];
[ "-DCMAKE_BUILD_TYPE=RelWithAssert" ];

NIX_CFLAGS_COMPILE =
optionals targetPlatform.isDarwin [ " -fno-aligned-allocation" ]
Expand Down
22 changes: 1 addition & 21 deletions barretenberg/cmake/threading.cmake
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
if (NOT NIX_VENDORED_LIBS)
if(APPLE)
message(STATUS "Setting OpenMP options")
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(OpenMP_C_FLAGS "-fopenmp")
set(OpenMP_C_FLAGS_WORK "-fopenmp")
set(OpenMP_C_LIB_NAMES "libomp")
set(OpenMP_C_LIB_NAMES_WORK "libomp")
set(OpenMP_libomp_LIBRARY "$ENV{BREW_PREFIX}/opt/libomp/lib/libomp.dylib")
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(OpenMP_CXX_FLAGS "-fopenmp")
set(OpenMP_CXX_FLAGS_WORK "-fopenmp")
set(OpenMP_CXX_LIB_NAMES "libomp")
set(OpenMP_CXX_LIB_NAMES_WORK "libomp")
set(OpenMP_libomp_LIBRARY "$ENV{BREW_PREFIX}/opt/libomp/lib/libomp.dylib")
endif()
endif()
endif()

# TODO: Add brew to path if it exists so OpenMP can be discovered from it
if(MULTITHREADING)
find_package(OpenMP REQUIRED)
message(STATUS "Multithreading is enabled.")
Expand Down
7 changes: 7 additions & 0 deletions barretenberg/cmake/toolchains/aarch64-darwin.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(CMAKE_SYSTEM_NAME Darwin)
set(CMAKE_SYSTEM_PROCESSOR aarch64)

# TODO: Add brew to path if it exists so clang can be discovered from it
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)

3 changes: 0 additions & 3 deletions barretenberg/cmake/toolchains/aarch64-linux-clang.cmake

This file was deleted.

6 changes: 6 additions & 0 deletions barretenberg/cmake/toolchains/aarch64-linux.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)

set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)

4 changes: 0 additions & 4 deletions barretenberg/cmake/toolchains/arm-apple-clang.cmake

This file was deleted.

37 changes: 0 additions & 37 deletions barretenberg/cmake/toolchains/wasm-linux-clang.cmake

This file was deleted.

4 changes: 4 additions & 0 deletions barretenberg/cmake/toolchains/wasm32-wasi.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR wasm32)
set(CMAKE_SYSTEM_VERSION 1)

3 changes: 0 additions & 3 deletions barretenberg/cmake/toolchains/x86_64-apple-clang.cmake

This file was deleted.

7 changes: 7 additions & 0 deletions barretenberg/cmake/toolchains/x86_64-darwin.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(CMAKE_SYSTEM_NAME Darwin)
set(CMAKE_SYSTEM_PROCESSOR x86_64)

# TODO: Add brew to path if it exists so clang can be discovered from it
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)

2 changes: 0 additions & 2 deletions barretenberg/cmake/toolchains/x86_64-linux-clang.cmake

This file was deleted.

2 changes: 0 additions & 2 deletions barretenberg/cmake/toolchains/x86_64-linux-gcc.cmake

This file was deleted.

2 changes: 0 additions & 2 deletions barretenberg/cmake/toolchains/x86_64-linux-gcc10.cmake

This file was deleted.

6 changes: 6 additions & 0 deletions barretenberg/cmake/toolchains/x86_64-linux.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86_64)

set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)

40 changes: 10 additions & 30 deletions barretenberg/src/aztec/stdlib/merkle_tree/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
if(NOT WASM)
include(FetchContent)
FetchContent_Declare(
leveldb
GIT_REPOSITORY https://github.com/google/leveldb.git
GIT_TAG 1.22
FIND_PACKAGE_ARGS
)

if (NOT NIX_VENDORED_LIBS)
include(FetchContent)
FetchContent_Declare(
leveldb
GIT_REPOSITORY https://github.com/google/leveldb.git
GIT_TAG 1.22
)

FetchContent_GetProperties(leveldb)
if(NOT leveldb_POPULATED)
FetchContent_Populate(leveldb)
set(LEVELDB_BUILD_TESTS OFF CACHE BOOL "LevelDB tests off")
add_subdirectory(${leveldb_SOURCE_DIR} ${leveldb_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

target_compile_options(
leveldb
PRIVATE
-Wno-unknown-warning-option
-Wno-unused-but-set-variable
-Wno-sign-conversion
-Wno-unused-parameter
-Wno-shorten-64-to-32
-Wno-implicit-int-conversion
-Wno-conversion
-Wno-implicit-fallthrough
)

link_libraries(leveldb)
endif()
FetchContent_MakeAvailable(leveldb)

link_libraries(leveldb)
endif()

barretenberg_module(stdlib_merkle_tree stdlib_primitives stdlib_blake2s stdlib_pedersen)
41 changes: 22 additions & 19 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,8 @@
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
libbarretenbergOverlay = final: prev: {
libbarretenberg = final.callPackage ./barretenberg/barretenberg.nix {
llvmPackages = final.llvmPackages_12;
};
};

pkgs = import nixpkgs {
inherit system;
overlays = [ libbarretenbergOverlay ];
};

shellComposition = {
Expand All @@ -29,28 +22,38 @@
pkgs.libbarretenberg.nativeBuildInputs ++ [ starship ];
buildInputs = pkgs.libbarretenberg.buildInputs;

shellHook = with pkgs; ''
shellHook = ''
eval "$(starship init bash)"
echo "Hello :)"
'';
};
in {

legacyPackages = pkgs;

packages.${pkgs.libbarretenberg.pname} = pkgs.libbarretenberg;

packages.default =
self.packages.${system}.${pkgs.libbarretenberg.pname};
in rec {
packages = {
llvm11 = pkgs.callPackage ./barretenberg/barretenberg.nix {
llvmPackages = pkgs.llvmPackages_11;
};
llvm12 = pkgs.callPackage ./barretenberg/barretenberg.nix {
llvmPackages = pkgs.llvmPackages_12;
};
llvm13 = pkgs.callPackage ./barretenberg/barretenberg.nix {
llvmPackages = pkgs.llvmPackages_13;
};
llvm14 = pkgs.callPackage ./barretenberg/barretenberg.nix {
llvmPackages = pkgs.llvmPackages_14;
};
wasm32 = pkgs.pkgsCross.wasi32.callPackage ./barretenberg/barretenberg.nix {
llvmPackages = pkgs.pkgsCross.wasi32.llvmPackages_12;
};

packages.wasm = pkgs.pkgsCross.wasi32.libbarretenberg;
default = packages.llvm11;
};

devShells.default =
pkgs.mkShell.override { stdenv = pkgs.libbarretenberg.stdenv; }
pkgs.mkShell.override { stdenv = packages.default.stdenv; }
shellComposition;

devShells.wasi32 = pkgs.mkShell.override {
stdenv = pkgs.pkgsCross.wasi32.libbarretenberg.stdenv;
stdenv = packages.wasm32.stdenv;
} shellComposition;

});
Expand Down

0 comments on commit 1a58bef

Please sign in to comment.