Skip to content

Building Swift fails on linux with module redefinition errors #62429

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

Closed
keith opened this issue Dec 7, 2022 · 8 comments
Closed

Building Swift fails on linux with module redefinition errors #62429

keith opened this issue Dec 7, 2022 · 8 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. Linux Platform: Linux

Comments

@keith
Copy link
Member

keith commented Dec 7, 2022

When building the Swift compiler on Linux with:

LDFLAGS="-Xlinker -z -Xlinker nostart-stop-gc" CC=/usr/bin/clang CXX=/usr/bin/clang++ ./swift/utils/build-script --release-debuginfo --sccache --llvm-max-parallel-lto-link-jobs 1 --llvm-cmake-options='-DLLVM_ENABLE_LLD=' --extra-cmake-options="-DSWIFT_USE_LINKER= -DLLVM_USE_LINKER=/home/ksmiley/.bin/ld.lld" --reconfigure --bootstrapping off

While also having swiftc 5.7.1 in my $PATH, I end up getting these build failures:

/opt/swift/swift-5.7.1/usr/lib/swift/dispatch/module.modulemap:8:8: error: redefinition of module 'DispatchIntrospection'
module DispatchIntrospection [system] [extern_c] {
       ^
/home/ksmiley/dev/oss-swift/swift-corelibs-libdispatch/dispatch/module.modulemap:8:8: note: previously defined here
module DispatchIntrospection [system] [extern_c] {
       ^
/opt/swift/swift-5.7.1/usr/lib/swift/dispatch/module.modulemap:13:8: error: redefinition of module 'CDispatch'
module CDispatch [system] [extern_c] {
       ^
/home/ksmiley/dev/oss-swift/swift-corelibs-libdispatch/dispatch/module.modulemap:13:8: note: previously defined here
module CDispatch [system] [extern_c] {
       ^
ninja: build stopped: subcommand failed.

Dispatch seems to be the first module that fails, but there are many errors with the same issue. Eventually I also see:

/home/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/lib/swift/host/SwiftDiagnostics.swiftmodule/x86_64-unknown-linux-gnu.private.swiftinterface:5:8: error: failed to build module 'SwiftSyntax' for importation due to the errors above; the textual interface may be broken by project issues or a compiler bug
import SwiftSyntax
       ^
/home/ksmiley/dev/oss-swift/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/lib/swift/host/SwiftParser.swiftmodule/x86_64-unknown-linux-gnu.private.swiftinterface:5:8: error: failed to build module 'SwiftDiagnostics' for importation due to the errors above; the textual interface may be broken by project issues or a compiler bug
import SwiftDiagnostics
       ^
/opt/swift/swift-5.7.1/usr/lib/swift/dispatch/module.modulemap:1:8: error: redefinition of module 'Dispatch'
module Dispatch {
       ^
/home/ksmiley/dev/oss-swift/swift-corelibs-libdispatch/dispatch/module.modulemap:1:8: note: previously defined here
module Dispatch {
       ^

But I believe the message is correct that the issue is the other duplicate modules.

My impression was that building with an existing Swift compiler installation was expected (or maybe even required), but I am attempting to build without these in my $PATH assuming that if it still works that way it won't be able to find these modulemaps, so maybe I'll side step this.

Steps to reproduce

  • Checkout 5b9aef9 and friends
  • Build with the command above

Environment

  • Swift 5.7.1 release
  • Ubuntu 20.04
@keith keith added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Dec 7, 2022
@keith
Copy link
Member Author

keith commented Dec 7, 2022

might have been fixed by passing -skip-early-swift-driver --skip-early-swiftsyntax from the docs (must have changed since my last build ~a month ago since I just re-ran my previous command)

@finagolfin
Copy link
Member

I've seen this on Android too, with the prebuilt Swift toolchain package colliding with a trunk toolchain I'm building. The Linux CI doesn't have a prebuilt Swift toolchain, so it doesn't build those early Swift tools, but we'll need to fix this for when building the Swift compiler with a prebuilt Swift compiler becomes mandatory, so keep this open.

@redsun82
Copy link
Contributor

redsun82 commented Apr 5, 2023

I am just encountering this since the update to swift 5.8. Unfortunately I do require bootstrapping. Any workaround for this?

@finagolfin
Copy link
Member

This has nothing to do with bootstrapping: it should work if you don't have a prebuilt toolchain in your path, as the linux CI doesn't, or if you pass the two build flags Keith mentioned.

@kateinoigakukun
Copy link
Member

Just for record, dispatch/module.modulemap is no longer placed under source directory of swift-corelibs-libdispatch after swiftlang/swift-corelibs-libdispatch#785, so I just needed to clean the source directory by git clean -f to repair the build failure.

@finagolfin
Copy link
Member

@keith, still seeing this or can we close? I haven't seen this in a while, and the linux CI builds with a prebuilt Swift 5.8 toolchain now.

@keith
Copy link
Member Author

keith commented Nov 11, 2023

not sure

@hborla hborla added Linux Platform: Linux and removed triage needed This issue needs more specific labels labels Jul 14, 2024
@finagolfin
Copy link
Member

The libdispatch pull Yuta linked should've fixed this, reopen if not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. Linux Platform: Linux
Projects
None yet
Development

No branches or pull requests

5 participants