mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-23 15:33:13 +00:00
Merge pull request #308504 from Liamolucko/circt-darwin
circt: fix darwin linking issues
This commit is contained in:
commit
ff02eca542
@ -1,4 +1,5 @@
|
||||
{ stdenv
|
||||
{ lib
|
||||
, stdenv
|
||||
, cmake
|
||||
, ninja
|
||||
, circt
|
||||
@ -31,6 +32,14 @@
|
||||
|
||||
outputs = [ "out" "lib" "dev" ];
|
||||
|
||||
# Get rid of ${extra_libdir} (which ends up containing a path to circt-llvm.dev
|
||||
# in circt) so that we only have to remove the one fixed rpath.
|
||||
postPatch = lib.optionalString stdenv.isDarwin ''
|
||||
substituteInPlace llvm/llvm/cmake/modules/AddLLVM.cmake \
|
||||
--replace-fail 'set(_install_rpath "@loader_path/../lib''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' \
|
||||
'set(_install_rpath "@loader_path/../lib''${LLVM_LIBDIR_SUFFIX}")'
|
||||
'';
|
||||
|
||||
postInstall = ''
|
||||
# move llvm-config to $dev to resolve a circular dependency
|
||||
moveToOutput "bin/llvm-config*" "$dev"
|
||||
@ -50,6 +59,30 @@
|
||||
--replace "$out/bin/llvm-config" "$dev/bin/llvm-config" # patch path for llvm-config
|
||||
'';
|
||||
|
||||
# Replace all references to @rpath with absolute paths and remove the rpaths.
|
||||
#
|
||||
# This is different from what the regular LLVM package does, which is to make
|
||||
# everything absolute from the start: however, that doesn't work for us because
|
||||
# we have `-DBUILD_SHARED_LIBS=ON`, meaning that many more things are
|
||||
# dynamically rather than statically linked. This includes TableGen, which then
|
||||
# fails to run halfway through the build because it tries to reference $lib when
|
||||
# it hasn't been populated yet.
|
||||
#
|
||||
# Inspired by fixDarwinDylibNames.
|
||||
postFixup = lib.optionalString stdenv.isDarwin ''
|
||||
local flags=(-delete_rpath @loader_path/../lib)
|
||||
for file in "$lib"/lib/*.dylib; do
|
||||
flags+=(-change @rpath/"$(basename "$file")" "$file")
|
||||
done
|
||||
|
||||
for file in "$out"/bin/* "$lib"/lib/*.dylib; do
|
||||
if [ -L "$file" ]; then continue; fi
|
||||
echo "$file: fixing dylib references"
|
||||
# note that -id does nothing on binaries
|
||||
install_name_tool -id "$file" "''${flags[@]}" "$file"
|
||||
done
|
||||
'';
|
||||
|
||||
# circt only use the mlir part of llvm, occasionally there are some unrelated failure from llvm,
|
||||
# disable the llvm check, but keep the circt check enabled.
|
||||
doCheck = false;
|
||||
|
@ -67,6 +67,13 @@ stdenv.mkDerivation rec {
|
||||
|
||||
outputs = [ "out" "lib" "dev" ];
|
||||
|
||||
# Copy circt-llvm's postFixup stage so that it can make all our dylib references
|
||||
# absolute as well.
|
||||
#
|
||||
# We don't need `postPatch` because circt seems to be automatically inheriting
|
||||
# the config somehow, presumably via. `-DMLIR_DIR`.
|
||||
postFixup = circt-llvm.postFixup;
|
||||
|
||||
postInstall = ''
|
||||
moveToOutput lib "$lib"
|
||||
'';
|
||||
|
Loading…
Reference in New Issue
Block a user