Skip to content

Commit

Permalink
82 Fix blocker macOS problems
Browse files Browse the repository at this point in the history
There were two main problems

1. Dynamic linking on macOS requires some extra hoop-jumping:

   ```cmake
   if(APPLE)
     target_link_options(nain4-tests PRIVATE -undefined dynamic_lookup)
   endif()
   ```

2. There was a clash of libc++ versions between clang 16 and the
   dependencies pulled in by Qt and Geant4. This caused very mysterious
   segfaults before main was entered on pretty much any executable.

   We got around this by overriding the libc++ version used by clang 16
   on Darwin. (The Linux version had no such problems).

   An [upstream fix](NixOS/nixpkgs#234710) is
   in the works. Once that lands, we can remove our hack.

Now that all this has been fixed, GHA failures on macOS are no longer
allowed.

We need to bump the tag in the client-side fetch-content test, which
will continue to fail until we push the corresponding tag to this merge
commit.
  • Loading branch information
jacg committed Aug 17, 2023
2 parents bf524c6 + 2b0615c commit dcd2941
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 24 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
os: [ubuntu-22.04, macos-12]
py: [311]
allow-fail: [false]
include:
- os: macos-12
py: 311
allow-fail: true

steps:
- uses: actions/checkout@v3.5.3
Expand Down
2 changes: 1 addition & 1 deletion client_side_tests/client_fetch_content/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(FETCHCONTENT_UPDATES_DISCONNECTED ON CACHE BOOL "Cache package contents to a
FetchContent_Declare(
Nain4
GIT_REPOSITORY https://github.com/jacg/nain4.git
GIT_TAG v0.1.8
GIT_TAG v0.1.9
# make sure that no other nain4 installation is used
OVERRIDE_FIND_PACKAGE
SOURCE_SUBDIR nain4
Expand Down
1 change: 1 addition & 0 deletions client_side_tests/test_fetch_content_recompile.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -e

tmp_dir=$(mktemp -d -t nain4-recompile-XXXXXX)
test_dir=$(dirname "$(readlink -f "$0")")
Expand Down
58 changes: 40 additions & 18 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,51 @@
enableRaytracerX11 = false;
});

# Should be able to remove this, once https://github.com/NixOS/nixpkgs/issues/234710 is merged
clang_16 = if pkgs.stdenv.isDarwin
then pkgs.llvmPackages_16.clang.override rec {
libc = pkgs.darwin.Libsystem;
bintools = pkgs.bintools.override { inherit libc; };
inherit (pkgs.llvmPackages) libcxx;
extraPackages = [
pkgs.llvmPackages.libcxxabi
# Use the compiler-rt associated with clang, but use the libc++abi from the stdenv
# to avoid linking against two different versions (for the same reasons as above).
(pkgs.llvmPackages_16.compiler-rt.override {
inherit (pkgs.llvmPackages) libcxxabi;
})
];
}
else pkgs.llvmPackages.clang;

my-packages = with pkgs; [
my-geant4
geant4.data.G4PhotonEvaporation
geant4.data.G4EMLOW
geant4.data.G4RadioactiveDecay
geant4.data.G4ENSDFSTATE
geant4.data.G4SAIDDATA
geant4.data.G4PARTICLEXS
geant4.data.G4NDL
clang_16
clang-tools
cmake
cmake-language-server
catch2_3
just
gnused # For hacking CMAKE_EXPORT stuff into CMakeLists.txt
mdbook
] ++ lib.optionals stdenv.isDarwin [

] ++ lib.optionals stdenv.isLinux [
];

in {

devShell = pkgs.mkShell.override { stdenv = pkgs.clang_16.stdenv; } {
name = "G4-examples-devenv";

packages = with pkgs; [
my-geant4
geant4.data.G4PhotonEvaporation
geant4.data.G4EMLOW
geant4.data.G4RadioactiveDecay
geant4.data.G4ENSDFSTATE
geant4.data.G4SAIDDATA
geant4.data.G4PARTICLEXS
geant4.data.G4NDL
clang_16
clang-tools
cmake
cmake-language-server
catch2_3
just
gnused # For hacking CMAKE_EXPORT stuff into CMakeLists.txt
mdbook
];
packages = my-packages;

G4_DIR = "${pkgs.geant4}";
G4_EXAMPLES_DIR = "${pkgs.geant4}/share/Geant4-11.0.4/examples/";
Expand Down
8 changes: 8 additions & 0 deletions nain4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ FILE(GLOB HEADERS ${PROJECT_SOURCE_DIR}/*.hh)

add_library(Nain4 SHARED ${SOURCES} ${HEADERS})

if(APPLE)
target_link_options(Nain4 PRIVATE -undefined dynamic_lookup)
endif()

#set_target_properties(Nain4 PROPERTIES ENABLE_EXPORTS ON)

#----------------------------------------------------------------------------
Expand Down Expand Up @@ -80,6 +84,10 @@ set(ALL_TEST_SOURCES
# TODO including headers in add_executable apparently makes them show up in IDEs. Verify how?
add_executable(nain4-tests ${ALL_TEST_SOURCES})

if(APPLE)
target_link_options(nain4-tests PRIVATE -undefined dynamic_lookup)
endif()


target_link_libraries(
nain4-tests
Expand Down

0 comments on commit dcd2941

Please sign in to comment.