-
-
Notifications
You must be signed in to change notification settings - Fork 662
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
Bazel 0.26 break iOS and perhaps Android cross compilation #2079
Comments
Actually, I'm not sure how we can tell bazel how to use multiple toolchains |
Adding
|
As you said, the problem seems to be that the
Go considers |
@steeve Could you try applying the patch below? I apparently don't have a C/C++ toolchain installed for iOS, so I'm not able to test this. It's probably not complete, but it's a start.
|
That's even more twisted than that: Also, bazel defines both archs as being "ios_armv7": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:arm"],
"ios_arm64": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:arm"], That would mean Thank you for the diff! I'll try that and so how I can go from that approach. |
I think it would be fine to define
Seems like a bug. Maybe that's why I couldn't get it to work yesterday? Can you reproduce that just with |
I've opened bazelbuild/bazel#8520 just in case I'm not sure what you want me to reproduce though? |
I agree that's the way to go. Actually I find it rather nicer than how Go itself does it to be honest. |
So far I have this diff --git a/go/platform/list.bzl b/go/platform/list.bzl
index ec6ec797..a0dad29e 100644
--- a/go/platform/list.bzl
+++ b/go/platform/list.bzl
@@ -13,8 +13,9 @@
# limitations under the License.
GOOS = {
- "android": None,
+ "android": "@bazel_tools//platforms:android",
"darwin": "@bazel_tools//platforms:osx",
+ "ios": "@bazel_tools//platforms:ios",
"dragonfly": None,
"freebsd": "@bazel_tools//platforms:freebsd",
"linux": "@bazel_tools//platforms:linux",
@@ -52,6 +53,10 @@ GOOS_GOARCH = (
("darwin", "amd64"),
("darwin", "arm"),
("darwin", "arm64"),
+ ("ios", "386"),
+ ("ios", "amd64"),
+ ("ios", "arm"),
+ ("ios", "arm64"),
("dragonfly", "amd64"),
("freebsd", "386"),
("freebsd", "amd64"), Where would you like to see the |
So this works, save for the diff --git a/go/platform/list.bzl b/go/platform/list.bzl
index ec6ec797..a0dad29e 100644
--- a/go/platform/list.bzl
+++ b/go/platform/list.bzl
@@ -13,8 +13,9 @@
# limitations under the License.
GOOS = {
- "android": None,
+ "android": "@bazel_tools//platforms:android",
"darwin": "@bazel_tools//platforms:osx",
+ "ios": "@bazel_tools//platforms:ios",
"dragonfly": None,
"freebsd": "@bazel_tools//platforms:freebsd",
"linux": "@bazel_tools//platforms:linux",
@@ -52,6 +53,10 @@ GOOS_GOARCH = (
("darwin", "amd64"),
("darwin", "arm"),
("darwin", "arm64"),
+ ("ios", "386"),
+ ("ios", "amd64"),
+ ("ios", "arm"),
+ ("ios", "arm64"),
("dragonfly", "amd64"),
("freebsd", "386"),
("freebsd", "amd64"),
diff --git a/go/private/go_toolchain.bzl b/go/private/go_toolchain.bzl
index 9e98fde8..ee4e7933 100644
--- a/go/private/go_toolchain.bzl
+++ b/go/private/go_toolchain.bzl
@@ -31,12 +31,15 @@ load("@io_bazel_rules_go//go/private:actions/stdlib.bzl", "emit_stdlib")
def _go_toolchain_impl(ctx):
sdk = ctx.attr.sdk[GoSDK]
- cross_compile = ctx.attr.goos != sdk.goos or ctx.attr.goarch != sdk.goarch
+ goos = ctx.attr.goos
+ if goos == "ios":
+ goos = "darwin"
+ cross_compile = goos != sdk.goos or ctx.attr.goarch != sdk.goarch
return [platform_common.ToolchainInfo(
# Public fields
name = ctx.label.name,
cross_compile = cross_compile,
- default_goos = ctx.attr.goos,
+ default_goos = goos,
default_goarch = ctx.attr.goarch,
actions = struct(
archive = emit_archive, I tried to push the luck into having the |
Also, |
I've started to work on a fix for this. Currently, we have a GOOS_GOARCH table of valid platforms, and everything is generated from that. I'm working on expanding this to be a wider table with struct elements. The GOOS and GOARCH may be independent from the constraint_values. I'd rather not introduce ios as anything other than a prefix for a few platform and toolchain targets. It's not a real GOOS value. I haven't figured out how "@io_bazel_rules_go//go/platform:darwin" is going to work yet in select. Need to experiment more. |
By the way, I've tested |
As I said in the PR: deps = select({
"@io_bazel_rules_go//go/platform:darwin": [
"//vendor/golang.org/x/sys/unix:go_default_library",
], Perhaps it should be: deps = select({
"@io_bazel_rules_go//go/platform:darwin": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:ios": [
"//vendor/golang.org/x/sys/unix:go_default_library",
], |
Refactored the description of target platforms. The source of truth is now the PLATFORMS table go/private/platforms.bzl. Declarations for config_settings in //go/platform; constraint_values and aliases in //go/toolchain; and toolchains in @go_sdk are generated from this table. In addition to the normal GOOS_GOARCH list, there are some additional entries for iOS. iOS platforms still have GOOS=darwin, but they are compatible with a different constraint_value (@bazel_tools//platforms:ios instead of @bazel_tools//platforms:osx). Fixes bazel-contrib#2079
Refactored the description of target platforms. The source of truth is now the PLATFORMS table go/private/platforms.bzl. Declarations for config_settings in //go/platform; constraint_values and aliases in //go/toolchain; and toolchains in @go_sdk are generated from this table. In addition to the normal GOOS_GOARCH list, there are some additional entries for iOS. iOS platforms still have GOOS=darwin, but they are compatible with a different constraint_value (@bazel_tools//platforms:ios instead of @bazel_tools//platforms:osx). There are also separate platforms for pure mode, and cgo (with _cgo suffix). Cross compilation may still be done with (for example) --platforms=@io_bazel_rules_go//go/platforms:linux_amd64, and this no longer requires a configured C/C++ toolchain. To cross-compile with cgo, use --platforms=@io_bazel_rules_go//go/platforms:linux_amd64_cgo. A compatible configured C/C++ toolchain is required in that case. Fixes #2079
What version of rules_go are you using?
What version of gazelle are you using?
What version of Bazel are you using?
Does this issue reproduce with the latest releases of all the above?
Yes.
What operating system and processor architecture are you using?
The problem
Bazel 0.26 ships with new platform enabled toolchains, which are defined like this:
Rules go uses the following constraints:
Now the problem is that it then becomes impossible to build for iOS since the toolchain requires
@bazel_tools//platforms:ios
and@bazel_tools//platforms:arm
but compiling fordarwin_arm64
requires/enforces@bazel_tools//platforms:osx
and@bazel_tools//platforms:aarch64
.I'm not sure what to do here since we can't apply both
osx
andios
constraints on the sameconstaint_setting
.The text was updated successfully, but these errors were encountered: