-
Notifications
You must be signed in to change notification settings - Fork 32
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
feat: Add a mechanism to set additional attributes on generated swift libraries. #1222
Comments
Ideally we wouldn't need to customize this and we can get all the information about if we need this or not from the information that SPM provides? If SPM is able to compile this with that info, we should be able to as well. |
@brentleyjones How do you think we should determine when we need to apply the alwayslink = True flag? These deps work as expected on linux when building with SPM but they fail at runtime with Bazel. |
Does SPM always link as well, e.g. when doing something like |
@luispadron I did not see any specific configuration for the module, but it's possible this is a default behavior in https://github.com/apple/swift-atomics/blob/main/Package.swift A swift_binary built from this package with Bazel crashed on Ubuntu but the same executable built with SPM worked. Keith suggested the alwayslink flag and that fixed it, which is why I added that to swift atomics in rules swift. I traced it back to the ManagedAtomic type and an extension in another file adding a conformance to a protocol. It's possible that Apple configures the linker differently than bazel when running swift build. |
This feels like we need to adjust our default behavior to mimic what SPM does. |
@brentleyjones @cgrindel this is the minimal example project I created to reproduce the issue with Bazel and show that it works with SPM: https://github.com/AttilaTheFun/swift_atomics_test I used a Ubuntu VM that matched the version used by RSPM / rules_swift CI. These are the instructions I wrote for myself to install the VM and install Bazel and Swift on it too: Installing a Multipass Ubuntu VM with Bazel and SwiftInstall Ubuntu VM with MultipassInstall multipass:
Check that it was successful:
List the available VMs:
Install a Ubuntu 20.04 (aka focal) with the default config:
If you want a different config:
To ssh into the running machine:
To start the VM:
To copy files to / from the VM:
Install BazeliskChange directory into the user binaries directory:
Download the bazelisk binary to this directory:
Change this URL for a newer bazelisk. Rename the binary file:
Make it executable:
Check that it was installed correctly:
Install swiftInstructions from: https://www.swift.org/install/linux/ Change into the home directory:
Update the package registry:
Install the package dependencies:
Download the tar file:
Uncompressed the tar file:
Delete the tar file:
Add the swift binaries to the PATH:
Verify Swift was installed successfully:
Use clang instead of gcc:
|
Based on bazelbuild/rules_swift@2cc542a, we should probably unconditionally set it?
|
Yeah @brentleyjones I'd be in favor of matching the SPM behavior in swift_library. Then this wouldn't be necessary. It could be gated behind a config if this is considered a breaking change. |
Since we are pre-1.0, I think we should just make the change. |
In order to merge my example using grpc-swift from RSPM I need to be able to add the alwayslink = True tag to the generated build file for SwiftAtomics. The tests will crash on Ubuntu if this is unset.
If we have a tag class to customize attributes for packages in MODULE.bazel, that would allow me to fix this issue.
From this thread: #1214
The text was updated successfully, but these errors were encountered: