Skip to content

Commit 5d2ae2e

Browse files
committed
windows support
1 parent e2d375d commit 5d2ae2e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+663
-227
lines changed

.bazelrc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Bazel settings that apply to this repository.
22
# Take care to document any settings that you expect users to apply.
33
# Settings that apply only to CI are in .github/workflows/ci.bazelrc
4+
common --enable_platform_specific_config
45

56
build --incompatible_strict_action_env
67
build --nolegacy_external_runfiles
78
common --test_env=DOCKER_HOST --action_env=DOCKER_HOST --repo_env=DOCKER_HOST
9+
common --test_env=APPDATA --action_env=APPDATA --repo_env=APPDATA
10+
common --test_env=PROGRAMDATA --action_env=PROGRAMDATA --repo_env=PROGRAMDATA
811

9-
# On bazel 6.4.0 these are needed to successfully fetch images.
12+
# On bazel 6.5.0 these are needed to successfully fetch images.
1013
common:needs_credential_helpers --credential_helper=public.ecr.aws=%workspace%/examples/credential_helper/auth.sh
1114
common:needs_credential_helpers --credential_helper=index.docker.io=%workspace%/examples/credential_helper/auth.sh
1215
common:needs_credential_helpers --credential_helper=docker.elastic.co=%workspace%/examples/credential_helper/auth.sh
@@ -17,6 +20,14 @@ common:needs_credential_helpers --credential_helper_cache_duration=0
1720
# https://bazelbuild.slack.com/archives/C014RARENH0/p1691158021917459?thread_ts=1691156601.420349&cid=C014RARENH0
1821
common --check_direct_dependencies=off
1922

23+
# Symlinks are pretty much required on windows so enable by default
24+
startup --windows_enable_symlinks
25+
26+
# Point tools such as coursier (used in rules_jvm_external) to Bazel's downloaded JDK
27+
# suggested in https://github.com/bazelbuild/rules_jvm_external/issues/445
28+
common --repo_env=JAVA_HOME=../bazel_tools/jdk
29+
common --action_env=JAVA_HOME=../bazel_tools/jdk
30+
2031
# Load any settings specific to the current user.
2132
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
2233
# This needs to be last statement in this

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
7.4.1
1+
7.6.1
22

33
# The first line of this file is used by Bazelisk and Bazel to be sure
44
# the right version of Bazel is used to build and test this repo.

.github/workflows/ci.yaml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ jobs:
2626
- id: bazel_7
2727
run: echo "bazelversion=$(head -n 1 .bazelversion)" >> $GITHUB_OUTPUT
2828
- id: bazel_6
29-
run: echo "bazelversion=6.4.0" >> $GITHUB_OUTPUT
29+
run: echo "bazelversion=6.5.0" >> $GITHUB_OUTPUT
3030
outputs:
31-
# Will look like ["<version from .bazelversion>", "6.4.0"]
31+
# Will look like ["<version from .bazelversion>", "6.5.0"]
3232
bazelversions: ${{ toJSON(steps.*.outputs.bazelversion) }}
3333

3434
matrix-prep-os:
@@ -43,8 +43,10 @@ jobs:
4343
run: echo "os=macos-13" >> $GITHUB_OUTPUT
4444
# Don't run MacOS if there is no TestContainers API token which is the case on forks. We need it for container tests.
4545
if: ${{ env.TC_CLOUD_TOKEN != '' }}
46+
- id: windows
47+
run: echo "os=windows" >> $GITHUB_OUTPUT
4648
outputs:
47-
# Will look like ["ubuntu-latest", "macos-13"]
49+
# Will look like ["ubuntu-latest", "macos-13", "windows"]
4850
os: ${{ toJSON(steps.*.outputs.os) }}
4951

5052
test:
@@ -74,13 +76,15 @@ jobs:
7476
- os: macos-13
7577
folder: e2e/assertion
7678
- os: macos-13
77-
bazelversion: 6.4.0
79+
bazelversion: 6.5.0
80+
- os: windows
81+
bazelversion: 6.5.0
7882
- folder: .
79-
bazelversion: 6.4.0
83+
bazelversion: 6.5.0
8084
- folder: examples/dockerfile
8185
bzlmodEnabled: false
8286
- folder: examples/dockerfile
83-
bazelversion: 6.4.0
87+
bazelversion: 6.5.0
8488
# e2e/assertion is bzlmod only but it has test for both cases.
8589
- folder: e2e/assertion
8690
bzlmodEnabled: false
@@ -121,12 +125,12 @@ jobs:
121125
# Add --config needs_credential_helpers to add additional credential helpers
122126
# to fetch from registries with HTTP headers set by credential helpers.
123127
id: set_credential_helper_flag
124-
if: matrix.bazelversion == '6.4.0' && matrix.folder == '.'
128+
if: matrix.bazelversion == '6.5.0' && matrix.folder == '.'
125129
run: echo "credential_helper_flag=--config=needs_credential_helpers" >> $GITHUB_OUTPUT
126130

127131
- name: Setup crane for credential helpers to use
128132
uses: imjasonh/setup-crane@v0.3
129-
if: matrix.bazelversion == '6.4.0' && matrix.folder == '.'
133+
if: matrix.bazelversion == '6.5.0' && matrix.folder == '.'
130134
with:
131135
version: "v0.19.1"
132136

MODULE.bazel

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
module(
44
name = "rules_oci",
5+
bazel_compatibility = [">=6.5.0"],
56
compatibility_level = 1,
67
)
78

8-
bazel_dep(name = "aspect_bazel_lib", version = "2.7.2")
9+
bazel_dep(name = "aspect_bazel_lib", version = "2.21.0")
910
bazel_dep(name = "bazel_features", version = "1.10.0")
1011
bazel_dep(name = "bazel_skylib", version = "1.8.1")
1112
bazel_dep(name = "platforms", version = "0.0.8")
13+
bazel_dep(name = "tar.bzl", version = "0.5.5")
1214

1315
oci = use_extension("//oci:extensions.bzl", "oci")
1416
oci.toolchains()

cosign/private/attest.bzl

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"Implementation details for attest rule"
22

3+
load("@aspect_bazel_lib//lib:paths.bzl", "BASH_RLOCATION_FUNCTION", "to_rlocation_path")
4+
load("@aspect_bazel_lib//lib:windows_utils.bzl", "create_windows_native_launcher_script")
5+
36
_DOC = """Attest an oci_image using cosign binary at a remote registry.
47
58
```starlark
@@ -52,8 +55,17 @@ _attrs = {
5255
Digests and tags are not allowed. If this attribute is not set, the repository must be passed at runtime via the `--repository` flag.
5356
"""),
5457
"_attest_sh_tpl": attr.label(default = "attest.sh.tpl", allow_single_file = True),
58+
"_runfiles": attr.label(default = "@bazel_tools//tools/bash/runfiles"),
5559
}
5660

61+
def _windows_host(ctx):
62+
"""Returns true if the host platform is windows.
63+
64+
The typical approach using ctx.target_platform_has_constraint does not work for transitioned
65+
build targets. We need to know the host platform, not the target platform.
66+
"""
67+
return ctx.configuration.host_path_separator == ";"
68+
5769
def _cosign_attest_impl(ctx):
5870
cosign = ctx.toolchains["@rules_oci//cosign:toolchain_type"]
5971
jq = ctx.toolchains["@aspect_bazel_lib//lib:jq_toolchain_type"]
@@ -63,31 +75,34 @@ def _cosign_attest_impl(ctx):
6375

6476
fixed_args = [
6577
"--predicate",
66-
ctx.file.predicate.short_path,
78+
to_rlocation_path(ctx, ctx.file.predicate),
6779
"--type",
6880
ctx.attr.type,
6981
]
7082
if ctx.attr.repository:
7183
fixed_args.extend(["--repository", ctx.attr.repository])
7284

73-
executable = ctx.actions.declare_file("cosign_attest_{}.sh".format(ctx.label.name))
85+
bash_launcher = ctx.actions.declare_file("cosign_attest_{}.sh".format(ctx.label.name))
7486
ctx.actions.expand_template(
7587
template = ctx.file._attest_sh_tpl,
76-
output = executable,
88+
output = bash_launcher,
7789
is_executable = True,
7890
substitutions = {
79-
"{{cosign_path}}": cosign.cosign_info.binary.short_path,
80-
"{{jq_path}}": jq.jqinfo.bin.short_path,
81-
"{{image_dir}}": ctx.file.image.short_path,
91+
"{{BASH_RLOCATION_FUNCTION}}": BASH_RLOCATION_FUNCTION,
92+
"{{cosign_path}}": to_rlocation_path(ctx, cosign.cosign_info.binary),
93+
"{{jq_path}}": to_rlocation_path(ctx, jq.jqinfo.bin),
94+
"{{image_dir}}": to_rlocation_path(ctx, ctx.file.image),
8295
"{{fixed_args}}": " ".join(fixed_args),
8396
"{{type}}": ctx.attr.type,
8497
},
8598
)
8699

87-
runfiles = ctx.runfiles(files = [ctx.file.image, ctx.file.predicate])
100+
executable = create_windows_native_launcher_script(ctx, bash_launcher) if _windows_host(ctx) else bash_launcher
101+
runfiles = ctx.runfiles(files = [ctx.file.image, ctx.file.predicate, bash_launcher])
88102
runfiles = runfiles.merge(ctx.attr.image[DefaultInfo].default_runfiles)
89103
runfiles = runfiles.merge(jq.default.default_runfiles)
90104
runfiles = runfiles.merge(cosign.default.default_runfiles)
105+
runfiles = runfiles.merge(ctx.attr._runfiles.default_runfiles)
91106

92107
return DefaultInfo(executable = executable, runfiles = runfiles)
93108

@@ -97,6 +112,7 @@ cosign_attest = rule(
97112
doc = _DOC,
98113
executable = True,
99114
toolchains = [
115+
"@bazel_tools//tools/sh:toolchain_type",
100116
"@rules_oci//cosign:toolchain_type",
101117
"@aspect_bazel_lib//lib:jq_toolchain_type",
102118
],

cosign/private/attest.sh.tpl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/usr/bin/env bash
22
set -o pipefail -o errexit -o nounset
33

4-
readonly COSIGN="{{cosign_path}}"
5-
readonly JQ="{{jq_path}}"
6-
readonly IMAGE_DIR="{{image_dir}}"
4+
{{BASH_RLOCATION_FUNCTION}}
5+
6+
readonly COSIGN="$(rlocation "{{cosign_path}}")"
7+
readonly JQ="$(rlocation "{{jq_path}}")"
8+
readonly IMAGE_DIR="$(rlocation "{{image_dir}}")"
79
readonly DIGEST=$("${JQ}" -r '.manifests[].digest' "${IMAGE_DIR}/index.json")
810
readonly FIXED_ARGS=({{fixed_args}})
911

@@ -15,11 +17,14 @@ fi
1517

1618
REPOSITORY=""
1719
ARGS=()
20+
PREDICATE=""
1821

1922
while (( $# > 0 )); do
2023
case "$1" in
2124
--repository) shift; REPOSITORY="$1"; shift ;;
2225
(--repository=*) REPOSITORY="${1#--repository=}"; shift ;;
26+
--predicate) shift; PREDICATE="$(rlocation "$1")"; shift ;;
27+
(--predicate=*) PREDICATE="$(rlocation "${1#--predicate=}")"; shift ;;
2328
*) ARGS+=( "$1" ); shift ;;
2429
esac
2530
done
@@ -29,5 +34,5 @@ if [[ -z "${REPOSITORY}" ]]; then
2934
exit 1
3035
fi
3136

32-
exec "${COSIGN}" attest "${REPOSITORY}@${DIGEST}" ${ARGS[@]+"${ARGS[@]}"}
37+
exec "${COSIGN}" attest "${REPOSITORY}@${DIGEST}" --predicate "${PREDICATE}" ${ARGS[@]+"${ARGS[@]}"}
3338

cosign/private/sign.bzl

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"Implementation details for sign rule"
22

3+
load("@aspect_bazel_lib//lib:paths.bzl", "BASH_RLOCATION_FUNCTION", "to_rlocation_path")
4+
load("@aspect_bazel_lib//lib:windows_utils.bzl", "create_windows_native_launcher_script")
5+
36
_DOC = """Sign an oci_image using cosign binary at a remote registry.
47
58
It signs the image by its digest determined beforehand.
@@ -48,37 +51,49 @@ _attrs = {
4851
Digests and tags are not allowed. If this attribute is not set, the repository must be passed at runtime via the `--repository` flag.
4952
"""),
5053
"_sign_sh_tpl": attr.label(default = "sign.sh.tpl", allow_single_file = True),
54+
"_runfiles": attr.label(default = "@bazel_tools//tools/bash/runfiles"),
5155
}
5256

57+
def _windows_host(ctx):
58+
"""Returns true if the host platform is windows.
59+
60+
The typical approach using ctx.target_platform_has_constraint does not work for transitioned
61+
build targets. We need to know the host platform, not the target platform.
62+
"""
63+
return ctx.configuration.host_path_separator == ";"
64+
5365
def _cosign_sign_impl(ctx):
5466
cosign = ctx.toolchains["@rules_oci//cosign:toolchain_type"]
5567
jq = ctx.toolchains["@aspect_bazel_lib//lib:jq_toolchain_type"]
5668

5769
if ctx.attr.repository and (ctx.attr.repository.find(":") != -1 or ctx.attr.repository.find("@") != -1):
5870
fail("repository attribute should not contain digest or tag.")
5971

60-
executable = ctx.actions.declare_file("cosign_sign_{}.sh".format(ctx.label.name))
72+
bash_launcher = ctx.actions.declare_file("cosign_sign_{}.sh".format(ctx.label.name))
6173

6274
fixed_args = []
6375
if ctx.attr.repository:
6476
fixed_args.extend(["--repository", ctx.attr.repository])
6577

6678
ctx.actions.expand_template(
6779
template = ctx.file._sign_sh_tpl,
68-
output = executable,
80+
output = bash_launcher,
6981
is_executable = True,
7082
substitutions = {
71-
"{{cosign_path}}": cosign.cosign_info.binary.short_path,
72-
"{{jq_path}}": jq.jqinfo.bin.short_path,
73-
"{{image_dir}}": ctx.file.image.short_path,
83+
"{{BASH_RLOCATION_FUNCTION}}": BASH_RLOCATION_FUNCTION,
84+
"{{cosign_path}}": to_rlocation_path(ctx, cosign.cosign_info.binary),
85+
"{{jq_path}}": to_rlocation_path(ctx, jq.jqinfo.bin),
86+
"{{image_dir}}": to_rlocation_path(ctx, ctx.file.image),
7487
"{{fixed_args}}": " ".join(fixed_args),
7588
},
7689
)
7790

78-
runfiles = ctx.runfiles(files = [ctx.file.image])
91+
executable = create_windows_native_launcher_script(ctx, bash_launcher) if _windows_host(ctx) else bash_launcher
92+
runfiles = ctx.runfiles(files = [ctx.file.image, bash_launcher])
7993
runfiles = runfiles.merge(ctx.attr.image[DefaultInfo].default_runfiles)
8094
runfiles = runfiles.merge(jq.default.default_runfiles)
8195
runfiles = runfiles.merge(cosign.default.default_runfiles)
96+
runfiles = runfiles.merge(ctx.attr._runfiles.default_runfiles)
8297

8398
return DefaultInfo(executable = executable, runfiles = runfiles)
8499

@@ -88,6 +103,7 @@ cosign_sign = rule(
88103
doc = _DOC,
89104
executable = True,
90105
toolchains = [
106+
"@bazel_tools//tools/sh:toolchain_type",
91107
"@rules_oci//cosign:toolchain_type",
92108
"@aspect_bazel_lib//lib:jq_toolchain_type",
93109
],

cosign/private/sign.sh.tpl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/usr/bin/env bash
22
set -o pipefail -o errexit -o nounset
33

4-
readonly COSIGN="{{cosign_path}}"
5-
readonly JQ="{{jq_path}}"
6-
readonly IMAGE_DIR="{{image_dir}}"
4+
{{BASH_RLOCATION_FUNCTION}}
5+
6+
readonly COSIGN="$(rlocation "{{cosign_path}}")"
7+
readonly JQ="$(rlocation "{{jq_path}}")"
8+
readonly IMAGE_DIR="$(rlocation "{{image_dir}}")"
79
readonly DIGEST=$("${JQ}" -r '.manifests[].digest' "${IMAGE_DIR}/index.json")
810
readonly FIXED_ARGS=({{fixed_args}})
911

cosign/private/versions.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ COSIGN_VERSIONS = {
1818
"linux-arm64": "sha256-sIjWdvDAEjuMNI4Y1CHPlmAg7cSXekhhFaEmQ96pmj8=",
1919
"linux-ppc64le": "sha256-IaAWkdvfyzUbTpTM9QGk6HNyLPX+b2epc172bstBlB0=",
2020
"linux-s390x": "sha256-1yzyiRkNKMacuVxeMhOaoZgf/KCoQyfImgErsfOoBR0=",
21+
"windows-amd64": "sha256-9/Jy1WxYCw7Jb1m/6fiOxfQrbhld8AnONBdCjg4N6tE=",
22+
"windows-arm64": "sha256-Adj8SzLWM8E5KqJkrtIlPB4ML7CSFvjizCabs7i7SbU=",
2123
},
2224
"v2.0.2": {
2325
"darwin-amd64": "sha256-D1HL4ZoxW5GehwQvBIUzGCFyLst/ziLMG4gO1IM/yLA=",

cosign/repositories.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def _cosign_repo_impl(repository_ctx):
2020
version = repository_ctx.attr.cosign_version,
2121
platform = platform,
2222
)
23+
if ("windows" in repository_ctx.attr.platform):
24+
url += ".exe"
2325
repository_ctx.download(
2426
url = url,
2527
output = "cosign",

0 commit comments

Comments
 (0)