Use the stock Tauri NSIS template with RuneStone installer hooks
Remove the 996-line fork of the Tauri 2.11.4 template and the custom
comparator. src-tauri/windows/hooks.nsh now adds the RuneStone behavior
through bundle.windows.nsis.installerHooks:
- RuneStoneGuiInit (MUI_CUSTOMFUNCTION_GUIINIT) runs before the first
page in interactive and passive setup. It stops a downgrade with exit
code 2. It makes the stock maintenance page skip itself, so that setup
never starts the uninstaller for an upgrade or a reinstall.
- The hidden section RuneStoneVersionCheck runs before the Tauri sections
in all modes. Silent setup shows no pages, so it needs this check.
- NSIS_HOOK_POSTINSTALL writes the release version to DisplayVersion and
RuneStoneReleaseVersion, and the Windows version to
RuneStoneWindowsVersion. Installed apps now show 0.1.23a, not 0.1.23+1.
Setup compares the four-number Windows encoding with ${VersionCompare}.
An unknown installed version stops setup.
buildInstaller.mjs gives the toolchain version to Tauri through a
--config override. It writes tauri.conf.json, Cargo.toml, and Cargo.lock
only after the installer is complete. package.json changes during the
build because the Settings dialog imports its version. A failed build
restores it. Add --dry-run, which prints the plan and changes no file.
The tests compile NSIS programs with the real makensis. They simulate the
installed version in a test-only HKCU key and check /S, /P, /UPDATE, and
interactive setup. A drift check reads the template from the installed
Tauri CLI. The first real installer needs the installer checks in
docs/builds.md.
This commit is contained in:
+70
-24
@@ -22,7 +22,8 @@ Procedure, in the RuneStone repository root:
|
||||
2. Run `pnpm check`.
|
||||
3. Run `pnpm test`.
|
||||
4. Select the version with the [version policy](releases.md#versions).
|
||||
5. Run `pnpm build:installer --version <version>`.
|
||||
5. Run `pnpm build:installer --version <version> --dry-run`. Make sure that the plan shows the correct versions. A dry run changes no file.
|
||||
6. Run `pnpm build:installer --version <version>`.
|
||||
|
||||
Without `--version`, the script uses the version in `package.json`.
|
||||
|
||||
@@ -43,32 +44,37 @@ Example, from the 0.1.44 download link in the README: version `0.1.44` gives `re
|
||||
Source: `scripts/buildInstaller.mjs`.
|
||||
|
||||
1. Reads the version and makes sure that all version fields match the current version.
|
||||
2. Makes sure that downgrade protection stays on in `tauri.conf.json` and `tauri.windows.conf.json`, and that the browser runtime is staged.
|
||||
2. Makes sure that downgrade protection stays on in `tauri.conf.json` and `tauri.windows.conf.json`.
|
||||
Makes sure that `tauri.windows.conf.json` names the installer hooks and that the browser runtime is staged.
|
||||
3. Stops if the setup file or `host.json` exists in the bundle folder or in `releases/<version>/`.
|
||||
A dry run prints the plan and stops here.
|
||||
4. Saves copies of the four version files as `*.before` in `output/installer-build/<version>/<time>/`, a new folder for each attempt.
|
||||
It also writes the NSIS template and a configuration override to that folder.
|
||||
5. Writes the new version to `package.json`, `tauri.conf.json`, `Cargo.toml`, and `Cargo.lock`.
|
||||
6. Runs `tauri build --no-bundle -- --locked`. This runs `pnpm build` and compiles the release app.
|
||||
7. Runs `scripts/setWindowsVersion.ps1` to write the version resource of `runestone.exe`.
|
||||
8. Runs `tauri bundle --bundles nsis` with the RuneStone template from `src-tauri/windows/installer.nsi`.
|
||||
It also writes the configuration override `tauri.version.json` to that folder. The override sets the toolchain version, for example `{"version": "0.1.23+1"}`.
|
||||
5. Writes the new version to `package.json`. The front-end build reads this version for the Settings dialog.
|
||||
6. Runs `tauri build --no-bundle --config <override> -- --locked`. This runs `pnpm build` and compiles the release app.
|
||||
Tauri gives the override to the Rust build script and to the app. Cargo keeps the previous package version, so the app must not use `CARGO_PKG_VERSION`.
|
||||
7. Runs `scripts/setWindowsVersion.ps1`. It writes the release version to the `FileVersion` and `ProductVersion` strings of `runestone.exe`. Tauri can write only a SemVer version to these strings.
|
||||
8. Runs `tauri bundle --bundles nsis --config <override>`. Tauri uses its stock NSIS template with the [installer hooks](#installer-hooks).
|
||||
9. Moves the setup file into `releases/<version>/`, writes `host.json`, and removes the bundle-folder copy.
|
||||
10. Writes the new version to `tauri.conf.json`, `Cargo.toml`, and `Cargo.lock`.
|
||||
|
||||
### Failure and rollback
|
||||
|
||||
If a step fails, or you press Ctrl+C, the script restores the four version files.
|
||||
If a step fails, or you press Ctrl+C, the script restores `package.json`. The other version files change only in step 10. If step 10 fails, the script restores them too.
|
||||
It moves partial setup files and `host.json` into the folder of that attempt with a `.failed-<timestamp>` suffix.
|
||||
If the process is killed before this cleanup, copy the `*.before` files of the attempt back to their original names.
|
||||
|
||||
## Installer requirements
|
||||
|
||||
Keep these properties when you change the installer configuration or template:
|
||||
Keep these properties when you change the installer configuration or hooks:
|
||||
|
||||
| Requirement | Implementation |
|
||||
| --- | --- |
|
||||
| Reinstall is the default when RuneStone is installed, also for the same version. | The NSIS maintenance page preselects the reinstall option. |
|
||||
| Users do not uninstall RuneStone before an update or a reinstall. | Updates and reinstalls replace the app in place. |
|
||||
| Reinstall is the default when RuneStone is installed, also for the same version. | The hooks make the stock maintenance page skip itself. Setup replaces the app in place. |
|
||||
| Users do not uninstall RuneStone before an update or a reinstall. | Setup does not start the uninstaller of the installed version. |
|
||||
| Updates and reinstalls keep workspace files and user settings. | Workspaces stay outside the installation folder. Settings stay in application data. |
|
||||
| Older versions cannot replace a newer installation. | `allowDowngrades` is `false`. `pnpm build:installer` stops if this setting changes. |
|
||||
| Older versions cannot replace a newer installation. | The hooks stop setup with exit code 2 in all modes: interactive, passive (`/P`), silent (`/S`), and update (`/UPDATE`). An installed version with an unknown format also stops setup. `allowDowngrades` stays `false`. `pnpm build:installer` stops if this setting changes. |
|
||||
| Windows shows the release version in installed apps. | The hooks write the release version, such as `0.1.23a`, to `DisplayVersion`. |
|
||||
| The app identity stays the same across upgrades. | The identifier stays `com.runestone.app`. |
|
||||
| WebView2 is available. | The installer embeds the WebView2 bootstrapper. If the runtime is missing, setup downloads it. |
|
||||
|
||||
@@ -76,9 +82,30 @@ The installer uses the RuneStone icon, installs for the current Windows account,
|
||||
It does not register document types or start RuneStone when Windows starts.
|
||||
|
||||
Local installers are unsigned. Configure Windows code signing with [Tauri's signing guide](https://v2.tauri.app/distribute/sign/windows/) before public distribution.
|
||||
The NSIS template comes from Tauri CLI 2.11.4. When you update Tauri, compare the template with the new Tauri version.
|
||||
See [Tauri's Windows installer documentation](https://v2.tauri.app/distribute/windows-installer/) for packaging options.
|
||||
|
||||
### Installer hooks
|
||||
|
||||
RuneStone uses the stock NSIS template of the Tauri CLI.
|
||||
`src-tauri/windows/hooks.nsh` adds the RuneStone behavior. `tauri.windows.conf.json` names this file in `bundle.windows.nsis.installerHooks`.
|
||||
|
||||
| Hook | When it runs | What it does |
|
||||
| --- | --- | --- |
|
||||
| `RuneStoneGuiInit`, set as `MUI_CUSTOMFUNCTION_GUIINIT` | Interactive and passive (`/P`) setup, before the first page | Stops a downgrade. Makes the maintenance page skip itself. |
|
||||
| Section `-RuneStoneVersionCheck` | All modes, before the Tauri sections | Restores the current-user context. Stops a downgrade. Silent setup shows no pages, so it needs this check. |
|
||||
| `NSIS_HOOK_POSTINSTALL` | At the end of the Tauri `Install` section | Writes `DisplayVersion`, `RuneStoneReleaseVersion`, and `RuneStoneWindowsVersion`. |
|
||||
|
||||
Tauri includes the hooks file before the template variables, pages, and sections.
|
||||
Thus only the `NSIS_HOOK_*` macros can use template symbols such as `${VERSION}`.
|
||||
The other hook code reads the version of the setup file from its version resource.
|
||||
|
||||
The stock maintenance page preselects "Uninstall before installing" for an upgrade.
|
||||
In passive mode, it also starts the uninstaller for a same-version reinstall. A hook cannot change this page.
|
||||
Thus `RuneStoneGuiInit` sets the shell context to all users. The page then looks in `HKLM`, does not find the current-user installation, and skips itself.
|
||||
|
||||
`tests/unit/release/installerVersion.spec.ts` reads the template from the installed Tauri CLI. It checks the template parts that the hooks use.
|
||||
After a Tauri update, run `pnpm test`. If this check fails, adapt the hooks before you build an installer.
|
||||
|
||||
## Hotfix installer versions
|
||||
|
||||
Cargo and Tauri accept only SemVer versions. The Windows version resource accepts only four numbers.
|
||||
@@ -89,36 +116,55 @@ The suffix index counts `a` = 1 through `z` = 26, then `aa` = 27. A regular vers
|
||||
| Field | Value for `0.1.23a` |
|
||||
| --- | --- |
|
||||
| `package.json`, `[package.metadata.runestone]`, the setup file name, the version in Settings, and the executable `FileVersion` and `ProductVersion` strings | `0.1.23a` |
|
||||
| `tauri.conf.json`, the Cargo package version, and `Cargo.lock` | `0.1.23+1` |
|
||||
| The numeric Windows version resource of the executable and the installer | `0.1.23.1` |
|
||||
| Registry value `RuneStoneReleaseVersion` | `0.1.23a` |
|
||||
| Registry value `DisplayVersion`, which Windows shows in installed apps | `0.1.23+1` |
|
||||
| Registry values `DisplayVersion`, which Windows shows in installed apps, and `RuneStoneReleaseVersion` | `0.1.23a` |
|
||||
| `tauri.conf.json`, the Cargo package version, `Cargo.lock`, and the `FileVersion` and `ProductVersion` strings of the setup file | `0.1.23+1` |
|
||||
| The numeric Windows version resources of the executable and the setup file, and the registry value `RuneStoneWindowsVersion` | `0.1.23.1` |
|
||||
|
||||
During the build, Tauri gets `0.1.23+1` from a configuration override. The script writes the table values to the files only after the installer is complete.
|
||||
The NSIS template writes the version strings of the setup file. A hook cannot change them, so they keep the toolchain version.
|
||||
|
||||
Each numeric part and the suffix index must not exceed 65535. The last valid suffix is `crxo`.
|
||||
The script rejects other versions before it changes a file.
|
||||
|
||||
The installer comparison in `src-tauri/windows/versionCompare.nsh` sorts the numeric release first, then the suffix:
|
||||
Setup compares Windows versions with the NSIS function `${VersionCompare}`. Their order is the release order:
|
||||
`0.1.23 < 0.1.23a < 0.1.23b < 0.1.23z < 0.1.23aa < 0.1.24`.
|
||||
The installer reads `RuneStoneReleaseVersion` and uses `DisplayVersion` when that value is missing.
|
||||
An installed version with an unknown format counts as newer, so setup blocks replacement.
|
||||
Older RuneStone installers read `DisplayVersion` as SemVer and treat `0.1.23+1` as newer than `0.1.23`. Thus an older `0.1.23` installer does not replace the hotfix.
|
||||
Setup reads the installed version from `RuneStoneWindowsVersion`.
|
||||
If that value is missing, setup reads `DisplayVersion`. Earlier installers wrote the toolchain version there, such as `0.1.23+1`.
|
||||
An installed version with an unknown format stops setup.
|
||||
Installers from 0.1.23a to 0.1.44 read `RuneStoneReleaseVersion`, so they also detect a newer hotfix installation.
|
||||
|
||||
## Installer checks
|
||||
|
||||
Do these checks on a separate Windows test account or virtual machine. A successful build does not prove them.
|
||||
|
||||
The unit tests compile small NSIS programs with the hooks file. They do not run a real RuneStone setup file.
|
||||
Do all checks in this table for the first installer that uses the stock template and the hooks file. Do not publish that installer before all checks pass.
|
||||
|
||||
| Check | Expected result |
|
||||
| --- | --- |
|
||||
| Install on an account without Node.js or Rust | Setup completes and RuneStone opens. |
|
||||
| Install without WebView2, with internet access | Setup installs the runtime and RuneStone opens. |
|
||||
| Open RuneStone from the Start menu | The app opens without a terminal or a development server. |
|
||||
| Create a workspace outside the installation folder | Notes save and open again. |
|
||||
| Install a newer version | Setup updates the app and keeps workspace files. |
|
||||
| Install the same version again | Setup selects reinstall and keeps workspace files and settings. |
|
||||
| Install an older version | Setup blocks the downgrade. |
|
||||
| Install the new version over 0.1.44 | Setup shows no maintenance page and does not start the uninstaller. It updates the app and keeps workspace files and settings. |
|
||||
| Install the same version again | Setup shows no maintenance page and does not start the uninstaller. It keeps workspace files and settings. |
|
||||
| Install an older version, for example 0.1.44 | Setup blocks the downgrade. |
|
||||
| Silent downgrade attempt | See the procedure below this table. Setup stops with exit code 2 and changes nothing. |
|
||||
| Open **Settings → Apps → Installed apps** in Windows | The RuneStone entry shows the release version, such as `0.1.45` or `0.1.45a`. |
|
||||
| Install a hotfix over its base version | Setup updates the app. |
|
||||
| Remove RuneStone through Windows Settings | The app and shortcuts are removed. The separate workspace stays. |
|
||||
|
||||
Silent downgrade attempt, in PowerShell on the test account:
|
||||
|
||||
1. Install the new version.
|
||||
2. Simulate a newer installation:
|
||||
`Set-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\RuneStone' RuneStoneWindowsVersion '9.0.0.0'`
|
||||
3. Run the setup file in silent mode and show its exit code:
|
||||
`(Start-Process .\RuneStone_<version>_x64-setup.exe -ArgumentList '/S' -Wait -PassThru).ExitCode`
|
||||
4. Make sure that the exit code is `2` and that installed apps show the same version as before.
|
||||
5. Run the same command with `-ArgumentList '/P'`. Setup shows a message, then stops with exit code `2`.
|
||||
6. Restore the registry value: set `RuneStoneWindowsVersion` to the `windowsVersion` value in `host.json`.
|
||||
|
||||
## Build Linux packages
|
||||
|
||||
Prerequisites:
|
||||
|
||||
Reference in New Issue
Block a user