diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 212385d..1815eba 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,6 +18,7 @@ jobs: - ubuntu-latest bazel: - 8.x + - 9.x - latest - last_rc - last_green diff --git a/MODULE.bazel b/MODULE.bazel index 8036752..dd06210 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -6,9 +6,19 @@ module( bazel_dep(name = "bazel_skylib", version = "1.7.1") bazel_dep(name = "platforms", version = "0.0.11") -bazel_dep(name = "rules_cc", version = "0.1.1") +bazel_dep(name = "rules_cc", version = "0.2.16") bazel_dep(name = "rules_python", version = "1.0.0") +# Apply this patch in your project if you want to use shared libraries with mojo +single_version_override( + module_name = "rules_cc", + patch_strip = 1, + patches = [ + # https://github.com/bazelbuild/rules_cc/pull/578 + "//tools:rules_cc.patch", + ], +) + mojo = use_extension("//mojo:extensions.bzl", "mojo") mojo.toolchain() mojo.gpu_toolchains() @@ -56,3 +66,9 @@ versions( dev_dependency = True, python_versions = _PYTHON_VERSIONS, ) + +link_hack = use_repo_rule("//mojo/private:link_hack.bzl", "link_hack") + +link_hack( + name = "build_bazel_rules_android", # See link_hack.bzl for details +) diff --git a/tools/build_defs/android/link_hack.bzl b/mojo/private/link_hack.bzl similarity index 64% rename from tools/build_defs/android/link_hack.bzl rename to mojo/private/link_hack.bzl index 3fc2a7d..0c57ada 100644 --- a/tools/build_defs/android/link_hack.bzl +++ b/mojo/private/link_hack.bzl @@ -3,7 +3,15 @@ https://github.com/bazelbuild/bazel/pull/23838 """ +def _link_hack_impl(rctx): + rctx.file("BUILD.bazel", "") + rctx.file("link_hack.bzl", """\ load("@rules_cc//cc/common:cc_common.bzl", "cc_common") def link_hack(**kwargs): return cc_common.link(**kwargs) +""") + +link_hack = repository_rule( + implementation = _link_hack_impl, +) diff --git a/mojo/private/mojo_binary_test.bzl b/mojo/private/mojo_binary_test.bzl index 5809f5f..f1abe07 100644 --- a/mojo/private/mojo_binary_test.bzl +++ b/mojo/private/mojo_binary_test.bzl @@ -3,11 +3,11 @@ load("@bazel_skylib//lib:paths.bzl", "paths") load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain") +load("@build_bazel_rules_android//:link_hack.bzl", "link_hack") # See link_hack.bzl for details load("@rules_cc//cc/common:cc_common.bzl", "cc_common") load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") load("@rules_python//python:py_info.bzl", "PyInfo") load("//mojo:providers.bzl", "MojoInfo") -load("//tools/build_defs/android:link_hack.bzl", "link_hack") # See link_hack.bzl for details load(":transitions.bzl", "python_version_transition") load(":utils.bzl", "MOJO_EXTENSIONS", "collect_mojoinfo") diff --git a/tools/build_defs/android/BUILD.bazel b/tools/BUILD.bazel similarity index 100% rename from tools/build_defs/android/BUILD.bazel rename to tools/BUILD.bazel diff --git a/tools/rules_cc.patch b/tools/rules_cc.patch new file mode 100644 index 0000000..3ba4c42 --- /dev/null +++ b/tools/rules_cc.patch @@ -0,0 +1,30 @@ +diff --git a/cc/private/cc_common.bzl b/cc/private/cc_common.bzl +index 69d6db11..82e9c49b 100644 +--- a/cc/private/cc_common.bzl ++++ b/cc/private/cc_common.bzl +@@ -85,7 +85,7 @@ def _link( + additional_linkstamp_defines = _UNBOUND, + always_link = _UNBOUND, + link_artifact_name_suffix = _UNBOUND, +- main_output = _UNBOUND, ++ main_output = None, + use_shareable_artifact_factory = _UNBOUND, + build_config = _UNBOUND, + emit_interface_shared_library = _UNBOUND): +@@ -103,7 +103,6 @@ def _link( + additional_linkstamp_defines != _UNBOUND or \ + always_link != _UNBOUND or \ + link_artifact_name_suffix != _UNBOUND or \ +- main_output != _UNBOUND or \ + use_shareable_artifact_factory != _UNBOUND or \ + build_config != _UNBOUND or \ + emit_interface_shared_library != _UNBOUND: +@@ -125,8 +124,6 @@ def _link( + always_link = False + if link_artifact_name_suffix == _UNBOUND: + link_artifact_name_suffix = "" +- if main_output == _UNBOUND: +- main_output = None + if use_shareable_artifact_factory == _UNBOUND: + use_shareable_artifact_factory = False + if build_config == _UNBOUND: