From 7642fda99f7f45eefee4c8a49f0a2cfde7bc2a66 Mon Sep 17 00:00:00 2001 From: Andrew Hlynskyi Date: Tue, 11 Apr 2023 09:48:48 +0300 Subject: [PATCH] cli: npm - strict platform / arch mapping for provided targets --- .github/workflows/build.yml | 9 ++++--- cli/npm/install.js | 48 ++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d76fb853..fc45f778 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,7 @@ jobs: fail-fast: false matrix: runtime: - - linux-aarch64 # + - linux-arm64 # - linux-arm # - linux-x64 # - linux-x86 # @@ -31,7 +31,10 @@ jobs: - macos-x64 # include: - - { runtime: linux-aarch64 , target: aarch64-unknown-linux-gnu , os: ubuntu-latest , use-cross: true } + # When adding a new `target`: + # 1. Define a new runtime alias above + # 2. Add a new record to a matrix map in `cli/npm/install.js` + - { runtime: linux-arm64 , target: aarch64-unknown-linux-gnu , os: ubuntu-latest , use-cross: true } - { runtime: linux-arm , target: arm-unknown-linux-gnueabihf , os: ubuntu-latest , use-cross: true } - { runtime: linux-x64 , target: x86_64-unknown-linux-gnu , os: ubuntu-latest } - { runtime: linux-x86 , target: i686-unknown-linux-gnu , os: ubuntu-latest , use-cross: true } @@ -41,7 +44,7 @@ jobs: - { runtime: macos-x64 , target: x86_64-apple-darwin , os: macos-latest } # Cross compilers for C library - - { runtime: linux-aarch64 , cc: aarch64-linux-gnu-gcc , ar: aarch64-linux-gnu-ar } + - { runtime: linux-arm64 , cc: aarch64-linux-gnu-gcc , ar: aarch64-linux-gnu-ar } - { runtime: linux-arm , cc: arm-unknown-linux-gnueabihf-gcc , ar: arm-unknown-linux-gnueabihf-gcc-ar } - { runtime: linux-x86 , cc: i686-linux-gnu-gcc , ar: i686-linux-gnu-ar } diff --git a/cli/npm/install.js b/cli/npm/install.js index 9e572c3a..e343158b 100755 --- a/cli/npm/install.js +++ b/cli/npm/install.js @@ -6,21 +6,41 @@ const http = require('http'); const https = require('https'); const packageJSON = require('./package.json'); +// Look to a results table in https://github.com/tree-sitter/tree-sitter/issues/2196 +const matrix = { + platform: { + 'darwin': { + name: 'macos', + arch: { + 'arm64': { name: 'arm64' }, + 'x64': { name: 'x64' }, + } + }, + 'linux': { + name: 'linux', + arch: { + 'arm64': { name: 'arm64' }, + 'arm': { name: 'arm' }, + 'x64': { name: 'x64' }, + 'x86': { name: 'x86' }, + } + }, + 'win32': { + name: 'windows', + arch: { + 'x64': { name: 'x64' }, + 'x86': { name: 'x86' }, + 'ia32': { name: 'x86' }, + } + }, + }, +} + // Determine the URL of the file. -const platformName = { - 'darwin': 'macos', - 'linux': 'linux', - 'win32': 'windows' -}[process.platform]; +const platform = matrix.platform[process.platform]; +const arch = platform && platform.arch[process.arch]; -let archName = { - 'x64': 'x64', - 'x86': 'x86', - 'ia32': 'x86', - 'arm64': 'arm64' -}[process.arch]; - -if (!platformName || !archName) { +if (!platform || !platform.name || !arch || !arch.name) { console.error( `Cannot install tree-sitter-cli for platform ${process.platform}, architecture ${process.arch}` ); @@ -28,7 +48,7 @@ if (!platformName || !archName) { } const releaseURL = `https://github.com/tree-sitter/tree-sitter/releases/download/v${packageJSON.version}`; -const assetName = `tree-sitter-${platformName}-${archName}.gz`; +const assetName = `tree-sitter-${platform.name}-${arch.name}.gz`; const assetURL = `${releaseURL}/${assetName}`; // Remove previously-downloaded files.