Skip to content

Swift target (x86_64-pc-linux-gnu) and compiled output (x86_64-unknown-linux-gnu) does not align #311565

Closed

Description

@chuangzhu

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:

When I run swift --version, I get:

<unknown>:0: warning: glibc not found for 'x86_64-pc-linux-gnu'; C stdlib may be unavailable
Swift version 5.8 (swift-5.8-RELEASE)
Target: x86_64-pc-linux-gnu

and when trying to compile my program, get:

<unknown>:0: error: could not find module '_Concurrency' for target 'x86_64-pc-linux

Steps To Reproduce

Steps to reproduce the behavior:

  1. Follow the documentation and run nix-shell -p swift --run 'swiftc -' <<< 'print("Hello world!")'
<unknown>:0: error: could not find module '_Concurrency' for target 'x86_64-pc-linux-gnu'; found: x86_64-unknown-linux-gnu, at: /nix/store/hfbzr5nzd2h90fs7ymbxvk505bcgynsi-swift-5.8-lib/lib/swift/linux/_Concurrency.swiftmodule

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.

[chuang@hawthorn:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.30, NixOS, 24.05 (Uakari), 24.05.20240507.b211b39`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.2`
 - nixpkgs: `/nix/store/f0ssy3p6898x9k880l23mhd0fl6rvrb2-source`

Add a 👍 reaction to issues you find important.

Activity

  1. added
    0.kind: bug
    on May 14, 2024
  2. chuangzhu commented on May 18, 2024

    @chuangzhu
    ContributorAuthor

    Cc @Samasaur1 @annalee @Ma27 @trofi for the recent changes in swiftc

  3. trofi commented on May 20, 2024

    @trofi
    Contributor

    Do you know when it was working last time? We can try to bisect to get the idea what change caused it.

  4. chuangzhu commented on Jun 1, 2024

    @chuangzhu
    ContributorAuthor

    Using swift.stdenv seems to be the trick, as described in #242779 (comment) (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
  5. added
    6.topic: swift
    on Nov 24, 2024
  6. oblique commented on Jan 16, 2025

    @oblique

    If someone came here because this issue in devenv, this this the solution:

      env.LD_LIBRARY_PATH = "${pkgs.swiftPackages.Dispatch}/lib";
      stdenv = pkgs.swift.stdenv;
    
  7. added
    2.status: stale
    on Jul 16, 2025
  8. reckenrode commented on Sep 29, 2026

    @reckenrode
    Contributor

    Fixed by #557896.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bug2.status: stale6.topic: swift

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions