From 3f1a65005bfa2af4d57790d0420abd14ca2dd97c Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 27 Mar 2026 11:24:34 -0800 Subject: [PATCH] Allow setting the VS Code build target For the NPM package (and tests, at least for now), we will still use linux-x64, but this is going to allow using the platform build targets for our standalone releases so we can avoid having to copy all the packaging steps (like cleaning up modules). This does mean that the NPM package when installed will be missing those cleanup steps. Possibly we can try to break out the packaging step into a something that can be ran standalone (which will also require installing dev dependencies like gulp) but not sure how much work this would be. --- .github/workflows/build.yaml | 26 +++++++++++------------ .prettierignore | 3 +-- ci/build/build-release.sh | 7 ++++-- ci/build/build-vscode.sh | 12 ++++------- ci/lib.sh | 41 +++++++++++++++++++++++++++++++----- 5 files changed, 58 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 01b93e48a..228a14249 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -157,11 +157,14 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} build: - name: Build code-server + name: Build code-server npm package runs-on: ubuntu-22.04 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} DISABLE_V8_COMPILE_CACHE: 1 + VERSION: 0.0.0 + VSCODE_TARGET: linux-x64 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v6 with: @@ -181,34 +184,29 @@ jobs: test/package-lock.json - run: SKIP_SUBMODULE_DEPS=1 npm ci - run: npm run build - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Get Code's git hash. When this changes it means the content is # different and we need to rebuild. - name: Get latest lib/vscode rev id: vscode-rev run: echo "rev=$(git rev-parse HEAD:./lib/vscode)" >> $GITHUB_OUTPUT - # We need to rebuild when we have a new version of Code, when any of - # the patches changed, or when the code-server version changes (since - # it gets embedded into the code). Use VSCODE_CACHE_VERSION to - # force a rebuild. - - name: Fetch prebuilt Code package from cache + # We need to rebuild when we have a new version of Code, when any of the + # patches changed, or when the code-server version changes (since it gets + # embedded into the code). Use VSCODE_CACHE_VERSION to force a rebuild. + - name: Fetch prebuilt linux-x64 Code package from cache id: cache-vscode uses: actions/cache@v4 with: - path: lib/vscode-reh-web-* - key: vscode-reh-package-${{ secrets.VSCODE_CACHE_VERSION }}-${{ steps.vscode-rev.outputs.rev }}-${{ hashFiles('patches/*.diff', 'ci/build/build-vscode.sh') }} + path: lib/vscode-reh-web-linux-x64-min-ci + key: vscode-reh-linux-x64-package-${{ secrets.VSCODE_CACHE_VERSION }}-${{ steps.vscode-rev.outputs.rev }}-${{ hashFiles('patches/*.diff', 'ci/build/build-vscode.sh') }} - name: Build vscode - env: - VERSION: "0.0.0" if: steps.cache-vscode.outputs.cache-hit != 'true' run: | pushd lib/vscode npm ci popd npm run build:vscode - # The release package does not contain any native modules - # and is neutral to architecture/os/libc version. + # The release package is just the compiled code, does not contain any + # native modules, and is thus neutral to architecture/os/libc version. - run: npm run release if: success() # https://github.com/actions/upload-artifact/issues/38 diff --git a/.prettierignore b/.prettierignore index cd007ef32..28bd69f6b 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1,4 @@ -lib/vscode -lib/vscode-reh-web-linux-x64 +lib release-standalone release-packages release diff --git a/ci/build/build-release.sh b/ci/build/build-release.sh index 0d226fd83..96c6f7292 100755 --- a/ci/build/build-release.sh +++ b/ci/build/build-release.sh @@ -4,13 +4,16 @@ set -euo pipefail # Once both code-server and VS Code have been built, use this script to copy # them into a single directory (./release), prepare the package.json and # product.json, and add shrinkwraps. This results in a generic NPM package that -# we published to NPM and also use to compile platform-specific packages. +# we can publish to NPM. # MINIFY controls whether minified VS Code is bundled. It must match the value # used when VS Code was built. MINIFY="${MINIFY-true}" # node_modules are not copied by default. Set KEEP_MODULES=1 to copy them. +# Note these modules will be for the platform that built them, making the result +# no longer generic (it can still be published though as the modules will be +# ignored when pushing). KEEP_MODULES="${KEEP_MODULES-0}" main() { @@ -85,7 +88,7 @@ bundle_vscode() { rsync_opts+=(--exclude node_modules) fi - rsync "${rsync_opts[@]}" ./lib/vscode-reh-web-*/ "$VSCODE_OUT_PATH" + rsync "${rsync_opts[@]}" "./lib/vscode-reh-web-$VSCODE_TARGET/" "$VSCODE_OUT_PATH" # Merge the package.json for the web/remote server so we can include # dependencies, since we want to ship this via NPM. diff --git a/ci/build/build-vscode.sh b/ci/build/build-vscode.sh index 8bfee50a8..3b25d598a 100755 --- a/ci/build/build-vscode.sh +++ b/ci/build/build-vscode.sh @@ -7,12 +7,12 @@ set -euo pipefail MINIFY=${MINIFY-true} delete-bin-script() { - rm -f "lib/vscode-reh-web-linux-x64/bin/$1" + rm -f "lib/vscode-reh-web-$VSCODE_TARGET/bin/$1" } copy-bin-script() { local script="$1" - local dest="lib/vscode-reh-web-linux-x64/bin/$script" + local dest="lib/vscode-reh-web-$VSCODE_TARGET/bin/$script" cp "lib/vscode/resources/server/bin/$script" "$dest" sed -i.bak "s/@@VERSION@@/$(vscode_version)/g" "$dest" sed -i.bak "s/@@COMMIT@@/$BUILD_SOURCEVERSION/g" "$dest" @@ -108,12 +108,8 @@ main() { EOF ) > product.json - # Any platform here works since we will do our own packaging. We have to do - # this because we have an NPM package that could be installed on any platform. - # The correct platform dependencies and scripts will be installed as part of - # the post-install during `npm install` or when building a standalone release. npm run gulp core-ci - npm run gulp "vscode-reh-web-linux-x64${MINIFY:+-min}-ci" + npm run gulp "vscode-reh-web-$VSCODE_TARGET${MINIFY:+-min}-ci" # Reset so if you develop after building you will not be stuck with the wrong # commit (the dev client will use `oss-dev` but the dev server will still use @@ -122,7 +118,7 @@ EOF popd - pushd lib/vscode-reh-web-linux-x64 + pushd "lib/vscode-reh-web-$VSCODE_TARGET" # Make sure Code took the version we set in the environment variable. Not # having a version will break display languages. if ! jq -e .commit product.json; then diff --git a/ci/lib.sh b/ci/lib.sh index 2b5023fd1..71a875c69 100755 --- a/ci/lib.sh +++ b/ci/lib.sh @@ -44,11 +44,42 @@ rsync() { command rsync -a --del "$@" } -ARCH="$(arch)" -export ARCH -OS=$(os) -export OS +if [[ ! ${ARCH-} ]]; then + ARCH=$(arch) + export ARCH +fi + +if [[ ! ${OS-} ]]; then + OS=$(os) + export OS +fi # RELEASE_PATH is the destination directory for the release from the root. # Defaults to release -RELEASE_PATH="${RELEASE_PATH-release}" +if [[ ! ${RELEASE_PATH-} ]]; then + RELEASE_PATH="release" + export RELEASE_PATH +fi + +nodeOS() { + osname=$OS + case $osname in + macos) osname=darwin ;; + windows) osname=win32 ;; + esac + echo "$osname" +} + +nodeArch() { + cpu=$ARCH + case $cpu in + amd64) cpu=x64 ;; + esac + echo "$cpu" +} + +# See gulpfile.reh.ts for available targets. +if [[ ! ${VSCODE_TARGET-} ]]; then + VSCODE_TARGET="$(nodeOS)-$(nodeArch)" + export VSCODE_TARGET +fi