Skip to content

Commit

Permalink
Prepare build on macOS (#378)
Browse files Browse the repository at this point in the history
* 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 4987693.

* llvm-backend: Use FastBuild profile
  • Loading branch information
ttuegel authored Jan 28, 2021
1 parent f1f3ee5 commit 9bc64b1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 23 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ on:
push:
jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/[email protected]
with:
Expand All @@ -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
19 changes: 17 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand Down
28 changes: 14 additions & 14 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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;
Expand Down
14 changes: 9 additions & 5 deletions nix/llvm-backend.nix
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 9bc64b1

Please sign in to comment.