From ac96783c18dcc9558deb9067ca281fe801e1da73 Mon Sep 17 00:00:00 2001
From: Cooper Bills <5051159+CooperBills@users.noreply.github.com>
Date: Tue, 7 Dec 2021 11:48:02 -0800
Subject: [PATCH] fix: allow cypress to run on m1 macs (#3088)
* fix: allow cypress to run on m1 macs
* fix: add additional cypress toolchain for darwin_arm64
* docs: update documentation for darwin_arm64 parameters in cypress_repositories
---
WORKSPACE | 1 +
docs/Cypress.md | 16 ++++++++--
docs/Toolchains.md | 16 ++++++++--
examples/cypress/WORKSPACE | 1 +
toolchains/cypress/BUILD.bazel | 17 +++++++++--
toolchains/cypress/cypress_repositories.bzl | 34 +++++++++++++++++++--
6 files changed, 77 insertions(+), 8 deletions(-)
diff --git a/WORKSPACE b/WORKSPACE
index a91b82f575..ca8cee2dc5 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -121,6 +121,7 @@ load("//packages/cypress:index.bzl", "cypress_repositories")
cypress_repositories(
name = "cypress",
+ darwin_arm64_sha256 = "101a0ced77fb74b356800cb3a3919f5288d23cc63fdd39a0c500673159e954fc",
darwin_sha256 = "101a0ced77fb74b356800cb3a3919f5288d23cc63fdd39a0c500673159e954fc",
linux_sha256 = "d8ea8d16fed33fdae8f17178bcae076aaf532fa7ccb48f377df1f143e60abd59",
version = "7.3.0",
diff --git a/docs/Cypress.md b/docs/Cypress.md
index 8363c6845b..5b2992cd19 100755
--- a/docs/Cypress.md
+++ b/docs/Cypress.md
@@ -356,7 +356,7 @@ Defaults to `None`
cypress_repositories(name, version, linux_urls, linux_sha256, darwin_urls, darwin_sha256,
- windows_urls, windows_sha256)
+ darwin_arm64_urls, darwin_arm64_sha256, windows_urls, windows_sha256)
Repository rule used to install cypress binary.
@@ -390,7 +390,7 @@ Defaults to `""`
darwin_urls
-(Optional) URLs at which the cypress binary for darwin distros of linux can be downloaded. If omitted, https://cdn.cypress.io/desktop will be used.
+(Optional) URLs at which the cypress binary for darwin can be downloaded. If omitted, https://cdn.cypress.io/desktop will be used.
Defaults to `[]`
@@ -400,6 +400,18 @@ Defaults to `[]`
Defaults to `""`
+darwin_arm64_urls
+
+(Optional) URLs at which the cypress binary for darwin arm64 can be downloaded. If omitted, https://cdn.cypress.io/desktop will be used (note: as of this writing (11/2021), Cypress does not have native arm64 builds, and this URL will link to the x86_64 build to run under Rosetta).
+
+Defaults to `[]`
+
+darwin_arm64_sha256
+
+(Optional) SHA-256 of the darwin arm64 cypress binary
+
+Defaults to `""`
+
windows_urls
(Optional) URLs at which the cypress binary for windows distros of linux can be downloaded. If omitted, https://cdn.cypress.io/desktop will be used.
diff --git a/docs/Toolchains.md b/docs/Toolchains.md
index 88848b8338..a9e3bd2e05 100644
--- a/docs/Toolchains.md
+++ b/docs/Toolchains.md
@@ -154,7 +154,7 @@ Defaults to `{}`
cypress_repositories(name, version, linux_urls, linux_sha256, darwin_urls, darwin_sha256,
- windows_urls, windows_sha256)
+ darwin_arm64_urls, darwin_arm64_sha256, windows_urls, windows_sha256)
Repository rule used to install cypress binary.
@@ -188,7 +188,7 @@ Defaults to `""`
darwin_urls
-(Optional) URLs at which the cypress binary for darwin distros of linux can be downloaded. If omitted, https://cdn.cypress.io/desktop will be used.
+(Optional) URLs at which the cypress binary for darwin can be downloaded. If omitted, https://cdn.cypress.io/desktop will be used.
Defaults to `[]`
@@ -198,6 +198,18 @@ Defaults to `[]`
Defaults to `""`
+darwin_arm64_urls
+
+(Optional) URLs at which the cypress binary for darwin arm64 can be downloaded. If omitted, https://cdn.cypress.io/desktop will be used (note: as of this writing (11/2021), Cypress does not have native arm64 builds, and this URL will link to the x86_64 build to run under Rosetta).
+
+Defaults to `[]`
+
+darwin_arm64_sha256
+
+(Optional) SHA-256 of the darwin arm64 cypress binary
+
+Defaults to `""`
+
windows_urls
(Optional) URLs at which the cypress binary for windows distros of linux can be downloaded. If omitted, https://cdn.cypress.io/desktop will be used.
diff --git a/examples/cypress/WORKSPACE b/examples/cypress/WORKSPACE
index e7b96f6839..0a811053e1 100644
--- a/examples/cypress/WORKSPACE
+++ b/examples/cypress/WORKSPACE
@@ -49,6 +49,7 @@ load("@build_bazel_rules_nodejs//toolchains/cypress:cypress_repositories.bzl", "
cypress_repositories(
name = "cypress",
+ darwin_arm64_sha256 = "101a0ced77fb74b356800cb3a3919f5288d23cc63fdd39a0c500673159e954fc",
darwin_sha256 = "101a0ced77fb74b356800cb3a3919f5288d23cc63fdd39a0c500673159e954fc",
linux_sha256 = "d8ea8d16fed33fdae8f17178bcae076aaf532fa7ccb48f377df1f143e60abd59",
version = "7.3.0",
diff --git a/toolchains/cypress/BUILD.bazel b/toolchains/cypress/BUILD.bazel
index b112c168a9..1d59a2f043 100644
--- a/toolchains/cypress/BUILD.bazel
+++ b/toolchains/cypress/BUILD.bazel
@@ -28,6 +28,7 @@ toolchain_type(name = "toolchain_type")
cypress_files = "@cypress_%s//:files" % os_name,
) for os_name in [
"darwin",
+ "darwin_arm64",
"linux",
"windows",
]]
@@ -37,7 +38,8 @@ toolchain_type(name = "toolchain_type")
alias(
name = "toolchain",
actual = select({
- "@bazel_tools//src/conditions:darwin": ":cypress_darwin_toolchain_config",
+ "@bazel_tools//src/conditions:darwin_x86_64": ":cypress_darwin_toolchain_config",
+ "@bazel_tools//src/conditions:darwin_arm64": ":cypress_darwin_arm64_toolchain_config",
"@bazel_tools//src/conditions:linux_x86_64": ":cypress_linux_toolchain_config",
"@bazel_tools//src/conditions:windows": ":cypress_windows_toolchain_config",
"//conditions:default": ":cypress_linux_toolchain_config",
@@ -49,7 +51,8 @@ alias(
alias(
name = "cypress_bin",
actual = select({
- "@bazel_tools//src/conditions:darwin": "@cypress_darwin//:bin",
+ "@bazel_tools//src/conditions:darwin_x86_64": "@cypress_darwin//:bin",
+ "@bazel_tools//src/conditions:darwin_arm64": "@cypress_darwin_arm64//:bin",
"@bazel_tools//src/conditions:linux_x86_64": "@cypress_linux//:bin",
"@bazel_tools//src/conditions:windows": "@cypress_windows//:bin",
"//conditions:default": "@cypress_linux//:bin",
@@ -77,6 +80,16 @@ toolchain(
toolchain_type = ":toolchain_type",
)
+toolchain(
+ name = "cypress_darwin_arm64_toolchain",
+ target_compatible_with = [
+ "@platforms//os:osx",
+ "@platforms//cpu:arm64",
+ ],
+ toolchain = ":cypress_darwin_arm64_toolchain_config",
+ toolchain_type = ":toolchain_type",
+)
+
toolchain(
name = "cypress_windows_toolchain",
target_compatible_with = [
diff --git a/toolchains/cypress/cypress_repositories.bzl b/toolchains/cypress/cypress_repositories.bzl
index a55f43f40d..a0a4ef9444 100644
--- a/toolchains/cypress/cypress_repositories.bzl
+++ b/toolchains/cypress/cypress_repositories.bzl
@@ -24,6 +24,8 @@ def cypress_repositories(
linux_sha256 = "",
darwin_urls = [],
darwin_sha256 = "",
+ darwin_arm64_urls = [],
+ darwin_arm64_sha256 = "",
windows_urls = [],
windows_sha256 = ""):
"""
@@ -34,8 +36,10 @@ def cypress_repositories(
version: Version of cypress binary to use. Should match package.json
linux_urls: (Optional) URLs at which the cypress binary for linux distros of linux can be downloaded. If omitted, https://cdn.cypress.io/desktop will be used.
linux_sha256: (Optional) SHA-256 of the linux cypress binary
- darwin_urls: (Optional) URLs at which the cypress binary for darwin distros of linux can be downloaded. If omitted, https://cdn.cypress.io/desktop will be used.
+ darwin_urls: (Optional) URLs at which the cypress binary for darwin can be downloaded. If omitted, https://cdn.cypress.io/desktop will be used.
darwin_sha256: (Optional) SHA-256 of the darwin cypress binary
+ darwin_arm64_urls: (Optional) URLs at which the cypress binary for darwin arm64 can be downloaded. If omitted, https://cdn.cypress.io/desktop will be used (note: as of this writing (11/2021), Cypress does not have native arm64 builds, and this URL will link to the x86_64 build to run under Rosetta).
+ darwin_arm64_sha256: (Optional) SHA-256 of the darwin arm64 cypress binary
windows_urls: (Optional) URLs at which the cypress binary for windows distros of linux can be downloaded. If omitted, https://cdn.cypress.io/desktop will be used.
windows_sha256: (Optional) SHA-256 of the windows cypress binary
"""
@@ -74,6 +78,32 @@ filegroup(
visibility = ["//visibility:public"],
)
+filegroup(
+ name = "bin",
+ # Cypress checks that the binary path matches **/Contents/MacOS/Cypress
+ srcs = ["Cypress.app/Contents/MacOS/Cypress"],
+ visibility = ["//visibility:public"],
+)
+""",
+ )
+
+ http_archive(
+ name = "cypress_darwin_arm64".format(name),
+ sha256 = darwin_arm64_sha256,
+ # Cypress checks that the binary path matches **/Contents/MacOS/Cypress so we do not strip that particular prefix.
+ urls = darwin_arm64_urls + [
+ # Note: there is currently no arm64 builds of cypress, so here we'll default to
+ # the x64 version so apple silicon macs can run the binary using Rosetta.
+ # Once a native arm64 build is available, this should be updated
+ "https://cdn.cypress.io/desktop/{}/darwin-x64/cypress.zip".format(version),
+ ],
+ build_file_content = """
+filegroup(
+ name = "files",
+ srcs = ["Cypress.app"],
+ visibility = ["//visibility:public"],
+)
+
filegroup(
name = "bin",
# Cypress checks that the binary path matches **/Contents/MacOS/Cypress
@@ -105,6 +135,6 @@ filegroup(
)
# This needs to be setup so toolchains can access nodejs for all different versions
- for os_name in ["windows", "darwin", "linux"]:
+ for os_name in ["windows", "darwin", "darwin_arm64", "linux"]:
toolchain_label = Label("@build_bazel_rules_nodejs//toolchains/cypress:cypress_{}_toolchain".format(os_name))
native.register_toolchains("@{}//{}:{}".format(toolchain_label.workspace_name, toolchain_label.package, toolchain_label.name))