Skip to content

Visual Studio Code, rebuilt in Rust

Rust
12.0 KB
Raw Blame

Packaging, signing and the update feed

How a build becomes the app a user downloads, and how an installed app replaces itself with a newer one. This file goes one level under ARCHITECTURE.md, section "Build, packaging, release". The code is port/tools/package-app, port/tools/package-linux, port/tools/app-files.ts and app/src/update.rs with app/src/update/install.rs. Upstream is build/gulpfile.vscode.ts for the package and src/vs/platform/update for the service; the part Electron leaves to Squirrel.Mac is ported too. The feed format, the version rules and the publish steps are in port/notes.md, section "Milestone 19: product shell, privacy, accessibility, release", entries "Update feed", "Update service", "Packaging" and "Signing": this file does not repeat them.

What lives where

File Job
port/tools/app-files.ts The app folder, the same on every OS: buildProduct, copyAppFiles, rebuildNativeModule, displayVersion, writeFeedEntries.
port/tools/shipped-files.ts Which built-in extensions and packages ship. port/tools/telemetry-source-check reads the same list, so the check covers what ships.
port/tools/package-app macOS: the bundle around the app folder, Info.plist, the icon, signing, notarization, the update zip, the feed entries.
port/tools/package-linux Linux: the archive folder, the .tar.gz, the AppImage (port/tools/linux/appimage), the feed entries.
app/src/update.rs The update service: states, schedule, the feed check, the download.
app/src/update/install.rs What Squirrel.Mac does upstream: the writable check, verification, the helper that swaps the bundle.
app/src/update/unattended_restart.rs The scheduler that restarts to apply an update while the screen is locked (unattendedRestartScheduler.ts).
app/src/workbench/update.rs, app/src/workbench/update_title_bar.rs, app/src/workbench/release_notes.rs The commands, menu items, title bar entry and release notes over the service.

What a package contains

A package is two layers. The inner one is the app folder, which port/tools/app-files.ts::copyAppFiles fills the same way for every OS. The outer one is per OS.

Part Comes from
The vsrustium binary cargo gc build --release -p app, from native/target/release or the target triple's folder for another arch.
bun beside the binary The host's own bun, or for another arch the pinned release that port/tools/package-app downloads and checks against a SHA-256 in the script.
product.json port/tools/app-files.ts::buildProduct: upstream's product.json, then port/product.json, then version, quality, commit and date.
out-exthost/bootstrap-exthost.js port/tools/build-exthost.
extensions/ The built extensions folder that VSCODE_GPUI_EXTENSIONS names, filtered by port/tools/shipped-files.ts::shippedBuiltins, with port/patches/extensions-*.patch applied to the copy.
node_modules/ The pnpm entries the host bundle and the shipped extension code load, copied whole with their relative links.
Media under src/vs/ The upstream files the workbench reads at run time, listed in copyAppFiles.
ThirdPartyNotices.txt, LICENSE.txt, NOTICE.txt Upstream's notices plus the licenses of what the port adds.
bin/code (macOS), bin/<applicationName> (Linux) Upstream's code.sh with the port's names.
Info.plist, icons The reference build's Info.plist for the document types, upstream's resources/darwin for their icons, port/AppIcon.icon compiled by actool for the app's.

The binary finds the app folder by its position: app/src/product.rs::BUNDLED_APP is the path from the bundle, and app/src/product.rs::is_bundled tells a package from a checkout run. exthost/src/lib.rs::Runtime takes the bun beside the executable before one on PATH.

Invariant: a new file the app reads at run time is added to copyAppFiles. A checkout run reads it from upstream/, so every test passes and only the packaged app fails. port/tools/app-smoke starts the package from outside the checkout to catch this.

Invariant: every native binary in a package has the package's arch. port/tools/package-app rebuilds a .node of another arch with node-gyp and then fails on any Mach-O that lipo -archs reports as another arch; port/tools/package-linux does the same for ELF files. There are no universal builds.

Trap: port/tools/package-app fails when out-exthost is older than port/tools/build-exthost, port/product.json or a port/patches/src-*.patch. It compares with the port's inputs only, so after a change in upstream/ run port/tools/build-exthost yourself.

Signing and notarization

All of it is in port/tools/package-app, in this order. The order is the contract: each step seals what the earlier ones wrote.

  1. Sign every Mach-O in the app folder (native modules, ripgrep), with the hardened runtime and no entitlements.
  2. Sign bun with the entitlements allow-jit, allow-unsigned-executable-memory and disable-library-validation: JavaScriptCore needs the first two, and bun loads native modules signed by others.
  3. Sign the bundle, with the same entitlements.
  4. With NOTARIZE=1: zip, notarytool submit --wait, stapler staple.
  5. codesign --verify --deep --strict. Only when it passes: make the update zip and write the feed entries. The zip is made with ditto --norsrc --noextattr: without them it holds ._ files, other unzippers write them into the bundle, and the seal breaks ("VSRustium is damaged"). The script fails when the zip holds one.
  6. spctl -a, as the exit code. Where Gatekeeper assessments are disabled it accepts any bundle, so the script reports "not assessed" and exits 3 instead of a pass.

What it needs, by name. No private key and no password is in the repository; port/notes.md, "Signing", names the identity and its Team ID:

Name What it is
IDENTITY Environment variable: the name of a Developer ID Application identity. Its private key is in the login keychain of the build machine. Unset means ad-hoc signing.
vsrustium-notary A notarytool keychain profile on the build machine, stored once with xcrun notarytool store-credentials. It holds the Apple ID, the team and an app-specific password.
FOREIGN_IDENTITY Environment variable of port/tools/update-check only: a second signing identity, for the update that must be refused.

No workflow in .github/workflows signs, notarizes or publishes, and none reads a repository secret: they use only the run's own github.token.

Trap: the login keychain stays locked in an ssh session, so codesign with a Developer ID fails there with errSecInternalComponent. inGuiSession in port/tools/package-app writes the commands to a .command file that Terminal opens in the GUI session and waits for its exit code. A build machine with no user logged in at the screen cannot sign with a Developer ID.

Trap: an ad-hoc signed app can be packaged and started, but it can never update: app/src/update/install.rs::verify_signature refuses when the installed bundle has no Team ID. A test of the update path needs a Developer ID.

Update check and apply

There is one app/src/update.rs::UpdateService per app, created with the first window by app/src/update.rs::service; upstream's lives in the main process. Windows subscribe to its State events. The decisions are upstream's (abstractUpdateService.ts, updateService.darwin.ts); the release channel is a port addition.

The service is Disabled unless the app runs from a package and its product.json has updateUrl, commit and date. Only the packaging scripts write commit and date, so a checkout run never checks.

What must pass before the installed app is replaced, in order:

  1. The bundle and its parent folder are writable and the app is not translocated (app/src/update/install.rs::check_writable), before the feed is read.
  2. The feed entry is newer than the running build and has a SHA-256 hash, and its URL is https, or http on a loopback host (app/src/update.rs::parse_feed).
  3. The downloaded zip has that hash, and holds exactly one .app (app/src/update/install.rs::verify_download).
  4. The bundle's signature is valid and satisfies the installed bundle's designated requirement, with the same identifier and Team ID (verify_signature).
  5. After the app quit, the helper checks 4 again on the staged bundle, then swaps (app/src/update/install.rs::apply_update).

Invariant: trust comes from the installed app's own signature, not from the feed. The feed and the hash in it are served from the same place as the zip, so the hash proves only that the download is whole. Step 4 is what stops a foreign build, and it must stay a check against the installed bundle.

Invariant: the helper verifies again because the staged bundle waits in a cache folder the user can write, for as long as the app keeps running. Do not pass the result of step 4 to the helper instead.

Invariant: a failed update leaves the installed app as it was. app/src/update/install.rs::replace moves the installed bundle aside first, and on any failure after that moves it back. A helper started with --relaunch starts the app again whether the swap passed or not.

The helper is the app's own executable: app/src/main.rs hands app/src/update/install.rs::APPLY_UPDATE to apply_update before it starts anything else. spawn_helper puts it in its own process group so it outlives the app. It starts on app quit, from Ready (a plain Quit, no relaunch) and from Restarting (Restart to Update). Its log is ShipIt_stderr.log in app/src/update/install.rs::shipit_dir.

Trap: the staging folder is removed at startup and when a check or a download fails. A Ready update that was not installed on quit is downloaded again.

Trap: the feed's platform is exthost/src/gallery.rs::CURRENT_TARGET_PLATFORM, fixed at compile time: an x64 build under Rosetta stays on the x64 feed. Linux and Windows have no apply path. A found update waits in AvailableForDownload, and Download opens downloadUrl or the archive's link in the browser (updateService.linux.ts). spawn_helper on Windows only fails. No feed names the AppImage.

What a release needs

A release is made by hand; port/notes.md has the steps ("Update feed", "Publishing a release"). What must be true:

  • release in port/product.json is bumped, and port/tools/build-exthost ran after that.
  • One run of port/tools/package-app per arch, with IDENTITY and NOTARIZE=1, on a machine with a GUI session. PRERELEASE=1 makes an Insiders build; TAG must be the tag the files are uploaded to, because the feed entry's URL names it.
  • A stable release writes both feed entries, a pre-release only the pre-release one (port/tools/app-files.ts::writeFeedEntries). Both channels read fixed URLs, so an entry uploaded to the wrong release is an update nobody sees.
  • .github/workflows/linux.yml builds the Linux package as an artifact; it does not upload to a release. Publishing a release starts .github/workflows/update-flake.yml and .github/workflows/update-issue-release-options.yml, which commit to the default branch.

Check a change

  • port/tools/cargo-test -p app update:: runs the feed, state and install tests; a_failed_move_in_puts_the_installed_app_back is the one for the swap.
  • port/tools/studio 'port/tools/package-app' makes an ad-hoc signed package. Its exit code is codesign --verify's, else spctl -a's: 3 with a good signature on the Studio, where Gatekeeper assessments are disabled, so read the codesign --verify ok line.
  • port/tools/studio --lane 'port/tools/app-smoke' starts that package from outside the checkout.
  • port/tools/update-check is the end to end check: it packages an old build, a new one, a pre-release and a foreign-signed one, serves them with port/tools/update-feed, and runs each update and each refusal. Its header has the two commands; it needs IDENTITY and FOREIGN_IDENTITY.
  • port/tools/check-licenses after a new crate, port/tools/telemetry-source-check after a change to what ships.