Skip to content

Commit 4b4ee9b

Browse files
authored
Revert link_hack change (#73)
This restores support for 8.x, and makes 9.x require a patch on rules_cc (which users have to opt into) The checking changed with 9.x in bazelbuild/bazel@26760a0 which is strict for external repos
1 parent 06a6841 commit 4b4ee9b

6 files changed

Lines changed: 57 additions & 2 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
- ubuntu-latest
1919
bazel:
2020
- 8.x
21+
- 9.x
2122
- latest
2223
- last_rc
2324
- last_green

MODULE.bazel

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@ module(
66

77
bazel_dep(name = "bazel_skylib", version = "1.7.1")
88
bazel_dep(name = "platforms", version = "0.0.11")
9-
bazel_dep(name = "rules_cc", version = "0.1.1")
9+
bazel_dep(name = "rules_cc", version = "0.2.16")
1010
bazel_dep(name = "rules_python", version = "1.0.0")
1111

12+
# Apply this patch in your project if you want to use shared libraries with mojo
13+
single_version_override(
14+
module_name = "rules_cc",
15+
patch_strip = 1,
16+
patches = [
17+
# https://github.com/bazelbuild/rules_cc/pull/578
18+
"//tools:rules_cc.patch",
19+
],
20+
)
21+
1222
mojo = use_extension("//mojo:extensions.bzl", "mojo")
1323
mojo.toolchain()
1424
mojo.gpu_toolchains()
@@ -56,3 +66,9 @@ versions(
5666
dev_dependency = True,
5767
python_versions = _PYTHON_VERSIONS,
5868
)
69+
70+
link_hack = use_repo_rule("//mojo/private:link_hack.bzl", "link_hack")
71+
72+
link_hack(
73+
name = "build_bazel_rules_android", # See link_hack.bzl for details
74+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
https://github.com/bazelbuild/bazel/pull/23838
44
"""
55

6+
def _link_hack_impl(rctx):
7+
rctx.file("BUILD.bazel", "")
8+
rctx.file("link_hack.bzl", """\
69
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
710
811
def link_hack(**kwargs):
912
return cc_common.link(**kwargs)
13+
""")
14+
15+
link_hack = repository_rule(
16+
implementation = _link_hack_impl,
17+
)

mojo/private/mojo_binary_test.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
load("@bazel_skylib//lib:paths.bzl", "paths")
44
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
55
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain")
6+
load("@build_bazel_rules_android//:link_hack.bzl", "link_hack") # See link_hack.bzl for details
67
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
78
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
89
load("@rules_python//python:py_info.bzl", "PyInfo")
910
load("//mojo:providers.bzl", "MojoInfo")
10-
load("//tools/build_defs/android:link_hack.bzl", "link_hack") # See link_hack.bzl for details
1111
load(":transitions.bzl", "python_version_transition")
1212
load(":utils.bzl", "MOJO_EXTENSIONS", "collect_mojoinfo")
1313

tools/rules_cc.patch

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
diff --git a/cc/private/cc_common.bzl b/cc/private/cc_common.bzl
2+
index 69d6db11..82e9c49b 100644
3+
--- a/cc/private/cc_common.bzl
4+
+++ b/cc/private/cc_common.bzl
5+
@@ -85,7 +85,7 @@ def _link(
6+
additional_linkstamp_defines = _UNBOUND,
7+
always_link = _UNBOUND,
8+
link_artifact_name_suffix = _UNBOUND,
9+
- main_output = _UNBOUND,
10+
+ main_output = None,
11+
use_shareable_artifact_factory = _UNBOUND,
12+
build_config = _UNBOUND,
13+
emit_interface_shared_library = _UNBOUND):
14+
@@ -103,7 +103,6 @@ def _link(
15+
additional_linkstamp_defines != _UNBOUND or \
16+
always_link != _UNBOUND or \
17+
link_artifact_name_suffix != _UNBOUND or \
18+
- main_output != _UNBOUND or \
19+
use_shareable_artifact_factory != _UNBOUND or \
20+
build_config != _UNBOUND or \
21+
emit_interface_shared_library != _UNBOUND:
22+
@@ -125,8 +124,6 @@ def _link(
23+
always_link = False
24+
if link_artifact_name_suffix == _UNBOUND:
25+
link_artifact_name_suffix = ""
26+
- if main_output == _UNBOUND:
27+
- main_output = None
28+
if use_shareable_artifact_factory == _UNBOUND:
29+
use_shareable_artifact_factory = False
30+
if build_config == _UNBOUND:

0 commit comments

Comments
 (0)