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
oracle-instantclient: fixes dylib rpath on macos #45157
oracle-instantclient: fixes dylib rpath on macos #45157
Conversation
install -Dm755 {sqlplus,adrci,genezi} $out/bin | ||
${optionalString stdenv.isDarwin '' | ||
for exe in "$out/bin/"* ; do | ||
install_name_tool -add_rpath "$out/lib" "$exe" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain a bit what's going on here, we generally don't use RPATHs on darwin and the combination of this with fixDarwinDylibNames
seems odd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The oracle instantclient binary zip sources are packaged as a flat structure and contain an RPATH relative to the executable (e.g. sqlplus, etc), so the embedded load commands don't find the associated libs when installed in the nix store under ./bin, ./lib tree structure. For example listing the sqlplus
binary in the instantclient-sqlplus-macos.x64-12.2.0.1.0-2.zip
source gives this:
$ otool -l sqlplus
Load command 12
cmd LC_LOAD_DYLIB
cmdsize 48
name @rpath/libsqlplus.dylib (offset 24)
time stamp 2 Wed Dec 31 17:00:02 1969
current version 0.0.0
compatibility version 0.0.0
Load command 13
cmd LC_LOAD_DYLIB
cmdsize 56
name @rpath/libclntsh.dylib.12.1 (offset 24)
time stamp 2 Wed Dec 31 17:00:02 1969
current version 0.0.0
compatibility version 0.0.0
Load command 14
cmd LC_LOAD_DYLIB
cmdsize 56
name @rpath/libclntshcore.dylib.12.1 (offset 24)
time stamp 2 Wed Dec 31 17:00:02 1969
current version 0.0.0
compatibility version 0.0.0
Load command 15
cmd LC_LOAD_DYLIB
cmdsize 48
name @rpath/libnnz12.dylib (offset 24)
time stamp 2 Wed Dec 31 17:00:02 1969
current version 0.0.0
compatibility version 0.0.0
Load command 18
cmd LC_RPATH
cmdsize 32
path @executable_path/ (offset 12)
I would have thought fixDarwinDylibNames
would work on executables similar to how autoPatchelfHook
works, but digging into the source reveals that function only works on *.dylib
files. Adding the call to install_name_tool
was the only way I could get the sqlplus
and other executables to run without having to mess around with setting the LD_LIBRARY_PATH or DYLD_LIBRARY_PATH in the environment. I am definitely a nix newb, so I'm not sure if there is a different function than fixDarwinDylibNames
that works like autoPatchelfHook
. I couldn't find anything in the standard nixpkgs setup-hooks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine adding $out/lib
to the rpath of all binaries - we do similar things in other places in Nixpkgs as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikemckibben I see, changing the LC_LOAD_DYLIB to use absolute paths instead would be nicer IMHO but this works. fixDarwinDylibNames
does indeed only handle dylibs and since this isn't built from source we can't fix the rpath referrences before the binaries are linked against the libraries, that would have made this unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR!
I didn't catch the binaries being broken on darwin, (as I was mostly only using his package via the odpic libraries)
install -Dm755 {sqlplus,adrci,genezi} $out/bin | ||
${optionalString stdenv.isDarwin '' | ||
for exe in "$out/bin/"* ; do | ||
install_name_tool -add_rpath "$out/lib" "$exe" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine adding $out/lib
to the rpath of all binaries - we do similar things in other places in Nixpkgs as well.
nativeBuildInputs = [ autoPatchelfHook makeWrapper unzip ]; | ||
++ optionals (stdenv.isLinux) [ libaio ] | ||
++ optional odbcSupport unixODBC; | ||
nativeBuildInputs = [ autoPatchelfHook makeWrapper unzip ] ++ optional stdenv.isDarwin fixDarwinDylibNames; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need fixDarwinDylibNames
- install_name_tool
should be available without it too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not correct this is a setup-hook. It's necessary for anything that links against these libraries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LnL7 it already worked, as it's (only?) consumer, odpic, loads it via dlopen and we add rpaths in postFixup - but no reason not to set the install names absolute :-)
ln -s $out/lib/libclntsh.so.12.1 $out/lib/libclntsh.so | ||
if [ \! -e "$out/lib/libclntsh${extLib}" ]; then | ||
ln -s $out/lib/libclntsh${extLib}.12.1 $out/lib/libclntsh${extLib} | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libclntsh${extLib}.12.1
should be available on linux as well, no need to check for existence here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, I'll remove the test. I must have had a weird store state locally, as during testing I ran into a link already exists error.
Ok, this should be good to go. Let me know if you see anything else or want me to squash the commits. Thanks! |
@@ -61,9 +63,7 @@ in stdenv.mkDerivation rec { | |||
install -Dm644 sdk/demo/* $out/share/${name}/demo | |||
|
|||
# PECL::oci8 will not build without this | |||
if [ \! -e "$out/lib/libclntsh${extLib}" ]; then | |||
ln -s $out/lib/libclntsh${extLib}.12.1 $out/lib/libclntsh${extLib} | |||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uff, the symlink already seems to exist in the darwin zipfile, but not in the linux one, so the build on darwin would now fail.
We indeed need to check for existence, sorry for the confusion. Could you add these back in, plus a comment above that this symlink only exists in zipfiles for some platforms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about just overwriting it with ln -sfn
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me too
@@ -42,7 +42,9 @@ in stdenv.mkDerivation rec { | |||
buildInputs = [ stdenv.cc.cc.lib ] | |||
++ optionals (stdenv.isLinux) [ libaio ] | |||
++ optional odbcSupport unixODBC; | |||
nativeBuildInputs = [ autoPatchelfHook makeWrapper unzip ] ++ optional stdenv.isDarwin fixDarwinDylibNames; | |||
|
|||
nativeBuildInputs = [ autoPatchelfHook makeWrapper unzip ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cosmetics: We can put the autoPatchelfHook
into a optional stdenv.isLinux
too.
Some more comments, thanks for the work so far! |
ok, added changes from latest comments and squashed the commits. Should be good. |
LGTM, verified |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Motivation for this change
Libraries and applications linked against the oracle-instantclient package on MacOS fail with the following error due to rpath not being patched:
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)@pesterhazy @flokli