Skip to content

Commit

Permalink
Reapply "work around objc crash on macOS"
Browse files Browse the repository at this point in the history
This reverts commit b6169e0.
  • Loading branch information
Mic92 authored and mergify[bot] committed Jun 24, 2024
1 parent b7839e6 commit 32071eb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ stdenv.mkDerivation {
nlohmann_json
nix
boost
curl
];
nativeBuildInputs = with pkgs; [
meson
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ project('nix-eval-jobs', 'cpp',
license : 'GPL-3.0',
)

libcurl_dep = dependency('libcurl', required: true)
nix_main_dep = dependency('nix-main', required: true)
nix_store_dep = dependency('nix-store', required: true)
nix_expr_dep = dependency('nix-expr', required: true)
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ configure_file(

executable('nix-eval-jobs', src,
dependencies : [
libcurl_dep,
nix_main_dep,
nix_store_dep,
nix_expr_dep,
Expand Down
14 changes: 14 additions & 0 deletions src/nix-eval-jobs.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <nix/config.h> // IWYU pragma: keep

#include <curl/curl.h>
#include <nix/eval-settings.hh>
#include <nix/shared.hh>
#include <nix/sync.hh>
Expand Down Expand Up @@ -347,6 +348,19 @@ int main(int argc, char **argv) {
/* We are doing the garbage collection by killing forks */
setenv("GC_DONT_GC", "1", 1);

/* Because of an objc quirk[1], calling curl_global_init for the first time
after fork() will always result in a crash.
Up until now the solution has been to set
OBJC_DISABLE_INITIALIZE_FORK_SAFETY for every nix process to ignore that
error. Instead of working around that error we address it at the core -
by calling curl_global_init here, which should mean curl will already
have been initialized by the time we try to do so in a forked process.
[1]
https://github.com/apple-oss-distributions/objc4/blob/01edf1705fbc3ff78a423cd21e03dfc21eb4d780/runtime/objc-initialize.mm#L614-L636
*/
curl_global_init(CURL_GLOBAL_ALL);

return handleExceptions(argv[0], [&]() {
initNix();
initGC();
Expand Down

0 comments on commit 32071eb

Please sign in to comment.