From 652aa3cc57c6f4d5b72491f1ad3fc44ac8ab7780 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Tue, 3 May 2022 16:38:30 +0800 Subject: [PATCH] feat(cli): new command upgrade - Add .gitignore file - Upgrade actions in CI.yml - Using the new cross compile image for x86_64-linux-gnu and aarch64-linux-gnu --- .github/workflows/docker.yaml | 8 ++ cli/src/new/.gitignore-template.ts | 190 +++++++++++++++++++++++++++++ cli/src/new/ci-template.ts | 83 ++++++------- cli/src/new/index.ts | 2 + cli/src/new/package.ts | 2 +- debian-aarch64.Dockerfile | 35 ++++++ debian.Dockerfile | 18 +-- 7 files changed, 282 insertions(+), 56 deletions(-) create mode 100644 cli/src/new/.gitignore-template.ts create mode 100644 debian-aarch64.Dockerfile diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 5e1bb5cc..d450c206 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -41,6 +41,14 @@ jobs: push: true tags: ghcr.io/${{ github.repository }}/nodejs-rust:lts-debian + - name: Build and push debian aarch64 cross + uses: docker/build-push-action@v2 + with: + file: debian-aarch64.Dockerfile + platforms: linux/amd64 + push: true + tags: ghcr.io/${{ github.repository }}/nodejs-rust:lts-debian-aarch64 + - name: Build and push debian with zig uses: docker/build-push-action@v2 with: diff --git a/cli/src/new/.gitignore-template.ts b/cli/src/new/.gitignore-template.ts new file mode 100644 index 00000000..313b28a2 --- /dev/null +++ b/cli/src/new/.gitignore-template.ts @@ -0,0 +1,190 @@ +export const GitIgnore = `# Created by https://www.toptal.com/developers/gitignore/api/node +# Edit at https://www.toptal.com/developers/gitignore?templates=node + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# Next.js build output +.next + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# End of https://www.toptal.com/developers/gitignore/api/node + +# Created by https://www.toptal.com/developers/gitignore/api/macos +# Edit at https://www.toptal.com/developers/gitignore?templates=macos + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +# End of https://www.toptal.com/developers/gitignore/api/macos + +# Created by https://www.toptal.com/developers/gitignore/api/windows +# Edit at https://www.toptal.com/developers/gitignore?templates=windows + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/windows + +#Added by cargo + +/target +Cargo.lock + +*.node +` diff --git a/cli/src/new/ci-template.ts b/cli/src/new/ci-template.ts index 44622e94..c51743f1 100644 --- a/cli/src/new/ci-template.ts +++ b/cli/src/new/ci-template.ts @@ -46,12 +46,11 @@ jobs: architecture: 'x86' - host: ubuntu-latest target: 'x86_64-unknown-linux-gnu' - docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine-zig + docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian build: >- set -e &&\n - rustup target add x86_64-unknown-linux-gnu &&\n - yarn build --target x86_64-unknown-linux-gnu --zig --zig-abi-suffix 2.12 &&\n - llvm-strip -x *.node + yarn build --target x86_64-unknown-linux-gnu &&\n + strip *.node - host: ubuntu-latest target: 'x86_64-unknown-linux-musl' docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine @@ -71,12 +70,11 @@ jobs: strip -x *.node - host: ubuntu-latest target: 'aarch64-unknown-linux-gnu' - docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine-zig + docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64 build: >- set -e &&\n - rustup target add aarch64-unknown-linux-gnu &&\n - yarn build --target aarch64-unknown-linux-gnu --zig --zig-abi-suffix 2.17 &&\n - llvm-strip -x *.node + yarn build --target aarch64-unknown-linux-gnu &&\n + aarch64-unknown-linux-gnu-strip *.node - host: ubuntu-latest architecture: 'x64' target: 'armv7-unknown-linux-gnueabihf' @@ -144,26 +142,21 @@ jobs: toolchain: stable target: \${{ matrix.settings.target }} - - name: Generate Cargo.lock - uses: actions-rs/cargo@v1 - if: \${{ !matrix.settings.docker }} - with: - command: generate-lockfile - - name: Cache cargo - uses: actions/cache@v2 + uses: actions/cache@v3 with: - path: ~/.cargo/registry - key: \${{ matrix.settings.target }}-cargo-registry - - - name: Cache cargo index - uses: actions/cache@v2 - with: - path: ~/.cargo/git - key: \${{ matrix.settings.target }}-cargo-index + path: | + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + .cargo-cache/registry/index/ + .cargo-cache/registry/cache/ + .cargo-cache/git/db/ + target/ + key: \${{ matrix.settings.target }}-cargo-\${{ matrix.settings.host }} - name: Cache NPM dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: node_modules key: npm-cache-build-\${{ matrix.settings.target }}-node@16 @@ -181,7 +174,7 @@ jobs: if: \${{ matrix.settings.docker }} with: image: \${{ matrix.settings.docker }} - options: -v \${{ env.HOME }}/.cargo/git:/root/.cargo/git -v \${{ env.HOME }}/.cargo/registry:/root/.cargo/registry -v \${{ github.workspace }}:/build -w /build + options: --user 0:0 -v \${{ github.workspace }}/.cargo-cache/git/db:/root/.cargo/git/db -v \${{ github.workspace }}/.cargo/registry/cache:/root/.cargo/registry/cache -v \${{ github.workspace }}/.cargo/registry/index:/root/.cargo/registry/index -v \${{ github.workspace }}:/build -w /build run: \${{ matrix.settings.build }} - name: 'Build' @@ -190,7 +183,7 @@ jobs: shell: bash - name: Upload artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: bindings-\${{ matrix.settings.target }} path: \${{ env.APP_NAME }}.*.node @@ -258,7 +251,7 @@ jobs: target: 'x86_64-apple-darwin' - host: windows-latest target: 'x86_64-pc-windows-msvc' - node: ['12', '14', '16'] + node: ['14', '16', '18'] runs-on: \${{ matrix.settings.host }} steps: @@ -272,7 +265,7 @@ jobs: cache: 'yarn' - name: Cache NPM dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: node_modules key: npm-cache-test-\${{ matrix.settings.target }}-\${{ matrix.node }}-\${{ hashFiles('yarn.lock') }} @@ -300,7 +293,7 @@ jobs: strategy: fail-fast: false matrix: - node: ['12', '14', '16'] + node: ['14', '16', '18'] runs-on: ubuntu-latest steps: @@ -314,10 +307,10 @@ jobs: cache: 'yarn' - name: Cache NPM dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: node_modules - key: npm-cache-test-linux-x64-gnu-\${{ matrix.node }}-\${{ hashFiles('yarn.lock') }} + key: npm-cache-test-linux-x64-gnu-\${{ matrix.node }} - name: 'Install dependencies' run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 @@ -342,7 +335,7 @@ jobs: strategy: fail-fast: false matrix: - node: ['12', '14', '16'] + node: ['14', '16', '18'] runs-on: ubuntu-latest steps: @@ -356,10 +349,10 @@ jobs: cache: 'yarn' - name: Cache NPM dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: node_modules - key: npm-cache-test-x86_64-unknown-linux-musl-\${{ matrix.node }}-\${{ hashFiles('yarn.lock') }} + key: npm-cache-test-x86_64-unknown-linux-musl-\${{ matrix.node }} - name: 'Install dependencies' run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 @@ -384,7 +377,7 @@ jobs: strategy: fail-fast: false matrix: - node: ['12', '14', '16'] + node: ['14', '16', '18'] runs-on: ubuntu-latest steps: @@ -403,10 +396,10 @@ jobs: shell: bash - name: Cache NPM dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: node_modules - key: npm-cache-test-linux-aarch64-gnu-\${{ matrix.node }}-\${{ hashFiles('yarn.lock') }} + key: npm-cache-test-linux-aarch64-gnu-\${{ matrix.node }} - name: Install dependencies run: yarn install --ignore-scripts --ignore-platform --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 @@ -444,10 +437,10 @@ jobs: shell: bash - name: Cache NPM dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: node_modules - key: npm-cache-test-linux-aarch64-musl-\${{ matrix.node }}-\${{ hashFiles('yarn.lock') }} + key: npm-cache-test-linux-aarch64-musl-\${{ matrix.node }} - name: Install dependencies run: yarn install --ignore-scripts --ignore-platform --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 @@ -469,7 +462,7 @@ jobs: strategy: fail-fast: false matrix: - node: ['12', '14', '16'] + node: ['14', '16', '18'] runs-on: ubuntu-latest steps: @@ -488,10 +481,10 @@ jobs: shell: bash - name: Cache NPM dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: node_modules - key: npm-cache-test-linux-arm-gnueabihf-\${{ matrix.node }}-\${{ hashFiles('yarn.lock') }} + key: npm-cache-test-linux-arm-gnueabihf-\${{ matrix.node }} - name: Install dependencies run: yarn install --ignore-scripts --ignore-platform --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 @@ -529,12 +522,10 @@ jobs: cache: 'yarn' - name: Cache NPM dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: node_modules - key: npm-cache-ubuntu-latest-\${{ hashFiles('yarn.lock') }} - restore-keys: | - npm-cache- + key: npm-cache-ubuntu-latest-publish - name: 'Install dependencies' run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 diff --git a/cli/src/new/index.ts b/cli/src/new/index.ts index e17b3680..aff44658 100644 --- a/cli/src/new/index.ts +++ b/cli/src/new/index.ts @@ -9,6 +9,7 @@ import { CreateNpmDirCommand } from '../create-npm-dir' import { debugFactory } from '../debug' import { DefaultPlatforms } from '../parse-triple' +import { GitIgnore } from './.gitignore-template' import { createCargoContent } from './cargo' import { createCargoConfig } from './cargo-config' import { createGithubActionsCIYml } from './ci-yml' @@ -200,6 +201,7 @@ test('sum from native', (t) => { edition = "2021" `, ) + this.writeFile('.gitignore', GitIgnore) } private writeFile(path: string, content: string) { diff --git a/cli/src/new/package.ts b/cli/src/new/package.ts index 85fcea09..cd04f3b8 100644 --- a/cli/src/new/package.ts +++ b/cli/src/new/package.ts @@ -17,7 +17,7 @@ export const createPackageJson = ( license: 'MIT', devDependencies: { '@napi-rs/cli': `^${version}`, - ava: '^4.0.1', + ava: '^4.2.0', }, engines: { node: '>= 10', diff --git a/debian-aarch64.Dockerfile b/debian-aarch64.Dockerfile new file mode 100644 index 00000000..30d52a0c --- /dev/null +++ b/debian-aarch64.Dockerfile @@ -0,0 +1,35 @@ +FROM messense/manylinux2014-cross:aarch64 + +ENV RUSTUP_HOME=/usr/local/rustup \ + CARGO_HOME=/usr/local/cargo \ + PATH=/usr/local/cargo/bin:$PATH \ + CC=clang \ + CXX=clang++ \ + CC_aarch64_unknown_linux_gnu=clang \ + CXX_aarch64_unknown_linux_gnu=clang++ + +RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \ + echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main" >> /etc/apt/sources.list && \ + echo "deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main" >> /etc/apt/sources.list && \ + curl -sL https://deb.nodesource.com/setup_16.x | bash - && \ + apt-get install -y --fix-missing --no-install-recommends \ + curl \ + llvm-14 \ + clang-14 \ + lld-14 \ + nodejs \ + xz-utils \ + rcs \ + git \ + make \ + ninja-build && \ + apt-get autoremove -y && \ + curl https://sh.rustup.rs -sSf | sh -s -- -y && \ + rustup target add aarch64-unknown-linux-gnu && \ + npm install -g yarn pnpm lerna && \ + npm cache clean --force && \ + npm cache verify && \ + ln -sf /usr/bin/clang-14 /usr/bin/clang && \ + ln -sf /usr/bin/clang++-14 /usr/bin/clang++ && \ + ln -sf /usr/bin/lld-14 /usr/bin/lld && \ + ln -sf /usr/bin/clang-14 /usr/bin/cc diff --git a/debian.Dockerfile b/debian.Dockerfile index 6f205d01..b4636833 100644 --- a/debian.Dockerfile +++ b/debian.Dockerfile @@ -11,14 +11,14 @@ ENV RUSTUP_HOME=/usr/local/rustup \ CXX_x86_64_unknown_linux_gnu=clang++ RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \ - echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-13 main" >> /etc/apt/sources.list && \ - echo "deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-13 main" >> /etc/apt/sources.list && \ + echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main" >> /etc/apt/sources.list && \ + echo "deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main" >> /etc/apt/sources.list && \ curl -sL https://deb.nodesource.com/setup_16.x | bash - && \ apt-get install -y --fix-missing --no-install-recommends \ curl \ - llvm-13 \ - clang-13 \ - lld-13 \ + llvm-14 \ + clang-14 \ + lld-14 \ nodejs \ xz-utils \ rcs \ @@ -34,10 +34,10 @@ RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \ rustup target add aarch64-unknown-linux-gnu && \ rustup target add armv7-unknown-linux-gnueabihf && \ npm install -g yarn pnpm lerna && \ - ln -sf /usr/bin/clang-13 /usr/bin/clang && \ - ln -sf /usr/bin/clang++-13 /usr/bin/clang++ && \ - ln -sf /usr/bin/lld-13 /usr/bin/lld && \ - ln -sf /usr/bin/clang-13 /usr/bin/cc + ln -sf /usr/bin/clang-14 /usr/bin/clang && \ + ln -sf /usr/bin/clang++-14 /usr/bin/clang++ && \ + ln -sf /usr/bin/lld-14 /usr/bin/lld && \ + ln -sf /usr/bin/clang-14 /usr/bin/cc RUN wget https://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/nasm-${NASM_VERSION}.tar.xz && \ tar -xf nasm-${NASM_VERSION}.tar.xz && \