Comments (16)
I started digging into this. Here are my current thoughts/observations:
- The
rules_spm
code is definitely not finding the Swift binary correctly. I will work on updating the code to respect the Xcode selection better. - The artifacts from
rules_spm
need to be built with the same Xcode version. Otherwise, compilation errors will occur.
main.swift:1:8: error: module compiled with Swift 5.4.2 cannot be imported by the Swift 5.3.2 compiler: /private/var/tmp/_bazel_chuck/acd478c94e4d22147ca64882e3ea61f8/execroot/simple_example/bazel-out/darwin-fastbuild/bin/external/swift_pkgs/spm_build/x86_64-apple-macosx/release/Logging.swiftmodule
import Logging
- Right now, it seems like
rules_spm
needs to follow the pattern that is laid out in the linked article.
from rules_spm.
OK. I should be able to start looking into adding DEVELOPER_DIR
support later today.
from rules_spm.
What does rules_swift
do to support different Swift versions? I haven't had to do this much myself. I have been trying to align with their conventions.
from rules_spm.
@cgrindel they use xcode_version
: https://www.smileykeith.com/2021/03/08/locking-xcode-in-bazel/
from rules_spm.
Seems they use fragments for obtaining the xcode version: https://github.com/bazelbuild/rules_apple/blob/master/apple/testing/default_runner/macos_test_runner.bzl#L112
But I tried using fragments in a repository rule, and got the following error: Error in repository_rule: repository_rule() got unexpected keyword argument 'fragments'
. Seems like repository rules cant use fragments 😕
from rules_spm.
I think that the solution is going to be:
- Use whatever
swift
is available in the repository rule. We are not building at this point, only fetching and generating descriptions. - Leverage
@build_bazel_rules_swift//tools/worker
in the toolchain rules.
I am still poking around to confirm this.
from rules_spm.
@cgrindel problem comes when:
- The default xcode selected results in swift version < 5.4
- The bazel configures an xcode that is different than the default, and that has swift version >= 5.4
In such case the rules will fail to generate descriptors due to swift version < 5.4
from rules_spm.
Yeah. That is going to be a problem. Right now, the only way I can think to work around that is to make sure that the default Xcode supports SPM at 5.4.0 or above. Once we get rules_spm
working properly, a client can downgrade to a lower version of Swift using the techniques mentioned in Keith's article.
@acecilia Do you think that is reasonable?
from rules_spm.
I currently suffer this issue in other repository rule, and the way I worked around it is by setting up the DEVELOPER_DIR
env variable when running swift. Thus the initial proposal for allowing to customize the env. Not pretty, but works and provides control over the swift version used
from rules_spm.
make sure that the default Xcode supports SPM at 5.4.0 or above
Sometimes this is not that easy. For example, in a farm of CIs: running sudo and having to do it in each one of them quickly becomes a problem. It also alters the state of the machine, which is usually problematic
from rules_spm.
@acecilia: I updated rules_spm
to respect the Xcode selection that you pointed out. Thank you for that. With regard to the original proposal, I have a few questions:
If rules_spm
did have an env
parameter, wouldn't you still need to set the same value for rules_swift
? From what I can tell, it would not be sufficient to just provide DEVELOPER_DIR
to the SPM rules.
With regard to the CI machines having an Xcode version that is less than 5.4, I see two options for how rules_spm
can support this.
- Implement a parser and dependency discovery mechanism in
rules_spm
. This would remove the 5.4 requirement. However, as you can imagine, this would be a pretty big undertaking and be duplicative of the logic that is built into SPM. - Update
spm_repositories
with a parameter likepackage_descriptions
which would allow the client to provide the description JSON. Then,rules_spm
would not need to generate it, which eases the requirement for SPM 5.4 to be available on the CI machine. A client developer could generate the package description JSON and check it into source control. The primary downside is that the client developer would need to keep that package description JSON up-to-date.
What do you think about option 2? Am I understanding the problem that you are trying to solve?
from rules_spm.
If rules_spm did have an env parameter, wouldn't you still need to set the same value for rules_swift?
Yes. Will need to use xcode_version
for rules_swift
and DEVELOPER_DIR
for repository rules. Of course xcode_version
and DEVELOPER_DIR
point to the same xcode. I asked about this in slack and according to the answers this is the only way to select swift/xcode version in repository rules
What do you think about option 2? Am I understanding the problem that you are trying to solve?
The problem is the inability to select the swift version to use when the machine has multiple xcodes installed. I would say allowing to pass a value for DEVELOPER_DIR
is a better option than option 2 explained above
from rules_spm.
OK. I think that I understand a little better. If we added support for DEVELOPER_DIR
to rules_spm
, you would have DEVELOPER_DIR
point to a version of Xcode that supported SPM 5.4 or higher. Is that correct?
from rules_spm.
If we added support for DEVELOPER_DIR to rules_spm, you would have DEVELOPER_DIR point to a version of Xcode that supported SPM 5.4 or higher. Is that correct?
Correct. In this case, I could use DEVELOPER_DIR
to point to any xcode/swift version installed in the machine, despite the value of xcode-select
from rules_spm.
@acecilia PR #80 should auto-merge shortly. Do you mind taking a look at it to confirm that this is what you were requesting? I tried adding you as a reviewer, but it would not let me add you. I'll look into that later.
from rules_spm.
Awesome, thanks 👏 🙌
from rules_spm.
Related Issues (20)
- Depend on package but not its dependencies HOT 3
- Update `rules_spm` to build fetched dependencies using Bazel instead of Swift Package Manager HOT 4
- Ask the community how they would like to move forward with `rules_spm` design/behavior HOT 1
- Write design doc describing path forward
- Unable to add dependency on `Stripe` HOT 7
- SPM packages that include the DocC output in repo fail to build HOT 1
- Update `spm_xcode_toolchain.bzl` to use `DefaultInfo.files_to_run`.
- spm_repositories - doesn't seem to work HOT 5
- spm_swift_binary - use local binary / or how to use local spm files HOT 1
- Undefined symbols for architecture x86_64 when using ios_unit_test HOT 2
- tools/spm_parser fails building with swiftc 5.7 HOT 4
- Error in fail: A clang target must have at least one public header. target: GoogleSignIn HOT 1
- Cannot include package with binary (not executable) library target HOT 1
- Dependency Dashboard
- Error building package in both modes
- Bazel mode regression in `0.11.1` HOT 5
- Enable `incompatible_xcode_` integration tests to run on `macos-12` CI
- Not all outputs were created or valid when building for IOS device HOT 7
- attribute 'srcs' in 'filegroup' rule: invalid target name '_:).json': HOT 2
- Deprecate `rules_spm`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rules_spm.