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

Cannot cross compile when package contains dylib product #7893

Closed
1 task done
rauhul opened this issue Aug 19, 2024 · 6 comments · Fixed by #8022
Closed
1 task done

Cannot cross compile when package contains dylib product #7893

rauhul opened this issue Aug 19, 2024 · 6 comments · Fixed by #8022

Comments

@rauhul
Copy link
Member

rauhul commented Aug 19, 2024

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

  • Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands, swift build, swift test, swift package etc.

Description

swift-mmio contains a dynamic library product called SVD2LLDB. When trying to build a project that only uses the MMIO product of swift-mmio for armv7em-apple-none-macho I hit the following assertion:

Basics/Triple+Basics.swift:149: Fatal error: Cannot create dynamic libraries for os "noneOS".

Expected behavior

No response

Actual behavior

No response

Steps to reproduce

No response

Swift Package Manager version/commit hash

No response

Swift & OS version (output of swift --version ; uname -a)

No response

rauhul added a commit to apple/swift-mmio that referenced this issue Aug 19, 2024
See:
swiftlang/swift-package-manager#7893
Cannot cross compile when package contains dylib product
rauhul added a commit to apple/swift-mmio that referenced this issue Aug 19, 2024
See:
swiftlang/swift-package-manager#7893
Cannot cross compile when package contains dylib product
rauhul added a commit to apple/swift-mmio that referenced this issue Aug 19, 2024
See:
swiftlang/swift-package-manager#7893
Cannot cross compile when package contains dylib product
@rauhul
Copy link
Member Author

rauhul commented Aug 19, 2024

So the current logic triggering this assertion is:

    /// The file extension for dynamic libraries (eg. `.dll`, `.so`, or `.dylib`)
    public var dynamicLibraryExtension: String {
        guard let os = self.os else {
            fatalError("Cannot create dynamic libraries unknown os.")
        }

        switch os {
        case _ where isDarwin():
            return ".dylib"
        case .linux, .openbsd:
            return ".so"
        case .win32:
            return ".dll"
        case .wasi:
            return ".wasm"
        default:
            fatalError("Cannot create dynamic libraries for os \"\(os)\".")
        }
    }

I wonder if this is actually switching on the wrong thing. Should the dylib extension be derived from the object file format?

@compnerd do you have thoughts here or any insight about how this works in cmake land?

@dschaefer2 dschaefer2 self-assigned this Aug 19, 2024
@dschaefer2
Copy link
Member

Is the issue that we're building the entire swift-mmio package for that triple and not just the required product dependencies?

@compnerd
Copy link
Member

@rauhul I think that is a totally fair assertion failure. I think that in the default case, we should switch on the file format. i.e. aarch64-unknown-none-elf should use .so even though the OS is none, aarch64-unknown-none-macho should likely use .dylib.

@rauhul
Copy link
Member Author

rauhul commented Aug 19, 2024

@dschaefer2 I don't think SVD2LLDB is even getting built, the build system is trying to plan the build and failing to determine a file path for where SVD2LLDB dylib would be if it were to be used.

@rauhul
Copy link
Member Author

rauhul commented Aug 19, 2024

@rauhul I think that is a totally fair assertion failure. I think that in the default case, we should switch on the file format. i.e. aarch64-unknown-none-elf should use .so even though the OS is none, aarch64-unknown-none-macho should likely use .dylib.

Well yeah, I do agree making a dylib for OS none is a bit nonsensical because there's no defined loader for such a platform, but I guess my question is: if you're building for <arch>-unknown-linux-coff what dynamic library extension should you expect?

@compnerd
Copy link
Member

@rauhul well, I can build a system that has a PE kernel built with MachO object files (this is not a facetious example). The environment could be loading a DLL and have a PE loader even though the target for compilation would be ...-unknown-none-macho.

rauhul added a commit to apple/swift-mmio that referenced this issue Aug 23, 2024
See:
swiftlang/swift-package-manager#7893
Cannot cross compile when package contains dylib product
rauhul added a commit that referenced this issue Oct 3, 2024
Adds a fake extension for none os dynamic libraries to avoid a SwiftPM
crash during build planning when cross compiling to none OS with a dylib
product in the graph.

Fixes #7893
rauhul added a commit that referenced this issue Oct 4, 2024
Adds an extension for none os dynamic libraries to avoid a SwiftPM crash
during build planning when cross compiling to none OS with a dylib
product in the graph.

Fixes #7893
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants