Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yujunz committed Aug 7, 2019
0 parents commit a3e132a
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bazel-*
.tags
.tags.lock
.tags.temp
Empty file added BUILD.bazel
Empty file.
5 changes: 5 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
workspace(name = "com_github_yujunz_rules_helm")

load("@com_github_yujunz_rules_helm//helm:deps.bzl", "helm_register_toolchains", "helm_rules_dependencies")
helm_rules_dependencies()
helm_register_toolchains()
4 changes: 4 additions & 0 deletions helm/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
toolchain_type(
name = "toolchain",
visibility = ["//visibility:public"],
)
10 changes: 10 additions & 0 deletions helm/def.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def _helm_chart_impl(ctx):
return []

def helm_chart():
return rule(
implementation = _helm_chart_impl,
attrs = {},
toolchains = ["@com_github_yujunz_rules_helm//helm:toolchain"],
**kwargs
)
5 changes: 5 additions & 0 deletions helm/deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def helm_rules_dependencies():
pass

def helm_register_toolchains():
pass
43 changes: 43 additions & 0 deletions helm/platforms.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
BAZEL_HELM_OS_CONSTRAINTS = {
"darwin": "@bazel_tools//platforms:osx",
"linux": "@bazel_tools//platforms:linux",
}

BAZEL_HELM_ARCH_CONSTRAINTS = {
"amd64": "@bazel_tools//platforms:x86_64",
}

HELM_OS_ARCH = (
("darwin", "amd64"),
("linux", "amd64"),
)

def _generate_constraints(names, bazel_constraints):
return {
name: bazel_constraints.get(name, "@com_github_yujunz_rules_helm//helm/toolchain:" + name)
for name in names
}

HELM_OS_CONSTRAINTS = _generate_constraints([p[0] for p in HELM_OS_ARCH], BAZEL_HELM_OS_CONSTRAINTS)
HELM_ARCH_CONSTRAINTS = _generate_constraints([p[1] for p in HELM_OS_ARCH], BAZEL_HELM_ARCH_CONSTRAINTS)

def _generate_platforms():
platforms = []
for os, arch in HELM_OS_ARCH:
constraints = [
HELM_OS_CONSTRAINTS[os],
HELM_ARCH_CONSTRAINTS[arch],
]
platforms.append(struct(
name = os + "_" + arch,
os = os,
arch = arch,
constraints = constraints,
))
return platforms

PLATFORMS = _generate_platforms()

def generate_toolchain_names():
# keep in sync with declare_toolchains
return ["helm_" + p.name for p in PLATFORMS]
15 changes: 15 additions & 0 deletions helm/toolchain/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load(
":toolchains.bzl",
"declare_constraints",
)

package(default_visibility = ["//visibility:public"])

declare_constraints()

filegroup(
name = "all_files",
testonly = True,
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
50 changes: 50 additions & 0 deletions helm/toolchain/toolchains.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
load(
"@com_github_yujunz_rules_helm//helm:platforms.bzl",
"HELM_ARCH_CONSTRAINTS",
"HELM_OS_CONSTRAINTS",
"PLATFORMS",
)

def declare_constraints():
"""Generates constraint_values and platform targets for valid platforms.
Each constraint_value corresponds to a valid os or goarch.
The os and goarch values belong to the constraint_settings
@bazel_tools//platforms:os and @bazel_tools//platforms:cpu, respectively.
To avoid redundancy, if there is an equivalent value in @bazel_tools,
we define an alias here instead of another constraint_value.
Each platform defined here selects a os and goarch constraint value.
These platforms may be used with --platforms for cross-compilation,
though users may create their own platforms (and
@bazel_tools//platforms:default_platform will be used most of the time).
"""
for os, constraint in HELM_OS_CONSTRAINTS.items():
if constraint.startswith("@com_github_yujunz_rules_helm//helm/toolchain:"):
native.constraint_value(
name = os,
constraint_setting = "@bazel_tools//platforms:os",
)
else:
native.alias(
name = os,
actual = constraint,
)

for arch, constraint in HELM_ARCH_CONSTRAINTS.items():
if constraint.startswith("@com_github_yujunz_rules_helm//helm/toolchain:"):
native.constraint_value(
name = arch,
constraint_setting = "@bazel_tools//platforms:cpu",
)
else:
native.alias(
name = arch,
actual = constraint,
)

for p in PLATFORMS:
native.platform(
name = p.name,
constraint_values = p.constraints,
)

0 comments on commit a3e132a

Please sign in to comment.