bazel-ios / rules_ios

Bazel rules for building iOS applications and frameworks
Apache License 2.0
276 stars 85 forks source link

Add support for Bazel 7 #795

Closed luispadron closed 5 months ago

luispadron commented 10 months ago

Bazel 7 is coming out soon (November 2023), building with USE_BAZEL_VERSION=last_rc we get the following error:

ERROR: /Users/lpadron/Development/rules_xcodeproj/examples/rules_ios/iOSApp/Source/BUILD:32:26: //iOSApp/Source:iOSApp: no such attribute 'output_discriminator' in 'ios_application' rule
ERROR: /Users/lpadron/Development/rules_xcodeproj/examples/rules_ios/iOSApp/Source/BUILD:32:26: errors encountered resolving select() keys for //iOSApp/Source:iOSApp

Tasks

mattrobmattrob commented 10 months ago

Are you working on this actively, @luispadron?

luispadron commented 10 months ago

I was going to pick it up next week (if I wasn't too busy) but if you want to take it, I wouldn't mind at all!

mattrobmattrob commented 10 months ago

I find it pretty bizarre that in rules_apple on the 3.1.1 tag, this doesn't work:

$ USE_BAZEL_VERSION=6.3.2 bazel build //examples/ios/HelloWorld
Starting local Bazel server and connecting to it...
ERROR: /Users/mattrobinson/Developer/github/bazelbuild/rules_apple/examples/ios/HelloWorld/BUILD:29:16: //examples/ios/HelloWorld:HelloWorld: no such attribute 'output_discriminator' in 'ios_application' rule
ERROR: Skipping '//examples/ios/HelloWorld': Error evaluating '//examples/ios/HelloWorld': error loading package 'examples/ios/HelloWorld': Package 'examples/ios/HelloWorld' contains errors
WARNING: Target pattern parsing failed.
ERROR: Error evaluating '//examples/ios/HelloWorld': error loading package 'examples/ios/HelloWorld': Package 'examples/ios/HelloWorld' contains errors
INFO: Elapsed time: 4.567s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded)

With these changes:

diff --git a/.bazelrc b/.bazelrc
index 44e77dbe..9872ad12 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -1,3 +1,5 @@
+common --experimental_enable_bzlmod
+
 # NOTE: These are mainly just for the BazelCI setup so they don't have
 # to be repeated multiple times in .bazelci/presubmit.yml.

diff --git a/examples/ios/HelloWorld/BUILD b/examples/ios/HelloWorld/BUILD
index 10edbf0b..ce41f4a3 100644
--- a/examples/ios/HelloWorld/BUILD
+++ b/examples/ios/HelloWorld/BUILD
@@ -39,6 +39,7 @@ ios_application(
     minimum_os_version = "11.0",
     version = ":HelloWorldVersion",
     deps = [":Sources"],
+    output_discriminator = "",
 )

But maybe I'm missing something. Haven't been able to determine where that attribute is coming from WRT rules_ios on non-Bazel 7.

luispadron commented 10 months ago

Hm yah that is confusing, if it's failing in rules_apple with Bazel 6 I'd expect the same here since output_discriminator was added in the rules_apple 3 pr

luispadron commented 10 months ago

@mattrobmattrob fwiw output_discriminator usage in the rules_ios which is failing seems to be old and set to None like in app.bzl.

Should we just remove setting this to None?

mattrobmattrob commented 10 months ago

That was my initial (and current) thought, @luispadron. I was just trying to explain what had changed because it didn't really make all that much sense to me.

luispadron commented 10 months ago

Yeah I searched a lil yesterday and couldn't find where that attr was removed

mattrobmattrob commented 10 months ago

Ah, okay. Now I've got it! It seems like it's Bazel validating the input attributes better when they come directly from macros.

With these changes:

diff --git a/apple/versioning.bzl b/apple/versioning.bzl
index c65ae432..7d309f79 100644
--- a/apple/versioning.bzl
+++ b/apple/versioning.bzl
@@ -23,11 +23,15 @@ load(
     "AppleXPlatToolsToolchainInfo",
     "apple_toolchain_utils",
 )
+load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application")
 load(
     "@bazel_skylib//lib:dicts.bzl",
     "dicts",
 )

+def fake_ios_application(**kwargs):
+    ios_application(output_discriminator = None, **kwargs)
+
 def _collect_group_names(s):
     """Returns the list of placeholder names found in the given string.

diff --git a/examples/ios/HelloWorld/BUILD b/examples/ios/HelloWorld/BUILD
index 10edbf0b..dc05455d 100644
--- a/examples/ios/HelloWorld/BUILD
+++ b/examples/ios/HelloWorld/BUILD
@@ -4,6 +4,7 @@ load("//apple:xcarchive.bzl", "xcarchive")
 load(
     "//apple:versioning.bzl",
     "apple_bundle_version",
+    "fake_ios_application",
 )

 licenses(["notice"])
@@ -26,7 +27,7 @@ apple_bundle_version(
     build_version = "1.0",
 )

-ios_application(
+fake_ios_application(
     name = "HelloWorld",
     app_icons = ["//examples/resources:PhoneAppIcon.xcassets"],
     bundle_id = "com.example.hello-world",

Works on 6.3.2 and not on last_rc:

$ USE_BAZEL_VERSION=6.3.2 bazel build //examples/ios/HelloWorld
INFO: Analyzed target //examples/ios/HelloWorld:HelloWorld (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //examples/ios/HelloWorld:HelloWorld up-to-date:
  bazel-bin/examples/ios/HelloWorld/HelloWorld.ipa
INFO: Elapsed time: 0.089s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action

$ USE_BAZEL_VERSION=last_rc bazel build //examples/ios/HelloWorld
Starting local Bazel server and connecting to it...
ERROR: /Users/mattrobinson/Developer/github/bazelbuild/rules_apple/examples/ios/HelloWorld/BUILD:30:21: //examples/ios/HelloWorld:HelloWorld: no such attribute 'output_discriminator' in 'ios_application' rule
WARNING: Target pattern parsing failed.
ERROR: Skipping '//examples/ios/HelloWorld': Error evaluating '//examples/ios/HelloWorld': error loading package 'examples/ios/HelloWorld': Package 'examples/ios/HelloWorld' contains errors
ERROR: Error evaluating '//examples/ios/HelloWorld': error loading package 'examples/ios/HelloWorld': Package 'examples/ios/HelloWorld' contains errors
INFO: Elapsed time: 3.681s
INFO: 0 processes.
ERROR: Build did NOT complete successfully
luispadron commented 10 months ago

Updated to include the two issues we've found

luispadron commented 9 months ago

@mattrobmattrob Have you made any more progress here? Thanks again for working on this!

mattrobmattrob commented 9 months ago

@mattrobmattrob Have you made any more progress here? Thanks again for working on this!

Nope. I haven’t had time to investigate the oddity in platform SDK selection yet. All PRs should link to this issue though if you want to pick it up.

mattrobmattrob commented 9 months ago

The clang: error: using sysroot for 'iPhoneSimulator' but targeting 'MacOSX' [-Werror,-Wincompatible-sysroot] error that's occurring after that toolchain fix is discussed a bit in: https://bazelbuild.slack.com/archives/CD3QY5C2X/p1701890904270059

karim-alweheshy commented 9 months ago

USE_BAZEL_VERSION=7.0.0 bazel build //examples/ios/HelloWorld works fine on latest master rules_apple:f37305163dd7546f87839f3187e153c955cd20d8

mattrobmattrob commented 9 months ago

https://github.com/bazel-ios/rules_ios/pull/797 is an example of the CI moved over to Bazel 7.0.0, @karim-alweheshy. It has some issues that'll need fixed as well if you want to look at the errors on CI.

luispadron commented 9 months ago

The current issue seems to be:

ld: Undefined symbols:
  _main, referenced from:
      <initial-undefines>

This is failing when running the following:

bazel build \
    --config=ios \
    --config=vfs \
    --ios_multi_cpus=sim_arm64 \
    -- \
    //tests/ios/... \
    -//tests/ios/unit-test/test-imports-app/...

This might be related to ObjcProvider changes made in: https://github.com/bazelbuild/bazel/issues/17377

We'll likely need to audit and update our usage of ObjcProvider for Bazel 7 specifically.

karim-alweheshy commented 9 months ago

@luispadron confirming your findings The overall effort is described in more details here

More details here