Repository navigation
Closed
Closed
Copy link
Labels
0.kind: bugSomething is broken2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md6.topic: swiftProgramming language (swift.org)
Description
Describe the bug
I'm trying swift on NixOS for the first time but I get a linker error. I imagine it's reported elsewhere, but I didn't find this specific error searching open issues or the discourse, so I thought I'd post.
I know swift is mostly MacOS focused, but should this be expected to work?
Steps To Reproduce
$ nix shell github:nixos/nixpkgs#swift -c bash -c "echo 'print(\"hello from swift\")' > hello.swift; swiftc hello.swift"
[0/1 built, 1/56/58 copied (2350.9/2640.2 MiB), 444.1/494.1 MiB DL] fetching swift-5.8 from http
error: link command failed with exit code 1 (use -v to see invocation)
/nix/store/zkjq96ik8cbv6ijh1lylnkk2bni9qvas-binutils-2.40/bin/ld.gold: error: cannot open Scrt1.o: No such file or directory
/nix/store/zkjq96ik8cbv6ijh1lylnkk2bni9qvas-binutils-2.40/bin/ld.gold: error: cannot open crti.o: No such file or directory
/nix/store/zkjq96ik8cbv6ijh1lylnkk2bni9qvas-binutils-2.40/bin/ld.gold: error: cannot open crtbeginS.o: No such file or directory
/nix/store/zkjq96ik8cbv6ijh1lylnkk2bni9qvas-binutils-2.40/bin/ld.gold: error: cannot open crtendS.o: No such file or directory
/nix/store/zkjq96ik8cbv6ijh1lylnkk2bni9qvas-binutils-2.40/bin/ld.gold: error: cannot open crtn.o: No such file or directory
/nix/store/w10qql6406k4g3rbpp8m9nziwsqqh1pv-swift-5.8-lib/lib/swift/linux/x86_64/swiftrt.o:function swift_image_constructor(): error: undefined reference to '__dso_handle'
Expected behavior
I think the above should compile without errors.
Additional context
I tried adding a few different linkers to my nix shell, using nix-locate to find some packages containing the above files (like crtendS.o) and including them in my nix shell, no luck.
I see few posts about swift on NixOS on the discourse, so I suspect it may just not be common to use on non-Darwin?
Notify maintainers
@dtzWill @trepetti @dduan @Trundle @stephank
Metadata
Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.
[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
- system: `"x86_64-linux"`
- host os: `Linux 6.1.36, NixOS, 23.05 (Stoat), 23.05.20230709.8df7a67`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.13.3`
- channels(root): `""`
- channels(n8henrie): `""`
- nixpkgs: `/nix/store/qwg77kl125qzjzv9lklfcv48x9jhb0hz-source`Reacted by Spotlight, Suraj, Chuang Zhu, Zuruh, Cathal, mochie and Johannes
Reacted by Suraj
Metadata
Metadata
Assignees
Labels
0.kind: bugSomething is broken2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md6.topic: swiftProgramming language (swift.org)
Activity
nrhtr commentedon Jul 12, 2023
That command also fails for me with a slightly different error (probably because I'm on aarch64-darwin), but this command works:
n8henrie commentedon Jul 12, 2023
@nrhtr does it still work with
--pureor is there a chance something on Darwin is polluting your env?nrhtr commentedon Jul 12, 2023
It does, but I think you're right that something is polluting my env, regardless:
I tested on my NixOS machine and get the same error as you. It looks like the linker is only searching $CWD for those glibc dependencies, but I don't understand why. Out of curiosity, I managed to symlink things in and compile a binary but it had an unresolvable reference to libdispatch.so (not using a nix store path).
Trundle commentedon Jul 12, 2023
The swift package relies on setup hooks and
nix shell github:nixos/nixpkgs#swiftdoesn't execute setup hooks, in contrast tonix-shelln8henrie commentedon Jul 12, 2023
@nrhtr @Trundle the
nix-shellcommand from above fails for me with the same error:bitmappergit commentedon Sep 14, 2023
This is also a problem for me, with the same errors as above on both nixpkgs master and release-23.05. Regardless of if I use flakes or nix-shell.
donn commentedon Sep 16, 2023
Problem persists when attempting to compile:
"x86_64-linux"Linux 6.1.52, NixOS, 23.05 (Stoat), 23.05.3427.e5f018cf150eyesyesnix-env (Nix) 2.13.5"nixos-23.05, nixos-unstable"""/nix/var/nix/profiles/per-user/root/channels/nixosThis hack at least allows compilation to proceed:
Unfortunately, there's immediately another problem; as mentioned by @nrhtr, binaries compiled by
swiftcare linked againstlibdispatch.sowithout a/nix/storepath:This can be worked around with an
LD_LIBRARY_PATHexport/patchelfin a derivation, but then, when attempting to run a file in interpreter mode, this happens:Curiously, the REPL and
-eboth work fine:donn commentedon Sep 16, 2023
I can also confirm that using the
swiftderivation in 0218941, everything works as expected. It's 5.6 but what are ya gonna do.stephank commentedon Sep 24, 2023
Apologies for not responding here sooner.
Swift requires a Clang stdenv. That's the default on Darwin (hence why the command works), but not on Linux. I don't know how you'd select a different stdenv using
nix shellornix-shell.Maybe we can guard against non-clang stdenv in our wrapper, but I haven't tried.
These
/usr/lib/references are normal (and required) on macOS, they're part of ABI stability. They're like system frameworks in that regard. (Trying to link your ownlibswiftCoreresults in warnings about duplicate ObjC class definitions and then crashes.)That's strange. I used your
shell.nixsnippet, but added Foundation like so:Then did the following:
Looks okay, I think?
n8henrie commentedon Sep 25, 2023
Interestingly I can run this just fine:
but I get the error with:
Using the topmost example straight from the manual doesn't even compile (at least on x86 NixOS):
@donn is correct, changing nothing but the nixpkgs version:
Will try running a bisect.
n8henrie commentedon Sep 25, 2023
Hmm, using
swiftinstead ofswiftcgets somewhere:and I can confirm that including using
Foundationand overridingstdenvalso gets me a working nix develop environment (without the above error).The nix-shell version:
So I guess this can be closed? I mean it would be nice to be able to
nix shell nixpkgs#swiftand be off to the races, but this isn't too bad.n8henrie commentedon Sep 29, 2023
Ran out of disk space and crashed 😆 Guess I should turn off zfs-auto-snapshot for that directory.
Mathnerd314 commentedon Oct 12, 2023
I think it is a bit premature to close this without at least documenting the proper command in the manual. The manual currently says that just running swiftc should work.
Mathnerd314 commentedon Oct 12, 2023
Also when I try to run swift or swiftc on my (recent NixOS-unstable) system, with the nix-shell command in #242779 (comment), I get an illegal instruction. I don't get that with the old 0218941 commit.
ink-splatters commentedon Dec 4, 2023
Just in case it helps anyone:
Given the latest nixpkgs-unstable on the date:
I'm having success building rather "demanding" https://github.com/jesse-c/AppearanceNotifier
which requires among other things,
swift packageto work:1. using
nix-shell( corrected: it was initially stated
nix shellbut that was wrong as it evaluates flakepackageattributes, being not related to development shells (AFAIK). In fact, this part has how become redundant, as it effectively matches other people's solutions from this thread)II. using flakes' development shell (
nix develop)copied code from NixOS/nixpkgs#242779 (comment)
nixos-discourse commentedon Dec 6, 2023
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/devenv-nixpkgs-mkshell-override-alternative/36533/1