Skip to content

Commit 4416351

Browse files
committed
feat: Start migration to bzlmod
1 parent d1f264f commit 4416351

8 files changed

Lines changed: 993 additions & 50 deletions

File tree

.bazelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
common --noenable_bzlmod
1919

20+
common:bzlmod --enable_bzlmod
21+
common:bzlmod --noenable_workspace
22+
2023
build --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
2124
build --incompatible_strict_action_env=true
2225
build --incompatible_enable_cc_toolchain_resolution

MODULE.bazel

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
module(name = "gcc_toolchain", version="0.8.0")
2+
3+
# Dependencies
4+
# ============
5+
bazel_dep(name = "bazel_skylib", version = "1.8.1")
6+
bazel_dep(name = "aspect_bazel_lib", version = "2.20.0")
7+
bazel_dep(name = "platforms", version = "1.0.0")
8+
bazel_dep(name = "rules_cc", version = "0.2.0")
9+
10+
# Local Toolchains
11+
# ================
12+
gcc_toolchains = use_extension("//toolchain:module_extensions.bzl", "gcc_toolchains")
13+
14+
# Unfortunately, we can't load `ARCHS` directly here.
15+
# But the attributes in `gcc_register_toolchain.register_toolchain` are gated to only contain values from ARCHS
16+
all_architectures = [
17+
"aarch64",
18+
"armv7",
19+
"x86_64",
20+
]
21+
[gcc_toolchains.toolchain(
22+
name = "gcc_toolchain_{}".format(arch),
23+
target_arch = arch,
24+
)
25+
for arch in all_architectures]
26+
27+
[use_repo(gcc_toolchains, "gcc_toolchain_{}".format(arch))
28+
for arch in all_architectures]
29+
30+
[register_toolchains(
31+
"@gcc_toolchain_{}//:cc_toolchain".format(arch),
32+
"@gcc_toolchain_{}//:fortran_toolchain".format(arch),
33+
)
34+
for arch in all_architectures]
35+
36+
# Dev Dependencies (for examples/)
37+
# ===============================
38+
bazel_dep(name = "rules_foreign_cc", version = "0.15.0", dev_dependency=True)
39+
bazel_dep(name = "rules_proto", version = "7.1.0", dev_dependency=True)
40+
bazel_dep(name = "protobuf", version = "29.3", dev_dependency=True, repo_name="com_google_protobuf")
41+
single_version_override(
42+
module_name = "protobuf",
43+
patch_strip = 1,
44+
patches = [
45+
"//third_party/patches:com_google_protobuf.bzlmod.patch",
46+
],
47+
version = "29.3",
48+
)
49+
50+
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
51+
http_archive(
52+
name = "avl",
53+
url = "https://web.mit.edu/drela/Public/web/avl/avl3.40b.tgz",
54+
sha256 = "6d62e563578b79795a84958cfe4e221a4c9847fbeb4a821d45bc049934fc6a90",
55+
strip_prefix = "Avl",
56+
build_file = "//:examples/avl/avl.BUILD.bazel",
57+
)
58+
59+
_ALL_SRCS = """\
60+
filegroup(
61+
name = "srcs",
62+
srcs = glob(
63+
include = ["**"],
64+
exclude = ["**/* *"],
65+
),
66+
visibility = ["//visibility:public"],
67+
)
68+
"""
69+
70+
_LAPAK_PATCH = """\
71+
cat > make.inc <<EOF
72+
####################################################################
73+
# LAPACK make include file. #
74+
####################################################################
75+
76+
SHELL = $0
77+
78+
CC ?=
79+
80+
FC ?=
81+
FFLAGS ?=
82+
FFLAGS_DRV ?=
83+
FFLAGS_NOOPT ?=
84+
85+
LDFLAGS ?=
86+
87+
AR ?=
88+
ARFLAGS = cr
89+
RANLIB = echo
90+
91+
BLASLIB ?=
92+
CBLASLIB ?=
93+
LAPACKLIB ?=
94+
TMGLIB ?=
95+
LAPACKELIB ?=
96+
97+
DOCSDIR ?=
98+
99+
TIMER ?=
100+
EOF
101+
"""
102+
103+
http_archive(
104+
name = "lapack",
105+
url = "https://github.com/Reference-LAPACK/lapack/archive/refs/tags/v3.12.0.tar.gz",
106+
sha256 = "eac9570f8e0ad6f30ce4b963f4f033f0f643e7c3912fc9ee6cd99120675ad48b",
107+
strip_prefix = "lapack-3.12.0",
108+
patch_cmds = [_LAPAK_PATCH],
109+
build_file_content = _ALL_SRCS,
110+
)
111+
112+
http_archive(
113+
name = "openssl",
114+
sha256 = "40dceb51a4f6a5275bde0e6bf20ef4b91bfc32ed57c0552e2e8e15463372b17a",
115+
strip_prefix = "openssl-1.1.1n",
116+
url = "https://www.openssl.org/source/openssl-1.1.1n.tar.gz",
117+
build_file_content = _ALL_SRCS,
118+
)
119+

MODULE.bazel.lock

Lines changed: 690 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/defs.md

Lines changed: 52 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rules_cc/defs.bzl

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,41 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
def cc_library(name, static_libstdcxx = False, **kwargs):
15+
def _with_libstdcxx(rule, name, static_libstdcxx = False, **kwargs):
16+
target_name = "libstdcxx{}".format("_static" if static_libstdcxx else "")
1617
deps = kwargs.pop("deps", [])
1718
deps += select({
18-
"@platforms//cpu:aarch64": ["@gcc_toolchain_aarch64//:libstdcxx{}".format("_static" if static_libstdcxx else "")],
19-
"@platforms//cpu:armv7": ["@gcc_toolchain_armv7//:libstdcxx{}".format("_static" if static_libstdcxx else "")],
20-
"@platforms//cpu:x86_64": ["@gcc_toolchain_x86_64//:libstdcxx{}".format("_static" if static_libstdcxx else "")],
19+
"@platforms//cpu:aarch64": ["@gcc_toolchain_aarch64//:{}".format(target_name)],
20+
"@platforms//cpu:armv7": ["@gcc_toolchain_armv7//:{}".format(target_name)],
21+
"@platforms//cpu:x86_64": ["@gcc_toolchain_x86_64//:{}".format(target_name)],
2122
})
22-
native.cc_library(
23+
24+
rule(
2325
name = name,
2426
deps = deps,
2527
**kwargs
2628
)
2729

30+
def cc_library(name, static_libstdcxx = False, **kwargs):
31+
_with_libstdcxx(
32+
rule = native.cc_library,
33+
name = name,
34+
static_libstdcxx = static_libstdcxx,
35+
**kwargs,
36+
)
37+
2838
def cc_binary(name, static_libstdcxx = False, **kwargs):
29-
deps = kwargs.pop("deps", [])
30-
deps += select({
31-
"@platforms//cpu:aarch64": ["@gcc_toolchain_aarch64//:libstdcxx{}".format("_static" if static_libstdcxx else "")],
32-
"@platforms//cpu:armv7": ["@gcc_toolchain_armv7//:libstdcxx{}".format("_static" if static_libstdcxx else "")],
33-
"@platforms//cpu:x86_64": ["@gcc_toolchain_x86_64//:libstdcxx{}".format("_static" if static_libstdcxx else "")],
34-
})
35-
native.cc_binary(
39+
_with_libstdcxx(
40+
rule = native.cc_binary,
3641
name = name,
37-
deps = deps,
38-
**kwargs
42+
static_libstdcxx = static_libstdcxx,
43+
**kwargs,
3944
)
4045

4146
def cc_test(name, static_libstdcxx = False, **kwargs):
42-
deps = kwargs.pop("deps", [])
43-
deps += select({
44-
"@platforms//cpu:aarch64": ["@gcc_toolchain_aarch64//:libstdcxx{}".format("_static" if static_libstdcxx else "")],
45-
"@platforms//cpu:armv7": ["@gcc_toolchain_armv7//:libstdcxx{}".format("_static" if static_libstdcxx else "")],
46-
"@platforms//cpu:x86_64": ["@gcc_toolchain_x86_64//:libstdcxx{}".format("_static" if static_libstdcxx else "")],
47-
})
48-
native.cc_test(
47+
_with_libstdcxx(
48+
rule = native.cc_test,
4949
name = name,
50-
deps = deps,
51-
**kwargs
50+
static_libstdcxx = static_libstdcxx,
51+
**kwargs,
5252
)

0 commit comments

Comments
 (0)