Skip to content

Commit

Permalink
fix: allow cypress to run on m1 macs (#3088)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
CooperBills authored and alexeagle committed Dec 18, 2021
1 parent 8bbf4a2 commit ac96783
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 8 deletions.
1 change: 1 addition & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 14 additions & 2 deletions docs/Cypress.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ Defaults to `None`

<pre>
cypress_repositories(<a href="#cypress_repositories-name">name</a>, <a href="#cypress_repositories-version">version</a>, <a href="#cypress_repositories-linux_urls">linux_urls</a>, <a href="#cypress_repositories-linux_sha256">linux_sha256</a>, <a href="#cypress_repositories-darwin_urls">darwin_urls</a>, <a href="#cypress_repositories-darwin_sha256">darwin_sha256</a>,
<a href="#cypress_repositories-windows_urls">windows_urls</a>, <a href="#cypress_repositories-windows_sha256">windows_sha256</a>)
<a href="#cypress_repositories-darwin_arm64_urls">darwin_arm64_urls</a>, <a href="#cypress_repositories-darwin_arm64_sha256">darwin_arm64_sha256</a>, <a href="#cypress_repositories-windows_urls">windows_urls</a>, <a href="#cypress_repositories-windows_sha256">windows_sha256</a>)
</pre>

Repository rule used to install cypress binary.
Expand Down Expand Up @@ -390,7 +390,7 @@ Defaults to `""`

<h4 id="cypress_repositories-darwin_urls">darwin_urls</h4>

(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 `[]`

Expand All @@ -400,6 +400,18 @@ Defaults to `[]`

Defaults to `""`

<h4 id="cypress_repositories-darwin_arm64_urls">darwin_arm64_urls</h4>

(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 `[]`

<h4 id="cypress_repositories-darwin_arm64_sha256">darwin_arm64_sha256</h4>

(Optional) SHA-256 of the darwin arm64 cypress binary

Defaults to `""`

<h4 id="cypress_repositories-windows_urls">windows_urls</h4>

(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.
Expand Down
16 changes: 14 additions & 2 deletions docs/Toolchains.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Defaults to `{}`

<pre>
cypress_repositories(<a href="#cypress_repositories-name">name</a>, <a href="#cypress_repositories-version">version</a>, <a href="#cypress_repositories-linux_urls">linux_urls</a>, <a href="#cypress_repositories-linux_sha256">linux_sha256</a>, <a href="#cypress_repositories-darwin_urls">darwin_urls</a>, <a href="#cypress_repositories-darwin_sha256">darwin_sha256</a>,
<a href="#cypress_repositories-windows_urls">windows_urls</a>, <a href="#cypress_repositories-windows_sha256">windows_sha256</a>)
<a href="#cypress_repositories-darwin_arm64_urls">darwin_arm64_urls</a>, <a href="#cypress_repositories-darwin_arm64_sha256">darwin_arm64_sha256</a>, <a href="#cypress_repositories-windows_urls">windows_urls</a>, <a href="#cypress_repositories-windows_sha256">windows_sha256</a>)
</pre>

Repository rule used to install cypress binary.
Expand Down Expand Up @@ -188,7 +188,7 @@ Defaults to `""`

<h4 id="cypress_repositories-darwin_urls">darwin_urls</h4>

(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 `[]`

Expand All @@ -198,6 +198,18 @@ Defaults to `[]`

Defaults to `""`

<h4 id="cypress_repositories-darwin_arm64_urls">darwin_arm64_urls</h4>

(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 `[]`

<h4 id="cypress_repositories-darwin_arm64_sha256">darwin_arm64_sha256</h4>

(Optional) SHA-256 of the darwin arm64 cypress binary

Defaults to `""`

<h4 id="cypress_repositories-windows_urls">windows_urls</h4>

(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.
Expand Down
1 change: 1 addition & 0 deletions examples/cypress/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 15 additions & 2 deletions toolchains/cypress/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]]
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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 = [
Expand Down
34 changes: 32 additions & 2 deletions toolchains/cypress/cypress_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def cypress_repositories(
linux_sha256 = "",
darwin_urls = [],
darwin_sha256 = "",
darwin_arm64_urls = [],
darwin_arm64_sha256 = "",
windows_urls = [],
windows_sha256 = ""):
"""
Expand All @@ -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
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))

0 comments on commit ac96783

Please sign in to comment.