Skip to content

Commit

Permalink
feat: build MacOS arm64 binaries [HEAD-204] (#4890)
Browse files Browse the repository at this point in the history
* feat: build Snyk for MacOS arm64

* fix: usage of non existing variable

* chore: add no-bytcode for macos arm64

* feat: build + sign macos arm64

* feat: support macos arm64 via npm

* chore: add macos arm64 to release.json

* chore: add additional files for deployment

* chore: add macos arm64 support to install-snyk.py

* chore: use node version variable

* chore: temp fix for basic acceptance tests

* chore: remove installation of rosetta

---------

Co-authored-by: Catalina Oyaneder <[email protected]>
  • Loading branch information
PeterSchafer and cat2608 authored Oct 4, 2023
1 parent 1e1702c commit 08ed346
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 24 deletions.
58 changes: 43 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,11 @@ executors:
- image: ubuntu:focal
working_directory: /mnt/ramdisk/snyk
resource_class: arm.medium
macos-amd64:
macos:
# https://circleci.com/docs/2.0/testing-ios/#supported-xcode-versions
xcode: '14.3.1'
resource_class: macos.x86.medium.gen2
macos-arm64:
macos:
# https://circleci.com/docs/2.0/testing-ios/#supported-xcode-versions
xcode: '14.3.1'
resource_class: macos.m1.large.gen1
resource_class: macos.m1.medium.gen1
win-server2022-amd64:
machine:
image: windows-server-2022-gui:2023.07.1
Expand Down Expand Up @@ -279,6 +274,9 @@ commands:
type: string
default: go gradle python elixir composer gradle@6 maven sbt dotnet
steps:
- run:
name: Installing Rosetta
command: softwareupdate --install-rosetta --agree-to-license
- restore_cache:
key: acceptance-tests-macos-<< parameters.items >>
- run:
Expand All @@ -298,6 +296,9 @@ commands:
type: string
default: go gradle python elixir composer gradle@6 maven sbt dotnet
steps:
- run:
name: Installing Rosetta
command: softwareupdate --install-rosetta --agree-to-license
- install-deps-python:
os: macos

Expand Down Expand Up @@ -409,7 +410,18 @@ workflows:
go_os: darwin
go_arch: amd64
go_download_base_url: << pipeline.parameters.go_download_base_url >>
executor: macos-amd64
executor: macos-arm64
install_deps_extension: macos-build
requires:
- prepare-build

- build-artifact:
name: build macOS arm64
go_target_os: darwin
go_os: darwin
go_arch: arm64
go_download_base_url: << pipeline.parameters.go_download_base_url >>
executor: macos-arm64
install_deps_extension: macos-build
requires:
- prepare-build
Expand Down Expand Up @@ -502,9 +514,9 @@ workflows:
branches:
ignore: master
requires:
- build macOS amd64
executor: macos-amd64
test_snyk_command: ./binary-releases/snyk-macos
- build macOS arm64
executor: macos-arm64
test_snyk_command: ./binary-releases/snyk-macos-arm64
install_deps_extension: macos-full

- acceptance-tests:
Expand Down Expand Up @@ -546,7 +558,22 @@ workflows:
- build macOS amd64
go_os: darwin
go_arch: amd64
executor: macos-amd64
executor: macos-arm64
install_deps_extension: noop
filters:
branches:
only:
- master
- '/.*e2e.*/'

- sign:
name: sign macos arm64
context: snyk-macos-signing
requires:
- build macOS arm64
go_os: darwin
go_arch: arm64
executor: macos-arm64
install_deps_extension: noop
filters:
branches:
Expand All @@ -559,6 +586,7 @@ workflows:
context: snyk-cli-pgp-signing
requires:
- sign macos amd64
- sign macos arm64
- sign windows amd64
- build alpine amd64
- build linux amd64
Expand Down Expand Up @@ -600,7 +628,7 @@ workflows:
executor:
- 'docker-amd64'
- 'win-server2019-amd64'
- 'macos-amd64'
- 'macos-arm64'
requires:
- upload version
filters:
Expand All @@ -619,7 +647,7 @@ workflows:
- 'docker-arm64'
- 'win-server2019-amd64'
- 'win-server2022-amd64'
- 'macos-amd64'
- 'macos-arm64'
- 'linux-ubuntu-latest-amd64'
- 'linux-ubuntu-mantic-amd64'
- 'linux-ubuntu-jammy-amd64'
Expand Down Expand Up @@ -673,12 +701,12 @@ workflows:
requires:
- Validate NPM artifacts (docker-amd64)
- Validate NPM artifacts (win-server2019-amd64)
- Validate NPM artifacts (macos-amd64)
- Validate NPM artifacts (macos-arm64)
- e2e tests (docker-amd64)
- e2e tests (docker-arm64)
- e2e tests (win-server2019-amd64)
- e2e tests (win-server2022-amd64)
- e2e tests (macos-amd64)
- e2e tests (macos-arm64)
- e2e tests (linux-ubuntu-latest-amd64)
- e2e tests (linux-ubuntu-mantic-amd64)
- e2e tests (linux-ubuntu-jammy-amd64)
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ $(BINARY_RELEASES_FOLDER_TS_CLI)/snyk-macos: prepack | $(BINARY_RELEASES_FOLDER_
$(PKG) -t node$(PKG_NODE_VERSION)-macos-x64 -o $(BINARY_RELEASES_FOLDER_TS_CLI)/snyk-macos
$(MAKE) $(BINARY_RELEASES_FOLDER_TS_CLI)/snyk-macos.sha256

$(BINARY_RELEASES_FOLDER_TS_CLI)/snyk-macos-arm64: prepack | $(BINARY_RELEASES_FOLDER_TS_CLI)
$(PKG) -t node$(PKG_NODE_VERSION)-macos-arm64 -o $(BINARY_RELEASES_FOLDER_TS_CLI)/snyk-macos-arm64 --no-bytecode
$(MAKE) $(BINARY_RELEASES_FOLDER_TS_CLI)/snyk-macos-arm64.sha256

$(BINARY_RELEASES_FOLDER_TS_CLI)/snyk-win.exe: prepack | $(BINARY_RELEASES_FOLDER_TS_CLI)
$(PKG) -t node$(PKG_NODE_VERSION)-win-x64 -o $(BINARY_RELEASES_FOLDER_TS_CLI)/snyk-win.exe
powershell $(WORKING_DIR)/cliv2/scripts/sign_windows.ps1 $(BINARY_RELEASES_FOLDER_TS_CLI) snyk-win.exe
Expand Down
2 changes: 1 addition & 1 deletion binary-deployments.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"darwin": {
"amd64": "snyk-macos",
"arm64": "snyk-macos"
"arm64": "snyk-macos-arm64"
},
"windows": {
"amd64": "snyk-win.exe"
Expand Down
2 changes: 0 additions & 2 deletions cliv2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ _SEPARATOR = _

ifeq ($(_V1_OS), darwin)
_V1_OS = macos
#temporarily ignoring any architecture for macos v1 binaries, this will enable to natively compile v2 as darwin arm64 and bundle v1 as amd64
_V1_ARCH =
else ifeq ($(_V1_OS), windows)
_V1_OS = win
_EXE_POSTFIX = .exe
Expand Down
5 changes: 5 additions & 0 deletions release-scripts/release.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
"sha256": "snyk-macos-sha256",
"sha256Url": "https://static.snyk.io/cli/v1.0.0-monorepo/snyk-macos.sha256"
},
"snyk-macos-arm64 ": {
"url": "https://static.snyk.io/cli/v1.0.0-monorepo/snyk-macos-arm64",
"sha256": "snyk-macos-arm64-sha256",
"sha256Url": "https://static.snyk.io/cli/v1.0.0-monorepo/snyk-macos-arm64.sha256"
},
"snyk-win.exe": {
"url": "https://static.snyk.io/cli/v1.0.0-monorepo/snyk-win.exe",
"sha256": "snyk-win.exe-sha256",
Expand Down
2 changes: 2 additions & 0 deletions release-scripts/release.json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if [[ $(uname -s) == "Darwin" ]];then
sed -i "" "s|snyk-linux-sha256|$(cat binary-releases/snyk-linux.sha256)|" "${OUTPUT_FILE}"
sed -i "" "s|snyk-linux-arm64-sha256|$(cat binary-releases/snyk-linux-arm64.sha256)|" "${OUTPUT_FILE}"
sed -i "" "s|snyk-macos-sha256|$(cat binary-releases/snyk-macos.sha256)|" "${OUTPUT_FILE}"
sed -i "" "s|snyk-macos-arm64-sha256|$(cat binary-releases/snyk-macos-arm64.sha256)|" "${OUTPUT_FILE}"
sed -i "" "s|snyk-win.exe-sha256|$(cat binary-releases/snyk-win.exe.sha256)|" "${OUTPUT_FILE}"
else
echo "this is Linux"
Expand All @@ -20,6 +21,7 @@ else
sed -i "s|snyk-linux-sha256|$(cat binary-releases/snyk-linux.sha256)|" "${OUTPUT_FILE}"
sed -i "s|snyk-linux-arm64-sha256|$(cat binary-releases/snyk-linux-arm64.sha256)|" "${OUTPUT_FILE}"
sed -i "s|snyk-macos-sha256|$(cat binary-releases/snyk-macos.sha256)|" "${OUTPUT_FILE}"
sed -i "s|snyk-macos-arm64-sha256|$(cat binary-releases/snyk-macos-arm64.sha256)|" "${OUTPUT_FILE}"
sed -i "s|snyk-win.exe-sha256|$(cat binary-releases/snyk-win.exe.sha256)|" "${OUTPUT_FILE}"
fi

Expand Down
2 changes: 2 additions & 0 deletions release-scripts/upload-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ declare -a StaticFiles=(
"binary-releases/snyk-linux"
"binary-releases/snyk-linux-arm64"
"binary-releases/snyk-macos"
"binary-releases/snyk-macos-arm64"
"binary-releases/snyk-win.exe"
"binary-releases/snyk-alpine.sha256"
"binary-releases/snyk-linux.sha256"
"binary-releases/snyk-linux-arm64.sha256"
"binary-releases/snyk-macos.sha256"
"binary-releases/snyk-macos-arm64.sha256"
"binary-releases/snyk-win.exe.sha256"
"binary-releases/sha256sums.txt.asc"
)
Expand Down
4 changes: 3 additions & 1 deletion scripts/install-snyk.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ def get_filename(arch_type, os_type):
if os_type == 'windows' and arch_type == 'amd64':
filename = "snyk-win"
suffix = ".exe"
if os_type == 'macos':
if os_type == 'macos' and arch_type == 'amd64':
filename = "snyk-macos"
if os_type == 'macos' and arch_type == 'arm64':
filename = "snyk-macos-arm64"

filename = filename + suffix
output_filename = output_filename + suffix
Expand Down
3 changes: 2 additions & 1 deletion ts-binary-wrapper/test/acceptance/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ jest.setTimeout(60 * 1000);

describe('Basic acceptance test', () => {
const envSetup = new TestEnvironmentSetup();
const cliVersionForTesting = '1.1143.0';
const cliVersionForTesting =
'1.1228.0-dev.b6d3a5aed7033dd2fe9fcc1330effeca0e4250b2';

beforeEach(async () => {
process.env.SNYK_DISABLE_ANALYTICS = '1';
Expand Down
9 changes: 5 additions & 4 deletions ts-binary-wrapper/test/unit/common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ const supportedPlatforms = JSON.parse(binaryDeployments);

describe('Determine Binary Name', () => {
it('Determine Binary Name (darwin)', async () => {
const expected = supportedPlatforms['darwin']['amd64'];
const expectedamd64 = supportedPlatforms['darwin']['amd64'];
const expectedarm64 = supportedPlatforms['darwin']['arm64'];
const actualx64 = common.determineBinaryName('darwin', 'x64');
const actualarm64 = common.determineBinaryName('darwin', 'arm64');
const actualamd64 = common.determineBinaryName('darwin', 'amd64');
expect(actualx64).toEqual(expected);
expect(actualarm64).toEqual(expected);
expect(actualamd64).toEqual(expected);
expect(actualx64).toEqual(expectedamd64);
expect(actualarm64).toEqual(expectedarm64);
expect(actualamd64).toEqual(expectedamd64);
});

it('Determine Binary Name (win)', async () => {
Expand Down

0 comments on commit 08ed346

Please sign in to comment.