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

rustfmt broken on macOS Darwin with Library not loaded: @rpath/librustc_driver-fd9e092a1dc273d5.dylib #273920

Closed
jfly opened this issue Dec 13, 2023 · 8 comments · Fixed by #274482
Labels
0.kind: bug 6.topic: darwin Running or building packages on Darwin

Comments

@jfly
Copy link
Contributor

jfly commented Dec 13, 2023

Describe the bug

rustfmt is broken on macOS.

Steps To Reproduce

$ nix shell github:NixOS/nixpkgs/120a26f8ce32ac2bdc0e49a9fed830b7446416b4#rustfmt   
$ rustfmt
dyld[5882]: Library not loaded: @rpath/librustc_driver-fd9e092a1dc273d5.dylib
  Referenced from: <774D4B03-B253-3815-924D-F0C9E4D55A23> /nix/store/2kffhdn8xlk1s7zjxgbw5x3447n4dd70-rustfmt-1.74.0/bin/rustfmt
  Reason: tried: '/nix/store/i2q9ff0fpgr20zza6kr6nlpki6mn43if-rustc-wrapper-1.74.0/lib/librustc_driver-fd9e092a1dc273d5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/nix/store/i2q9ff0fpgr20zza6kr6nlpki6mn43if-rustc-wrapper-1.74.0/lib/librustc_driver-fd9e092a1dc273d5.dylib' (no such file), '/nix/store/i2q9ff0fpgr20zza6kr6nlpki6mn43if-rustc-wrapper-1.74.0/lib/librustc_driver-fd9e092a1dc273d5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/nix/store/i2q9ff0fpgr20zza6kr6nlpki6mn43if-rustc-wrapper-1.74.0/lib/librustc_driver-fd9e092a1dc273d5.dylib' (no such file), '/usr/local/lib/librustc_driver-fd9e092a1dc273d5.dylib' (no such file), '/usr/lib/librustc_driver-fd9e092a1dc273d5.dylib' (no such file, not in dyld cache)
zsh: abort      rustfmt

Here's the output of otool if it's helpful:

$ otool -L `which rustfmt`
/nix/store/2kffhdn8xlk1s7zjxgbw5x3447n4dd70-rustfmt-1.74.0/bin/rustfmt:
	@rpath/librustc_driver-fd9e092a1dc273d5.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libstd-03c53b54a0b1f97d.dylib (compatibility version 0.0.0, current version 0.0.0)
	/nix/store/a78xnmg223s3iffja69ydg6sswbwd3i3-libiconv-50/lib/libiconv.dylib (compatibility version 7.0.0, current version 7.0.0)
	/nix/store/z4by244ay1bc3axm8m4816jywfhf2v5w-zlib-1.3/lib/libz.dylib (compatibility version 1.0.0, current version 1.3.0)
	/nix/store/xnvy5pf8v1fa5jac1mxhg21f03n1gk2g-llvm-16.0.6-lib/lib/libLLVM.dylib (compatibility version 1.0.0, current version 16.0.6)
	/nix/store/p5wr7bxrs2naa4rwy9sqs19rljr7g7qh-libcxx-16.0.6/lib/libc++.1.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.60.1)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1770.255.0)

Expected behavior

rustfmt should run without crashing =)

Additional context

This feels like a recurrence of #231078

Notify maintainers

@globin @basvandijk

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"aarch64-darwin"`
 - host os: `Darwin 23.2.0, macOS 14.2`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.18.1`
 - nixpkgs: `/nix/store/vf6skxhiqknlnqcxh8n4z2jldzzpb171-source`
@Samyak2
Copy link
Contributor

Samyak2 commented Dec 13, 2023

WIP bisect log

@eclairevoyant eclairevoyant added the 6.topic: darwin Running or building packages on Darwin label Dec 15, 2023
@jfly
Copy link
Contributor Author

jfly commented Dec 15, 2023

After a very long time spent bisecting, I now know this was introduced by 8b51cdd (@alyssais since you authored this).

Broken in 8b51cdd:

jeremy@Jeremys-MBP nixpkgs % nix run nixpkgs/8b51cdd3bea18e806e3ed63add8e19292dfc84ec#rustfmt -- --version 
dyld[97738]: Library not loaded: @rpath/librustc_driver-fd9e092a1dc273d5.dylib
  Referenced from: <no uuid> /nix/store/imwqzd4864wz7g3jh2r6ghqggvrsc0mf-rustfmt-1.74.0/bin/rustfmt
  Reason: tried: '/nix/store/d16gx9vprzhrdqpabx7mjr2q5nma8ylg-rustc-wrapper-1.74.0/lib/librustc_driver-fd9e092a1dc273d5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/nix/store/d16gx9vprzhrdqpabx7mjr2q5nma8ylg-rustc-wrapper-1.74.0/lib/librustc_driver-fd9e092a1dc273d5.dylib' (no such file), '/nix/store/d16gx9vprzhrdqpabx7mjr2q5nma8ylg-rustc-wrapper-1.74.0/lib/librustc_driver-fd9e092a1dc273d5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/nix/store/d16gx9vprzhrdqpabx7mjr2q5nma8ylg-rustc-wrapper-1.74.0/lib/librustc_driver-fd9e092a1dc273d5.dylib' (no such file), '/usr/local/lib/librustc_driver-fd9e092a1dc273d5.dylib' (no such file), '/usr/lib/librustc_driver-fd9e092a1dc273d5.dylib' (no such file, not in dyld cache)
zsh: abort      nix run nixpkgs/8b51cdd3bea18e806e3ed63add8e19292dfc84ec#rustfmt -- --version

Working in c6f3c04 (the parent of 8b51cdd):

jeremy@Jeremys-MBP nixpkgs % nix run nixpkgs/c6f3c0403fd012327b69b6cd475aeee7c6ae9592#rustfmt -- --version
rustfmt 1.6.0-

@alyssais
Copy link
Member

Ah I see, it's trying to load librustc_driver from the wrapper's lib directory, where it doesn't exist. I wonder how rustfmt decides where to load that from. Can we change that, or does the wrapper need to pass through lib?

@alyssais
Copy link
Member

On Linux it links correctly:

librustc_driver-176f96622de184df.so => /nix/store/792bs5larfnxcrhwy8cqkgky6n72grsf-rustc-1.74.0/lib/rustlib/aarch64-unknown-linux-gnu/lib/librustc_driver-176f96622de184df.so (0x0000fffee6560000)

So this needs some investigation from somebody on Darwin to determine what's different about linking there, and how it ends up using the wrong path.

@Samyak2
Copy link
Contributor

Samyak2 commented Dec 15, 2023

I suspect it might be because of these darwin specific prefixup commands:

preFixup = lib.optionalString stdenv.isDarwin ''
install_name_tool -add_rpath "${rustc}/lib" "$out/bin/rustfmt"
install_name_tool -add_rpath "${rustc}/lib" "$out/bin/git-rustfmt"
'';

Changing rustc to rustc-unwrapped might work? I'll try that out.

@alyssais
Copy link
Member

Ah yes, that looks likely! Probably better to use rustc.unwrapped over rustc-unwrapped so overriding stays easy.

@alyssais
Copy link
Member

clippy likely needs a similar fix

@Samyak2
Copy link
Contributor

Samyak2 commented Dec 15, 2023

Yes, clippy wasn't working either.

Opened a PR to fix both: #274482

Thank you for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug 6.topic: darwin Running or building packages on Darwin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants