From e0212fa841a32179d3dacadd2ec02b417cb2db28 Mon Sep 17 00:00:00 2001 From: Christopher Dignam Date: Sun, 16 Jun 2024 21:45:43 -0400 Subject: [PATCH] fix macOS build for x64 and arm64 (#356) fix #355 I had trouble getting linux to build for arm64, so I gave up for now --- .github/workflows/rust.yml | 36 ++++++++++++++----- CHANGELOG.md | 6 ++++ Cargo.lock | 28 +++++++++------ cli/Cargo.toml | 2 +- flake.nix | 2 +- js/install.js | 18 +++++----- package.json | 2 +- parser/Cargo.toml | 2 +- ...r__parse__tests__parse_sql_query_json.snap | 2 +- rust-toolchain.toml | 2 +- 10 files changed, 66 insertions(+), 34 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 3f6bf2c0..2f7e2a68 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -20,10 +20,11 @@ jobs: with: paths_ignore: '["docs/**", "*.md"]' - build-linux: + build-linux-x64: needs: pre_job if: needs.pre_job.outputs.should_skip != 'true' || startsWith(github.ref, 'refs/tags/') + name: Linux x86_64 runs-on: ubuntu-latest steps: @@ -32,25 +33,30 @@ jobs: - name: Install Toolchain uses: oxidecomputer/actions-rs_toolchain@ad3f86084a8a5acf2c09cb691421b31cf8af7a36 # pin@oxide/master + with: + toolchain: stable + target: x86_64-unknown-linux-gnu + profile: minimal + override: true - name: Cache uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # pin@v2 - name: Build - run: RUSTFLAGS='-C target-feature=+crt-static' cargo build --target x86_64-unknown-linux-gnu --all --release && ls target && mv target/x86_64-unknown-linux-gnu/release/squawk target/release/squawk-linux-x86_64 + run: cargo build --target x86_64-unknown-linux-gnu --release && mv target/x86_64-unknown-linux-gnu/release/squawk target/release/squawk-linux-x64 - name: Artifact uses: actions/upload-artifact@v3 with: name: release - path: target/release/squawk-linux-x86_64 + path: target/release/squawk-linux-x64 - name: Release uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # pin@v1 if: startsWith(github.ref, 'refs/tags/') with: files: | - target/release/squawk-linux-x86_64 + target/release/squawk-linux-x64 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -61,6 +67,16 @@ jobs: needs: pre_job if: needs.pre_job.outputs.should_skip != 'true' || startsWith(github.ref, 'refs/tags/') + strategy: + fail-fast: false + matrix: + include: + - arch: x64 + target: x86_64-apple-darwin + - arch: arm64 + target: aarch64-apple-darwin + + name: macOS ${{ matrix.arch }} runs-on: macos-latest steps: @@ -69,31 +85,35 @@ jobs: - name: Install Toolchain uses: oxidecomputer/actions-rs_toolchain@ad3f86084a8a5acf2c09cb691421b31cf8af7a36 # pin@oxide/master + with: + target: ${{ matrix.target }} + profile: minimal + override: true - name: Cache uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # pin@v2 - name: Build for mac - run: cargo build --all --release && mv target/release/squawk target/release/squawk-darwin-x86_64 + run: cargo build --release --target=${{ matrix.target }} && mv target/${{ matrix.target }}/release/squawk target/release/squawk-darwin-${{ matrix.arch }} - name: Artifact uses: actions/upload-artifact@v3 with: name: release - path: target/release/squawk-darwin-x86_64 + path: target/release/squawk-darwin-${{ matrix.arch }} - name: Release uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # pin@v1 if: startsWith(github.ref, 'refs/tags/') with: files: | - target/release/squawk-darwin-x86_64 + target/release/squawk-darwin-${{ matrix.arch }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} publish-npm: if: startsWith(github.ref, 'refs/tags/') - needs: [build-linux, build-mac] + needs: [build-linux-x64, build-mac] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e633a6e..342d03d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## v1.1.1 - 2024-06-16 + +### Fixed + +- fix build for macos arm64 (#356) + ## v1.1.0 - 2024-06-13 ### Changed diff --git a/Cargo.lock b/Cargo.lock index 4adce4cf..f0b45be6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -141,9 +141,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.73" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" [[package]] name = "cexpr" @@ -424,6 +424,12 @@ dependencies = [ "percent-encoding 2.1.0", ] +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "fuchsia-cprng" version = "0.1.1" @@ -727,11 +733,13 @@ dependencies = [ [[package]] name = "libpg_query-sys" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "848f284a5fcc6220619f8a2779d5f856364357e24ce8763e7a2173fdb4651e3e" +version = "0.4.0" +source = "git+https://github.com/chdsbd/libpg_query-sys.git?rev=f4584dcbcb8c1f3bee550477257e84a846fdd92d#f4584dcbcb8c1f3bee550477257e84a846fdd92d" dependencies = [ "bindgen", + "cc", + "fs_extra", + "glob", "make-cmd", ] @@ -1097,9 +1105,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ] @@ -1116,9 +1124,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.20" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -1534,7 +1542,7 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "squawk" -version = "1.1.0" +version = "1.1.1" dependencies = [ "atty", "base64 0.12.3", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index fb3caf73..35b451a7 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "squawk" -version = "1.1.0" +version = "1.1.1" authors = ["Steve Dignam "] edition = "2018" license = "GPL-3.0" diff --git a/flake.nix b/flake.nix index bbf51db4..49291c82 100644 --- a/flake.nix +++ b/flake.nix @@ -18,7 +18,7 @@ { squawk = final.rustPlatform.buildRustPackage { pname = "squawk"; - version = "1.1.0"; + version = "1.1.1"; cargoLock = { lockFile = ./Cargo.lock; diff --git a/js/install.js b/js/install.js index f2ca4843..f01f84b3 100644 --- a/js/install.js +++ b/js/install.js @@ -46,19 +46,17 @@ const { binaryPath } = require("./helpers") // e.g.: https://github.com/sbdchd/squawk/releases/download/v0.1.3/squawk-darwin-x86_64 const RELEASES_BASE_URL = "https://github.com/sbdchd/squawk/releases/download" +const SUPPORTED_PLATFORMS = new Set(["darmin-x64", "darwin-arm64", "linux-x64"]) + /** * @param {string} platform + * @param {string} arch */ -function getDownloadUrl(platform) { - const releasesUrl = `${RELEASES_BASE_URL}/v${pkgInfo.version}/squawk` - switch (platform) { - case "darwin": - return `${releasesUrl}-darwin-x86_64` - case "linux": - return `${releasesUrl}-linux-x86_64` - default: - return null +function getDownloadUrl(platform, arch) { + if (!SUPPORTED_PLATFORMS.has(`${platform}-${arch}`)) { + return null } + return `${RELEASES_BASE_URL}/v${pkgInfo.version}/squawk-${platform}-${arch}` } function getNpmCache() { @@ -107,7 +105,7 @@ function getDecompressor(response) { function downloadBinary() { const arch = os.arch() const platform = os.platform() - const downloadUrl = getDownloadUrl(platform) + const downloadUrl = getDownloadUrl(platform, arch) if (!downloadUrl) { return Promise.reject(new Error(`unsupported target ${platform}-${arch}`)) } diff --git a/package.json b/package.json index 77ae3e04..4c9365d7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "squawk-cli", - "version": "1.1.0", + "version": "1.1.1", "description": "linter for PostgreSQL, focused on migrations", "repository": "git@github.com:sbdchd/squawk.git", "author": "Steve Dignam ", diff --git a/parser/Cargo.toml b/parser/Cargo.toml index c52c57ec..d4c66e05 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -12,7 +12,7 @@ keywords = ["postgres", "sql", "parser"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -libpg_query-sys = "0.3.1" +libpg_query-sys = { git = "https://github.com/chdsbd/libpg_query-sys.git", rev = "f4584dcbcb8c1f3bee550477257e84a846fdd92d" } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } serde_repr = "0.1" diff --git a/parser/src/snapshots/squawk_parser__parse__tests__parse_sql_query_json.snap b/parser/src/snapshots/squawk_parser__parse__tests__parse_sql_query_json.snap index 2264e569..60b4810c 100644 --- a/parser/src/snapshots/squawk_parser__parse__tests__parse_sql_query_json.snap +++ b/parser/src/snapshots/squawk_parser__parse__tests__parse_sql_query_json.snap @@ -133,7 +133,7 @@ Ok( }), ]), "version": Number( - 150001, + 160001, ), }), ) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 7507887a..aa20aabd 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -targets = ["x86_64-unknown-linux-gnu"] +targets = ["x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "aarch64-apple-darwin"] channel = "1.67.0"