From 9bc64b1f671c3f818cb9dd31d85acedf3ac3f376 Mon Sep 17 00:00:00 2001 From: Thomas Tuegel Date: Thu, 28 Jan 2021 15:34:18 -0600 Subject: [PATCH] Prepare build on macOS (#378) * test.yml: Run jobs on macOS * Test only on Ubuntu * test.yml: Build targets one at a time * Use llvmPackages.stdenv * llvm-backend: Set USE_NIX=TRUE * Remove -rpath from kllvm_add_tool * Remove link_directories and include_directories * Add CMake flag USE_LTO * Revert "Add CMake flag USE_LTO" This reverts commit 498769330412efad77a16a6bf93b7b7b50a28305. * llvm-backend: Use FastBuild profile --- .github/workflows/test.yml | 8 ++++++-- CMakeLists.txt | 19 +++++++++++++++++-- default.nix | 28 ++++++++++++++-------------- nix/llvm-backend.nix | 14 +++++++++----- 4 files changed, 46 insertions(+), 23 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f5539dec3..0a8cf5113 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,10 @@ on: push: jobs: tests: - runs-on: ubuntu-latest + strategy: + matrix: + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2.3.4 with: @@ -14,6 +17,7 @@ jobs: with: name: runtimeverification signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}' - - run: nix-build -A llvm-backend -A llvm-backend-matching + - run: nix-build -A llvm-backend + - run: nix-build -A llvm-backend-matching - run: nix-shell --run "echo OK" - run: nix-build test.nix diff --git a/CMakeLists.txt b/CMakeLists.txt index 901c4fed6..8933fa967 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,17 +30,24 @@ set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -fl if(APPLE) set(BACKEND_TARGET_TRIPLE "x86_64-apple-darwin") +if(NOT USE_NIX) include_directories(AFTER SYSTEM /usr/local/include) link_directories(AFTER /usr/local/lib) set(ENV{PKG_CONFIG_PATH} "/usr/local/opt/libffi/lib/pkgconfig") +endif() # USE_NIX else() set(BACKEND_TARGET_TRIPLE "x86_64-unknown-linux-gnu") endif() find_package(PkgConfig REQUIRED) pkg_check_modules(FFI REQUIRED libffi) +if(USE_NIX) +include_directories(AFTER ${FFI_INCLUDE_DIRS}) +link_directories(AFTER ${FFI_LIBRARY_DIRS}) +else() # USE_NIX include_directories(AFTER SYSTEM ${FFI_INCLUDE_DIRS}) link_directories(AFTER SYSTEM ${FFI_LIBRARY_DIRS}) +endif() # USE_NIX if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") set(LLVM_KOMPILE_LTO "lto") @@ -100,10 +107,18 @@ macro(kllvm_add_tool name) # Link against LLVM libraries llvm_config(${name}) if(APPLE) +if(NOT USE_NIX) target_link_libraries(${name} PUBLIC "-ljemalloc" "-Wl,-rpath /usr/local/lib" "-ldl") else() - target_link_libraries(${name} PUBLIC "-ljemalloc" "-Wl,-rpath=/usr/local/lib" "-ldl") -endif() + target_link_libraries(${name} PUBLIC "-ljemalloc" "-ldl") +endif() # NOT USE_NIX +else() +if(NOT USE_NIX) + target_link_libraries(${name} PUBLIC "-ljemalloc" "-Wl,-rpath /usr/local/lib" "-ldl") +else() + target_link_libraries(${name} PUBLIC "-ljemalloc" "-ldl") +endif() # NOT USE_NIX +endif() # APPLE endmacro(kllvm_add_tool) install( diff --git a/default.nix b/default.nix index cc8d2814f..27f9cbe63 100644 --- a/default.nix +++ b/default.nix @@ -10,6 +10,20 @@ let llvmPackages = pkgs.llvmPackages_10; + # The backend requires clang/lld/libstdc++ at runtime. + # The closest configuration in Nixpkgs is clang/lld without any C++ standard + # library. We override that configuration to inherit libstdc++ from stdenv. + clang = + let + override = attrs: { + extraBuildCommands = '' + ${attrs.extraBuildCommands} + sed -i $out/nix-support/cc-cflags -e '/^-nostdlib/ d' + ''; + }; + in + llvmPackages.lldClangNoLibcxx.override override; + llvm-backend = callPackage ./nix/llvm-backend.nix { inherit llvmPackages; }; @@ -33,20 +47,6 @@ let patchShebangs "$out/bin/llvm-kompile-testing" ''; - # The backend requires clang/lld/libstdc++ at runtime. - # The closest configuration in Nixpkgs is clang/lld without any C++ standard - # library. We override that configuration to inherit libstdc++ from stdenv. - clang = - let - override = attrs: { - extraBuildCommands = '' - ${attrs.extraBuildCommands} - sed -i $out/nix-support/cc-cflags -e '/^-nostdlib/ d' - ''; - }; - in - llvmPackages.lldClangNoLibcxx.override override; - self = { inherit clang llvm-backend llvm-backend-matching llvm-kompile-testing; inherit mavenix; diff --git a/nix/llvm-backend.nix b/nix/llvm-backend.nix index d82d20237..c17f15f8a 100644 --- a/nix/llvm-backend.nix +++ b/nix/llvm-backend.nix @@ -1,14 +1,14 @@ { - lib, stdenv, nix-gitignore, + lib, nix-gitignore, cmake, flex, pkgconfig, llvmPackages, boost, gmp, jemalloc, libffi, libyaml, mpfr, }: let inherit (nix-gitignore) gitignoreSourcePure; in +let inherit (llvmPackages) stdenv llvm; in let - inherit (llvmPackages) llvm clang; pname = "llvm-backend"; version = "0"; in @@ -32,13 +32,17 @@ stdenv.mkDerivation { ] ./..; - nativeBuildInputs = [ cmake clang flex llvm pkgconfig ]; + nativeBuildInputs = [ cmake flex llvm pkgconfig ]; buildInputs = [ boost gmp libffi libyaml jemalloc mpfr ]; cmakeFlags = [ - ''-DCMAKE_C_COMPILER=${lib.getBin clang}/bin/cc'' - ''-DCMAKE_CXX_COMPILER=${lib.getBin clang}/bin/c++'' + ''-DCMAKE_C_COMPILER=${lib.getBin stdenv.cc}/bin/cc'' + ''-DCMAKE_CXX_COMPILER=${lib.getBin stdenv.cc}/bin/c++'' + ''-DUSE_NIX=TRUE'' ]; + + cmakeBuildType = "FastBuild"; + NIX_CFLAGS_COMPILE = [ "-Wno-error" ]; doCheck = true;