Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare build on macOS #378

Merged
merged 11 commits into from
Jan 28, 2021
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/checkout@v2.3.4
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