Skip to content
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

fix: Configure target_compatible_with toolchain to allow for cross-building #93

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 5 additions & 17 deletions cypress/BUILD.cypress
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@ load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
# Copy the cypress binary directory to make it RBE compatible.
copy_directory(
name = "cypress_binary",
src = select({
"@bazel_tools//src/conditions:darwin": "Cypress.app",
"//conditions:default": "Cypress",
}),
out = select({
"@bazel_tools//src/conditions:darwin": "Cypress.app",
"//conditions:default": "Cypress",
}),
src = "%{COPY_DIRECTORY_SRC}",
out = "Cypress",
tags = ["manual"]
)

Expand All @@ -27,18 +21,12 @@ copy_to_bin(

filegroup(
name = "files",
srcs = select({
"@bazel_tools//src/conditions:darwin": ["Cypress.app", "binary_state.json"],
"//conditions:default": [":cypress_binary", ":binary_state_file"]
}),
srcs = [":cypress_binary", ":binary_state_file"],
visibility = ["//visibility:public"],
)

cypress_toolchain(
name = "cypress_toolchain",
target_tool = select({
"@bazel_tools//src/conditions:darwin": "Cypress.app/Contents/MacOS/Cypress",
"//conditions:default": "Cypress/Cypress",
}),
target_tool = "%{TARGET_TOOL}",
target_tool_files = ":files",
)
)
6 changes: 6 additions & 0 deletions cypress/private/toolchains_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ toolchain(
toolchain = "@{user_repository_name}_{platform}//:cypress_toolchain",
toolchain_type = "@aspect_rules_cypress//cypress:toolchain_type",
)
toolchain(
name = "{platform}_toolchain_target",
target_compatible_with = {compatible_with},
toolchain = "@{user_repository_name}_{platform}//:cypress_toolchain",
toolchain_type = "@aspect_rules_cypress//cypress:toolchain_type",
)
""".format(
platform = platform,
name = repository_ctx.attr.name,
Expand Down
8 changes: 7 additions & 1 deletion cypress/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ def _cypress_repo_impl(repository_ctx):
repository_ctx.file("binary_state.json", binary_state_json_contents)

# Base BUILD file for this repository
repository_ctx.template("BUILD.bazel", Label("//cypress:BUILD.cypress"))
is_darwin = repository_ctx.attr.platform.startswith("darwin")
substitution = {
"%{COPY_DIRECTORY_SRC}": "Cypress.app" if is_darwin else "Cypress",
"%{TARGET_TOOL}": "Cypress/Contents/MacOS/Cypress" if is_darwin else "Cypress/Cypress",
}
repository_ctx.template("BUILD.bazel", Label("//cypress:BUILD.cypress"), substitution)

cypress_repositories = repository_rule(
_cypress_repo_impl,
Expand Down Expand Up @@ -86,6 +91,7 @@ Alternately, you may manually specify platform integrity hashes with cypress_int
)
if register:
native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform))
native.register_toolchains("@%s_toolchains//:%s_toolchain_target" % (name, platform))

toolchains_repo(
name = name + "_toolchains",
Expand Down