From 2d011922f8047736b50fbdd8de1c46ee37cef631 Mon Sep 17 00:00:00 2001 From: Simon Hailes Date: Fri, 1 Nov 2024 10:25:52 +0000 Subject: [PATCH 1/6] add library locations which work on macos-13 and macos-latest (arm64) --- prebuild/macOS/binding.gyp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/prebuild/macOS/binding.gyp b/prebuild/macOS/binding.gyp index 718844ac8..a10569ebc 100644 --- a/prebuild/macOS/binding.gyp +++ b/prebuild/macOS/binding.gyp @@ -34,6 +34,8 @@ ' Date: Fri, 1 Nov 2024 10:26:54 +0000 Subject: [PATCH 2/6] Add choice of prebuild to build. increase to build on node 22. add runner macos-latest. --- .github/workflows/prebuild.yaml | 104 ++++++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 6 deletions(-) diff --git a/.github/workflows/prebuild.yaml b/.github/workflows/prebuild.yaml index 48cc39cfa..7ed0a7caf 100644 --- a/.github/workflows/prebuild.yaml +++ b/.github/workflows/prebuild.yaml @@ -32,7 +32,21 @@ # "edit" and delete any assets that are in purgatory (have a /!\ next to them). name: Make Prebuilds -on: workflow_dispatch +on: + workflow_dispatch: + inputs: + os: + description: 'Target os' + required: true + type: choice + options: + - '["ubuntu-latest"]' + - '["windows-latest"]' + - '["macos-13"]' + - '["macos-latest"]' + - '["ubuntu-latest", "windows-latest", "macos-13", "macos-latest"]' + default: '["ubuntu-latest", "windows-latest", "macos-13", "macos-latest"]' + # UPLOAD_TO can be specified to upload the release assets under a different tag # name (e.g. for testing). If omitted, the assets are published under the same @@ -50,10 +64,11 @@ jobs: strategy: fail-fast: false matrix: - node: [21] + node: [22] canvas_tag: ["v3.0.0-rc2"] # e.g. "v2.6.1" name: ${{ matrix.canvas_tag }}, Node.js ${{ matrix.node }}, Linux runs-on: ubuntu-latest + if: contains(fromJson(inputs.os), 'ubuntu-latest') container: image: ${{ matrix.node < 18 && 'chearon/canvas-prebuilt:9' || 'zbbjornson/canvas-prebuilt:11' }} env: @@ -142,10 +157,86 @@ jobs: strategy: fail-fast: false matrix: - node: [21] + node: [22] canvas_tag: ["v3.0.0-rc2"] # e.g. "v2.6.1" name: ${{ matrix.canvas_tag}}, Node.js ${{ matrix.node }}, macOS - runs-on: macos-12 # macos-14+ is M1 + runs-on: macos-13 # macos-14+ is M1 + if: contains(fromJson(inputs.os), 'macos-13') + env: + CANVAS_VERSION_TO_BUILD: ${{ matrix.canvas_tag }} + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ matrix.canvas_tag }} + # Fetch all commits/all branches so we can checkout the prebuild + # branch's files + fetch-depth: 0 + + - uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + + - name: Build + run: | + set -Eeuxo pipefail + git checkout ${{ matrix.canvas_tag }} + git checkout $GITHUB_SHA -- prebuild/ + npm install -g node-gyp + npm install --ignore-scripts + . prebuild/macOS/preinstall.sh + cp prebuild/macOS/binding.gyp binding.gyp + node-gyp rebuild -j 2 + . prebuild/macOS/bundle.sh + + - name: Test binary + run: | + brew uninstall --force --ignore-dependencies cairo pango librsvg giflib harfbuzz + npm test + + - name: Make bundle + id: make_bundle + run: . prebuild/tarball.sh + + - name: Upload + uses: actions/github-script@v2 + with: + script: | + const fs = require("fs"); + const assetName = "${{ steps.make_bundle.outputs.asset_name }}"; + const tagName = process.env.UPLOAD_TO || process.env.CANVAS_VERSION_TO_BUILD; + const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/"); + + const releases = await github.repos.listReleases({owner, repo}); + const release = releases.data.find(r => r.tag_name === tagName); + if (!release) + throw new Error(`Tag ${tagName} not found. Did you make the GitHub release?`); + + const oldAsset = release.assets.find(a => a.name === assetName); + if (oldAsset) + await github.repos.deleteReleaseAsset({owner, repo, asset_id: oldAsset.id}); + + // (This is equivalent to actions/upload-release-asset. We're + // already in a script, so might as well do it here.) + const r = await github.repos.uploadReleaseAsset({ + url: release.upload_url, + headers: { + "content-type": "application/x-gzip", + "content-length": `${fs.statSync(assetName).size}` + }, + name: assetName, + data: fs.readFileSync(assetName) + }); + + + macOSarm: + strategy: + fail-fast: false + matrix: + node: [22] + canvas_tag: ["v3.0.0-rc2"] # e.g. "v2.6.1" + name: ${{ matrix.canvas_tag}}, Node.js ${{ matrix.node }}, macOS + runs-on: macos-latest # macos-14+ is M1 + if: contains(fromJson(inputs.os), 'macos-latest') env: CANVAS_VERSION_TO_BUILD: ${{ matrix.canvas_tag }} steps: @@ -215,10 +306,11 @@ jobs: strategy: fail-fast: false matrix: - node: [21] + node: [22] canvas_tag: ["v3.0.0-rc2"] # e.g. "v2.6.1" name: ${{ matrix.canvas_tag}}, Node.js ${{ matrix.node }}, Windows - runs-on: windows-2019 + runs-on: target-latest + if: contains(fromJson(inputs.os), 'windows-latest') env: CANVAS_VERSION_TO_BUILD: ${{ matrix.canvas_tag }} steps: From 25ebf706b5e5257f8b3b71f3c5359f4da6de9a48 Mon Sep 17 00:00:00 2001 From: Simon Hailes Date: Fri, 1 Nov 2024 11:05:06 +0000 Subject: [PATCH 3/6] fix typos (cherry picked from commit 25fe193fad30e50f355ccc90b0de75ec9b467ff9) --- .github/workflows/prebuild.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/prebuild.yaml b/.github/workflows/prebuild.yaml index 7ed0a7caf..44c9aebec 100644 --- a/.github/workflows/prebuild.yaml +++ b/.github/workflows/prebuild.yaml @@ -234,7 +234,7 @@ jobs: matrix: node: [22] canvas_tag: ["v3.0.0-rc2"] # e.g. "v2.6.1" - name: ${{ matrix.canvas_tag}}, Node.js ${{ matrix.node }}, macOS + name: ${{ matrix.canvas_tag}}, Node.js ${{ matrix.node }}, macOSarm64 runs-on: macos-latest # macos-14+ is M1 if: contains(fromJson(inputs.os), 'macos-latest') env: @@ -309,7 +309,7 @@ jobs: node: [22] canvas_tag: ["v3.0.0-rc2"] # e.g. "v2.6.1" name: ${{ matrix.canvas_tag}}, Node.js ${{ matrix.node }}, Windows - runs-on: target-latest + runs-on: windows-latest if: contains(fromJson(inputs.os), 'windows-latest') env: CANVAS_VERSION_TO_BUILD: ${{ matrix.canvas_tag }} From 4ea4200f74327f7a907dbcc377a2a89bfc8086c4 Mon Sep 17 00:00:00 2001 From: Simon Hailes Date: Fri, 1 Nov 2024 11:32:46 +0000 Subject: [PATCH 4/6] move macosarm above macos, just to make the commit look cleaner. --- .github/workflows/prebuild.yaml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/prebuild.yaml b/.github/workflows/prebuild.yaml index 44c9aebec..c8cd02a7e 100644 --- a/.github/workflows/prebuild.yaml +++ b/.github/workflows/prebuild.yaml @@ -152,16 +152,15 @@ jobs: name: assetName, data: fs.readFileSync(assetName) }); - - macOS: + macOSarm: strategy: fail-fast: false matrix: node: [22] canvas_tag: ["v3.0.0-rc2"] # e.g. "v2.6.1" - name: ${{ matrix.canvas_tag}}, Node.js ${{ matrix.node }}, macOS - runs-on: macos-13 # macos-14+ is M1 - if: contains(fromJson(inputs.os), 'macos-13') + name: ${{ matrix.canvas_tag}}, Node.js ${{ matrix.node }}, macOSarm64 + runs-on: macos-latest # macos-14+ is M1 + if: contains(fromJson(inputs.os), 'macos-latest') env: CANVAS_VERSION_TO_BUILD: ${{ matrix.canvas_tag }} steps: @@ -227,16 +226,16 @@ jobs: data: fs.readFileSync(assetName) }); - - macOSarm: + + macOS: strategy: fail-fast: false matrix: node: [22] canvas_tag: ["v3.0.0-rc2"] # e.g. "v2.6.1" - name: ${{ matrix.canvas_tag}}, Node.js ${{ matrix.node }}, macOSarm64 - runs-on: macos-latest # macos-14+ is M1 - if: contains(fromJson(inputs.os), 'macos-latest') + name: ${{ matrix.canvas_tag}}, Node.js ${{ matrix.node }}, macOS + runs-on: macos-13 # macos-14+ is M1 + if: contains(fromJson(inputs.os), 'macos-13') env: CANVAS_VERSION_TO_BUILD: ${{ matrix.canvas_tag }} steps: @@ -302,6 +301,7 @@ jobs: data: fs.readFileSync(assetName) }); + Win: strategy: fail-fast: false From fa6374f3c30a60849e34159da57b8e370b352b12 Mon Sep 17 00:00:00 2001 From: Simon Hailes Date: Fri, 1 Nov 2024 16:39:41 +0000 Subject: [PATCH 5/6] fix uploaded names --- prebuild/tarball.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/prebuild/tarball.sh b/prebuild/tarball.sh index 20aaa0b89..7d0d807ca 100644 --- a/prebuild/tarball.sh +++ b/prebuild/tarball.sh @@ -1,8 +1,11 @@ # Generate the prebuild-install formatted filename from the node environment +# match prebuild-install style. FILENAME=$( node -e " - var p = process, v = p.versions, libc = require('detect-libc').familySync() || 'unknown'; - if (libc === 'glibc') libc = ''; + var p = process, v = p.versions; + const detectLibc = require('detect-libc'); + const libc = process.env.LIBC || process.env.npm_config_libc || + (detectLibc.isNonGlibcLinuxSync() && detectLibc.familySync()) || '' const tagName = p.env.UPLOAD_TO || p.env.CANVAS_VERSION_TO_BUILD; console.log('canvas-' + tagName + '-napi-v7-' + p.platform + libc + '-' + p.arch); " From 94e61033890f6214f171d617a2a516a8d57ed78f Mon Sep 17 00:00:00 2001 From: Simon Hailes Date: Fri, 1 Nov 2024 16:55:15 +0000 Subject: [PATCH 6/6] Add to readme in prebuild branch --- README.md | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ceb76773c..40923150b 100644 --- a/README.md +++ b/README.md @@ -1 +1,94 @@ -This is the prebuild branch. The only directory used in it is prebuild/. Otherwise files are taken from the branch being built. \ No newline at end of file +This is the prebuild branch. + +The only directory used in it is prebuild/. + +Otherwise files are taken from the branch being built. + +# Changes: + +## 2024-11-01 btsimonh + +Added the below notes. + +Added macos arm64 prebuilds. + + + +# notes from prebuild.yml: + +``` +# Release procedure: +# 1. On the master branch, update the changelog and stage it in git. +# 2. Run `yarn version --[major|minor|patch]`. (This tags the commit.) +# 3. Push both the commit and tags to GitHub (`git push --tags Automattic` and +# `git push Automattic HEAD:master`, where "Automattic" is the remote name +# for git@github.com:Automattic/node-canvas.git). +# 4. Create a draft release manually using the GitHub UI for the new tag. +# 5. Switch to the prebuilds branch. +# 6. Set the `jobs.*.strategy.matrix.node` arrays to the set of Node.js versions +# to build for. +# 7. Set the `jobs.*.strategy.matrix.canvas_tag` arrays to the set of Canvas +# tags to build. (Usually this is a single tag, but can be an array when a +# new version of Node.js is released and older versions of Canvas need to be +# built.) +# 8. Commit this file and push. +# 9. In the Actions tab, navigate to the "Make Prebuilds" workflow and click +# "Run workflow". Select the `prebuilds` branch so that that branch's +# prebuild.yaml file is used. +# 10.Once the builds succeed, promote the draft release to a full release and +# run npm publish. + +# Note that the files in the prebuild/ directory will be used from the commit +# that was used to trigger the prebuild workflow. They will not be from the +# commit/tag that you are building. Because of differences in the provided +# versions of git, this is achieved in a different way on Linux than on Mac and +# Win. +# +# Pay particular attention to changes to binding.gyp on master. That file is not +# used! The ones in prebuild/**/ are. + +# Tip: If uploads are inexplicably failing, open the release in GitHub, click +# "edit" and delete any assets that are in purgatory (have a /!\ next to them). +``` + +### Prebuilding only a specific platform: + +When manually running `Make Prebuilds`, you should be asked for `Target os`. + +Select the single target os OR the default multiple OSes. + + +### prebuilding for your own repo. + +If you fork, and prebuild on your own repo, you will need to create a release based on a tag. + +Prebuild WILL checkout the tag you specify in the cavnas tag property for each OS, and will build THAT tag from master - not your master HEAD or another branch. + +e.g.: +``` + canvas_tag: ["vdev"] # e.g. "v2.6.1"` +``` + +Prebuild will upload the output to YOUR repo into the release you created. + +IF you want to USE your prebuilds, you would need to change (in package.json): +``` + "repository": "git://github.com/Automattic/node-canvas.git", +``` +and +``` + "version": "3.0.0-rc2", +``` +in the installed branch to reflect the repo you want to pull released prebuilds from, + +and for version, this MUST match your tag without 'v' prefix (e.g. a version of 'dev' needs a tag of 'vdev') + + + + + + + + + +