Skip to content

Add a fallback extension none os dylibs #8022

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

Merged
merged 2 commits into from
Oct 4, 2024
Merged

Add a fallback extension none os dylibs #8022

merged 2 commits into from
Oct 4, 2024

Conversation

rauhul
Copy link
Member

@rauhul rauhul commented 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

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
Copy link
Member Author

rauhul commented Oct 3, 2024

@swift-ci test

fatalError("Cannot create dynamic libraries for os \"\(os)\".")
// Fallback to a nonsense extension for operating systems with
// unknown conventions.
return ".dynamiclibrary"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this is preferred over .so?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like the idea of the extension for "macho" being "so". I think that would be kinda surprising to the user.

I was considering this default branch determining the extension based on the object file format instead, thought?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the behavior if building on a non-macho platform like Linux? Would this still work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code path is only used to plan the build of a dynamic library product for an os none triple. Actually doing this build is nonsensical because the dynamic library would require a specific dynamic loader provided by the OS and by definition, os none does not have a dynamic loader.

One alternative option is to use the object format e.g.:

switch os {
case _ where isDarwin():
    return ".dylib"
case .linux, .openbsd:
    return ".so"
case .win32:
    return ".dll"
case .wasi:
    return ".wasm"
default:
  break
}

guard let objectFormat = self.objectFormat else {
    fatalError("Cannot create dynamic libraries unknown object format.")
}

switch objectFormat {
case .coff:
    return ".coff"
case .elf:
    return ".elf"
case .macho:
    return ".macho"
case .wasm:
    return ".wasm"
case .xcoff:
    return ".xcoff"
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this basically just spoofs the "dynamic library" on a none OS but doesn't actually generate anything? That's kind of weird. But if that's the case then I guess it's just arbitrary what you pick there.

Copy link
Member Author

@rauhul rauhul Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah its not a great thing to do, but fixing the underlying issue with build planning is something the swift pm team is working on

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I'm okay with this if it fixes the none OS issue and if it doesn't break anything!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think doing this based on object format looks better.

@rauhul
Copy link
Member Author

rauhul commented Oct 4, 2024

@swift-ci test

@rauhul rauhul enabled auto-merge (squash) October 4, 2024 17:15
@MaxDesiatov
Copy link
Contributor

@swift-ci test windows

@rauhul rauhul merged commit 23fa281 into main Oct 4, 2024
5 checks passed
@rauhul rauhul deleted the fix-7893 branch October 4, 2024 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot cross compile when package contains dylib product
4 participants