Skip to content

Add support for arm64 on Darwin #17

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
workspace(name = "rules_kubebuilder")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@rules_kubebuilder//kubebuilder:sdk.bzl", "kubebuilder_register_sdk")

kubebuilder_register_sdk(version = "2.3.1")

## Next section is for testing in this same MP.

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_pkg",
sha256 = "6b5969a7acd7b60c02f816773b06fcf32fbe8ba0c7919ccdc2df4f8fb923804a",
sha256 = "335632735e625d408870ec3e361e192e99ef7462315caa887417f4d88c4c8fb8",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.3.0/rules_pkg-0.3.0.tar.gz",
"https://github.com/bazelbuild/rules_pkg/releases/download/0.3.0/rules_pkg-0.3.0.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.0/rules_pkg-0.9.0.tar.gz",
"https://github.com/bazelbuild/rules_pkg/releases/download/0.9.0/rules_pkg-0.9.0.tar.gz",
],
)

Expand All @@ -23,15 +22,20 @@ rules_pkg_dependencies()

http_archive(
name = "io_bazel_rules_go",
sha256 = "b4433651f57560237681cb9caa969106aba614f5b1e66fefa5834c42b8013b42",
sha256 = "6b65cb7917b4d1709f9410ffe00ecf3e160edf674b78c54a894471320862184f",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.24.6/rules_go-v0.24.6.tar.gz",
"https://github.com/bazelbuild/rules_go/releases/download/v0.24.6/rules_go-v0.24.6.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.39.0/rules_go-v0.39.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.39.0/rules_go-v0.39.0.zip",
],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains()
go_register_toolchains(version = "1.19.3")

load("@rules_kubebuilder//kustomize:deps.bzl", "kustomize_register_toolchain")

# 4.2.0 is the first version that supports the M1 architecture.
kustomize_register_toolchain(version = "4.2.0")
93 changes: 56 additions & 37 deletions controller-gen/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
load("@rules_kubebuilder//controller-gen:controller-gen-toolchain.bzl", "controller_gen_toolchain")
load("@rules_kubebuilder//controller-gen:controller-gen-toolchain.bzl", "CONTROLLER_GEN_ARCHES", "CONTROLLER_GEN_VERSIONS", "controller_gen_toolchain")
load("@rules_pkg//:pkg.bzl", "pkg_tar")

exports_files(
[
"bin/controller-gen.linux",
"bin/controller-gen.darwin",
],
visibility = ["//visibility:public"],
)
[
exports_files(
[
"bin/controller-gen-%s.linux" % version,
"bin/controller-gen-%s.darwin-%s" % (version, arch),
],
visibility = ["//visibility:public"],
)
for version in CONTROLLER_GEN_VERSIONS
for arch in CONTROLLER_GEN_ARCHES
]

filegroup(
name = "srcs",
Expand Down Expand Up @@ -35,36 +39,51 @@ pkg_tar(
deps = [":release-bin"],
)

toolchain_type(name = "toolchain")
toolchain_type(name = "toolchain_type")

controller_gen_toolchain(
name = "controller_gen_linux",
controller_gen_bin = "@rules_kubebuilder//controller-gen:bin/controller-gen.linux",
)
[
controller_gen_toolchain(
name = "controller_gen_linux_%s" % version,
controller_gen_bin = "@rules_kubebuilder//controller-gen:bin/controller-gen-%s.linux" % version,
)
for version in CONTROLLER_GEN_VERSIONS
]

controller_gen_toolchain(
name = "controller_gen_darwin",
controller_gen_bin = "@rules_kubebuilder//controller-gen:bin/controller-gen.darwin",
)
[
controller_gen_toolchain(
name = "controller_gen_darwin_%s_%s" % (version, arch),
controller_gen_bin = "@rules_kubebuilder//controller-gen:bin/controller-gen-%s.darwin-%s" % (version, arch),
)
for version in CONTROLLER_GEN_VERSIONS
for arch in CONTROLLER_GEN_ARCHES
]

toolchain(
name = "controller_gen_linux_toolchain",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
toolchain = ":controller_gen_linux",
toolchain_type = ":toolchain",
visibility = ["//visibility:public"],
)
[
toolchain(
name = "controller_gen_linux_toolchain_%s" % version,
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
toolchain = ":controller_gen_linux_%s" % version,
toolchain_type = ":toolchain_type",
visibility = ["//visibility:public"],
)
for version in CONTROLLER_GEN_VERSIONS
# TODO: Add arm64 support for linux
]

toolchain(
name = "controller_gen_darwin_toolchain",
exec_compatible_with = [
"@platforms//os:osx",
"@platforms//cpu:x86_64",
],
toolchain = ":controller_gen_darwin",
toolchain_type = ":toolchain",
visibility = ["//visibility:public"],
)
[
toolchain(
name = "controller_gen_darwin_toolchain_%s_%s" % (version, arch),
exec_compatible_with = [
"@platforms//os:osx",
"@platforms//cpu:%s" % arch,
],
toolchain = ":controller_gen_darwin_%s_%s" % (version, arch),
toolchain_type = ":toolchain_type",
visibility = ["//visibility:public"],
)
for version in CONTROLLER_GEN_VERSIONS
for arch in CONTROLLER_GEN_ARCHES
]
Binary file not shown.
Binary file not shown.
Binary file added controller-gen/bin/controller-gen-0.3.0.linux
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions controller-gen/controller-gen-toolchain.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
""" Toolchain definitions for controller-gen
"""

CONTROLLER_GEN_VERSIONS = [
"0.3.0",
"0.4.1",
]
CONTROLLER_GEN_DEFAULT_VERSION = CONTROLLER_GEN_VERSIONS[0]

CONTROLLER_GEN_ARCHES = [
"x86_64",
"arm64",
]

ControllerGenInfo = provider(
doc = "Information about how to invoke controller-gen",
fields = ["controller_gen_bin"],
Expand Down
11 changes: 8 additions & 3 deletions controller-gen/deps.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
""" Dependencies for controller-gen
"""

def controller_gen_register_toolchain(name = None):
load("@rules_kubebuilder//controller-gen:controller-gen-toolchain.bzl", "CONTROLLER_GEN_ARCHES", "CONTROLLER_GEN_DEFAULT_VERSION")

def controller_gen_register_toolchain(name = None, version = CONTROLLER_GEN_DEFAULT_VERSION):
for arch in CONTROLLER_GEN_ARCHES:
native.register_toolchains(
"@rules_kubebuilder//controller-gen:controller_gen_darwin_toolchain_%s_%s" % (version, arch),
)
native.register_toolchains(
"@rules_kubebuilder//controller-gen:controller_gen_linux_toolchain",
"@rules_kubebuilder//controller-gen:controller_gen_darwin_toolchain",
"@rules_kubebuilder//controller-gen:controller_gen_linux_toolchain_%s" % version,
)
26 changes: 20 additions & 6 deletions kubebuilder/generate_sdk_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ReleaseItem:
version: str
linux_amd64_checksum: str
darwin_amd64_checksum: str
darwin_arm64_checksum: str


def main():
Expand Down Expand Up @@ -39,9 +40,15 @@ def fetch_release_items():
list(checksum_dic.keys()), "linux_amd64")
darwin_amd64_key = get_key_containing(
list(checksum_dic.keys()), "darwin_amd64")
darwin_arm64_key = get_key_containing(
list(checksum_dic.keys()), "darwin_arm64")

items.append(ReleaseItem(
release["tag_name"], checksum_dic[linux_amd64_key], checksum_dic[darwin_amd64_key]))
if darwin_arm64_key:
items.append(ReleaseItem(
release["tag_name"], checksum_dic[linux_amd64_key], checksum_dic[darwin_amd64_key], checksum_dic[darwin_arm64_key]))
else:
items.append(ReleaseItem(
release["tag_name"], checksum_dic[linux_amd64_key], checksum_dic[darwin_amd64_key], None))

return items

Expand All @@ -55,10 +62,17 @@ def generate_sdk_list(items: List[ReleaseItem]):
"""
sdk_dic = {}
for item in items:
sdk_dic[item.version.replace("v","")] = {
"linux_amd64": item.linux_amd64_checksum,
"darwin_amd64": item.darwin_amd64_checksum,
}
if item.darwin_arm64_checksum:
sdk_dic[item.version.replace("v","")] = {
"linux_amd64": item.linux_amd64_checksum,
"darwin_amd64": item.darwin_amd64_checksum,
"darwin_arm64": item.darwin_arm64_checksum,
}
else:
sdk_dic[item.version.replace("v","")] = {
"linux_amd64": item.linux_amd64_checksum,
"darwin_amd64": item.darwin_amd64_checksum,
}
result += remove_first_line(json.dumps(sdk_dic, indent=4))
with open("sdk_list.bzl", "w") as f:
f.write(result)
Expand Down
4 changes: 3 additions & 1 deletion kubebuilder/sdk.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ def kubebuilder_download_sdk(name, **kwargs):
def _detect_host_platform(ctx):
if ctx.os.name == "linux":
host = "linux_amd64"
elif ctx.os.name == "mac os x":
elif ctx.os.name == "mac os x" and ctx.os.uname.machine == "x86_64":
host = "darwin_amd64"
elif ctx.os.name == "mac os x" and ctx.os.uname.machine == "arm64":
host = "darwin_arm64"
else:
fail("Unsupported operating system: " + ctx.os.name)
return host
Expand Down
63 changes: 36 additions & 27 deletions kubebuilder/sdk_list.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,50 @@
DEFAULT_VERSION = "2.3.1"

SDK_VERSION_SHA256 = {
"3.10.0": {
"linux_amd64": "d9ba5517a8cc8acaa9cf46c62525db7c5b2d3fd160618904a7796491e3f1ea21",
"darwin_amd64": "f27ac711e33ba794398ea6bd5b7447fc297f4c0f8c7a6bd01755f22e515cbf3a",
"darwin_arm64": "6d47e6d15508738b07da360529baefc246e589b0ebe8d54a6a8818a30ca24e90"
},
"3.9.1": {
"linux_amd64": "aa20234e12e8d74c988482c21f8bb00be12b859e377a51d2358dac4017f3623b",
"darwin_amd64": "81a20c7076479042c9fa8fa814462fd1349d63e9ff86c789c4267118ef4ceaf2",
"darwin_arm64": "a48ff7b589e4787db60de3b17d2f6f6a1f75ac33b2c93d32d37a9e91f42378d7"
},
"3.9.0": {
"linux_amd64": "2dfd6eebabd7e6b05c02ca1f5e5ecd9be38f462a2754dea039318c6565517c3f",
"darwin_amd64": "943c102e23c78c9e772d0c3470bd685a87ad396d39f24c0f21d36a8a218aa808",
"darwin_arm64": "756d5c6cdd19efc3c1bb313b2666a9ee88effd06986811037cf8a18bd72e316e"
},
"3.8.0": {
"linux_amd64": "27d22a91e293c916012d60b66e42e72e7f0234fded7cc5c73eb28343cca7a869",
"darwin_amd64": "6ad9e48197afdf6f2352bb8b824f5fe87369df881dcaa0fcb2261fb69add9082",
"darwin_arm64": "f98de66ae5e83a8aebb2d023dac3f886f64c0d73979a0b79a1a002d5aa90208f"
},
"3.7.0": {
"linux_amd64": "b413f3229a27d83bdfe525c20144e8bab5c15fc8771717c41d8fb9fd68898dd8",
"darwin_amd64": "235ca6649f05f7dfff2152a9adbf8fbee15b71b8553d4c04df954fc5e121756d",
"darwin_arm64": "d2c7c533db79e748d5a3539b942cd0518eeb8993a20f971f13084a66280d6e50"
},
"3.6.0": {
"linux_amd64": "d5a9f639cb98298817bcab32b6046eb45cb912b56217a75d729646512a436ff4",
"darwin_amd64": "c5f1d912ba08e2745c034e1d531bf8af956f316e76e7f02afccb05f377aee5a4",
"darwin_arm64": "4b117e547d4b8557b7f72f7c508885733f13e1100710379cdd35daab0c74b4ac"
},
"3.5.0": {
"linux_amd64": "271e59de861684156515b8aa53eafa0cd242017595652c52a072b1812bbd3775",
"darwin_amd64": "b75c1f1532fc27187097f9ccb6c4d8e8ea751e7e9a238a1c1f2c58b171eadad7"
"darwin_amd64": "b75c1f1532fc27187097f9ccb6c4d8e8ea751e7e9a238a1c1f2c58b171eadad7",
"darwin_arm64": "dfde9dda51d4f32dd16499103198ebe45430cf71c59d4fe4c0614212273a4bd1"
},
"3.4.1": {
"linux_amd64": "4b9c6b3afec09bd1c1f1a67ed11c275854b9cbddc1654ebdb77c3b0b95f4e065",
"darwin_amd64": "6c4600ff2a4ed02c073f0c9d305bf89948e02b3767d2d5a810d0138d269c133d"
"darwin_amd64": "6c4600ff2a4ed02c073f0c9d305bf89948e02b3767d2d5a810d0138d269c133d",
"darwin_arm64": "8f20303a8d3ed579d38160b92a7314f793892daa33cbc366b4f340bbb0308bc2"
},
"3.4.0": {
"linux_amd64": "cf90dad16d27a9c31db11f2c326aad926036610a75be03f342e28136ae64cf47",
"darwin_amd64": "4d77ba9e9fc214dbd16077fa069bf40606bfe57c359b3e24fbf38919922d7b5f"
"darwin_amd64": "4d77ba9e9fc214dbd16077fa069bf40606bfe57c359b3e24fbf38919922d7b5f",
"darwin_arm64": "d55fa73e8bf510c3614fa75bf2cff56cf21c300e7a4ced77f4757c9e0ed08a47"
},
"3.3.0": {
"linux_amd64": "f9fb1a8e329dfe3be635ccdec3c7d3a6df4092ba13243bfcb89111b12343eb4f",
Expand Down Expand Up @@ -98,29 +131,5 @@ SDK_VERSION_SHA256 = {
"2.0.0-alpha.2": {
"linux_amd64": "d9d3f471cb54f4e802ed763d0706720be45f65c7bd36e45ab28db7840028bf72",
"darwin_amd64": "795e49c0c9111f27307f63af9271f736efc1d2c8d2379be0087ff26321a7719c"
},
"2.0.0-alpha.1": {
"linux_amd64": "8647fcac60166ae211b9e198596452003c5887dd5b0d8b79427aa4fe3357f125",
"darwin_amd64": "c19887e34f5ff008d89ae3e86aeecd0560002c0dacd36f870b46741e9426b551"
},
"2.0.0-alpha.0": {
"linux_amd64": "edee6582e8cf0c2836d509ed3939b7c3a1006c28bb57f22f2a3d4a5f4699ae99",
"darwin_amd64": "9405023af5ddbadf5196cf450c412e3d328c995a86f097f69222c26110c003b2"
},
"1.0.8": {
"linux_amd64": "7dfaf7a38d69c77f046e85aeabfe96f7cdd88634feab3ecc0bb03f9da7e69ad3",
"darwin_amd64": "a2a2db0db67c61e7ae958b9ff393e44a7032cd11b5e46acf9bd0a547e3fb9915"
},
"1.0.7": {
"linux_amd64": "9f7f55708429122b2111a5012977265522228764e756e0094f0128605f85b462",
"darwin_amd64": "f58b9b33a3a61be2313c1747c91c46436deede87d20ad13287618d5e54e9d315"
},
"1.0.6": {
"linux_amd64": "a622eebdcc95984d3a3d87d0acd2d7c02b463f4db23b1b22020a2bc77c032668",
"darwin_amd64": "0a056b58af62e4204cc65e0a7a39236396acff1935fe10effd52bf226ea6dbc3"
},
"1.0.5": {
"linux_amd64": "e729c74f6a1b3ab9c416642f372b84df60d07c84f64302f1f7e3fe7a9f9411e5",
"darwin_amd64": "a510ef34d947764f57385e11990ba70560bf2d520f56849160174d2c18544063"
}
}
Loading