Open chuangzhu opened 1 month ago
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
Cc @Samasaur1 @annalee @Ma27 @trofi for the recent changes in swiftc
Do you know when it was working last time? We can try to bisect to get the idea what change caused it.
Using swift.stdenv
seems to be the trick, as described in https://github.com/NixOS/nixpkgs/issues/242779#issuecomment-1734561750 (although he missed the c
in swiftc
):
nix-shell -E "with import <nixpkgs> {}; pkgs.mkShell.override { inherit (pkgs.swift) stdenv; } { buildInputs = [ swift swiftPackages.Foundation ]; }" --run "swiftc -" <<< 'import Foundation; print("hello")'
The libdispatch.so
problem can also be worked around by adding ${swiftPackages.Dispatch}/lib
to LD_LIBRARY_PATH
, because sometimes it is not trivial to add import Foundation
to every Swift file:
$ nix-shell -E 'with import <nixpkgs> {}; pkgs.mkShell.override { inherit (pkgs.swift) stdenv; } { buildInputs = [ swift swiftpm ]; LD_LIBRARY_PATH = "${swiftPackages.Dispatch}/lib"; }'
$ swiftc - <<< 'print("Hello")'
$ ./main
Hello
Describe the bug
Reposted from https://discourse.nixos.org/t/swift-target-x86-64-pc-linux-gnu-and-compiled-output-x86-64-unknown-linux-gnu-does-not-align/39393:
Steps To Reproduce
Steps to reproduce the behavior:
nix-shell -p swift --run 'swiftc -' <<< 'print("Hello world!")'
Expected behavior
Swift builds an executable
./main
, which, when run, prints "Hello world!".Additional context
Adding swift to
enviroment.systemPackages
in NixOS configuration seems to be a workaround.Notify maintainers
@dtzWill @trepetti @dduan @trundle @stephank
Metadata
Please run
nix-shell -p nix-info --run "nix-info -m"
and paste the result.Add a :+1: reaction to issues you find important.