diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index a1869ee..d2d0630 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -1,13 +1,13 @@ name: build-and-release -# Builds the x64 plugin, runs the Catch2 test suite, and packages a -# Plugins-Admin-ready zip. +# Builds the plugin for x64, x86 (Win32) and ARM64 Notepad++, runs the Catch2 +# test suite, and packages one Plugins-Admin-ready zip per architecture. # -# * push / PR -> build + test + upload the zip as a CI artifact -# * push a "v*" tag -> additionally publish a GitHub Release with the zip -# and print the SHA-256 needed for the nppPluginList PR +# * push / PR -> build + test + upload the zips as CI artifacts +# * push a "v*" tag -> additionally publish a GitHub Release with the zips +# and print the SHA-256 needed for each nppPluginList PR # -# The DLL is placed at the ROOT of the zip and named exactly LLMAssistant.dll, +# In each zip the DLL sits at the ROOT and is named exactly LLMAssistant.dll, # which is what Notepad++ Plugins Admin requires. on: @@ -40,6 +40,25 @@ jobs: /p:WindowsTargetPlatformVersion=10.0 /m + - name: Build plugin (Win32 Release) + run: > + msbuild LLMAssistant.vcxproj + /p:Configuration=Release + /p:Platform=Win32 + /p:PlatformToolset=v143 + /p:WindowsTargetPlatformVersion=10.0 + /m + + # The runner's v143 tools (MSVC 14.44) cover x64 and x86 only, so ARM64 + # builds with the project's own toolset (v145). + - name: Build plugin (ARM64 Release) + run: > + msbuild LLMAssistant.vcxproj + /p:Configuration=Release + /p:Platform=ARM64 + /p:WindowsTargetPlatformVersion=10.0 + /m + - name: Configure tests (CMake) run: cmake -S . -B CMakeBuild @@ -49,7 +68,18 @@ jobs: - name: Run tests run: ctest --test-dir CMakeBuild --output-on-failure -C Debug - - name: Package Plugins-Admin zip + # The 32-bit DLL compiles the same core code, so run the tests as 32-bit + # too. (The x64 runner can't run ARM64 binaries.) + - name: Configure tests (CMake, Win32) + run: cmake -S . -B CMakeBuild-Win32 -A Win32 + + - name: Build tests (Win32) + run: cmake --build CMakeBuild-Win32 --config Debug + + - name: Run tests (Win32) + run: ctest --test-dir CMakeBuild-Win32 --output-on-failure -C Debug + + - name: Package Plugins-Admin zips id: package shell: pwsh run: | @@ -58,52 +88,53 @@ jobs: } else { $ver = "dev" } - $zip = "LLMAssistant_v${ver}_x64.zip" - - # DLL must sit at the zip root and be named exactly LLMAssistant.dll. - Copy-Item "x64\Release\LLMAssistant.dll" ".\LLMAssistant.dll" -Force - if (Test-Path $zip) { Remove-Item $zip -Force } - Compress-Archive -Path ".\LLMAssistant.dll" -DestinationPath $zip -Force - $hash = (Get-FileHash $zip -Algorithm SHA256).Hash.ToUpper() - "zip=$zip" >> $env:GITHUB_OUTPUT - "version=$ver" >> $env:GITHUB_OUTPUT - "sha256=$hash" >> $env:GITHUB_OUTPUT + $notes = @( + '### Notepad++ Plugins Admin metadata', + '', + 'Each Notepad++ architecture has its own plugin list in nppPluginList. `id` is the SHA-256 of that architecture''s zip.' + ) + foreach ($platform in "x64", "x86", "arm64") { + # Checks the DLL's CPU type, version and Notepad++ exports, zips it + # as LLMAssistant.dll at the zip root, prints the zip's SHA-256, and + # returns the nppPluginList entry with that SHA-256 as "id". + $entry = & .\packaging\make-release-zip.ps1 -Platform $platform -Version $ver -OutDir dist + $notes += '', "Add / update this in ``src/pl.$platform.json``:", '', '```json', $entry, '```' + } - Write-Host "===============================================" - Write-Host "Package : $zip" - Write-Host "SHA-256 : $hash <-- use as \"id\" in pl.x64.json" - Write-Host "===============================================" + $notes | Set-Content dist\release-notes.md + $notes | Add-Content $env:GITHUB_STEP_SUMMARY + "version=$ver" >> $env:GITHUB_OUTPUT - - name: Upload CI artifact + - name: Upload CI artifact (x64) uses: actions/upload-artifact@v4 with: name: LLMAssistant-x64 - path: ${{ steps.package.outputs.zip }} + path: dist/LLMAssistant_v${{ steps.package.outputs.version }}_x64.zip + if-no-files-found: error + + - name: Upload CI artifact (x86) + uses: actions/upload-artifact@v4 + with: + name: LLMAssistant-x86 + path: dist/LLMAssistant_v${{ steps.package.outputs.version }}_x86.zip + if-no-files-found: error + + - name: Upload CI artifact (arm64) + uses: actions/upload-artifact@v4 + with: + name: LLMAssistant-arm64 + path: dist/LLMAssistant_v${{ steps.package.outputs.version }}_arm64.zip if-no-files-found: error - name: Publish GitHub Release if: github.ref_type == 'tag' uses: softprops/action-gh-release@v2 with: - files: ${{ steps.package.outputs.zip }} + files: | + dist/LLMAssistant_v${{ steps.package.outputs.version }}_x64.zip + dist/LLMAssistant_v${{ steps.package.outputs.version }}_x86.zip + dist/LLMAssistant_v${{ steps.package.outputs.version }}_arm64.zip + fail_on_unmatched_files: true generate_release_notes: true - body: | - ### Notepad++ Plugins Admin metadata - - Add / update this in `nppPluginList` (`src/pl.x64.json`): - - ```json - { - "folder-name": "LLMAssistant", - "display-name": "LLM Assistant", - "version": "${{ steps.package.outputs.version }}", - "id": "${{ steps.package.outputs.sha256 }}", - "repository": "${{ github.server_url }}/${{ github.repository }}/releases/download/${{ github.ref_name }}/${{ steps.package.outputs.zip }}", - "description": "AI-powered text processing (enhance, translate, summarize, grammar, code) via the OpenAI API, directly inside Notepad++.", - "author": "Gvo87", - "homepage": "${{ github.server_url }}/${{ github.repository }}" - } - ``` - - `id` is the SHA-256 of the attached zip: `${{ steps.package.outputs.sha256 }}` + body_path: dist/release-notes.md diff --git a/.gitignore b/.gitignore index c40f516..95076a5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ -# x64 build directory +# Build directories (one per platform) x64/ -CMakeBuild/ +Win32/ +ARM64/ +CMakeBuild*/ _deps/ # Release packaging output diff --git a/INSTALLATION_GUIDE.md b/INSTALLATION_GUIDE.md index d61f355..f80e642 100644 --- a/INSTALLATION_GUIDE.md +++ b/INSTALLATION_GUIDE.md @@ -3,13 +3,18 @@ ## Quick Start ### Step 1: Download -- Get the plugin file: `LLMAssistant.dll` from the `x64\Release\` directory +- Get the plugin file `LLMAssistant.dll` for your Notepad++ architecture: + - from a [release](https://github.com/Gvo87/NotepadPlusPlus-LLM-Plugin/releases/latest): `LLMAssistant_v_x64.zip`, `_x86.zip` (32-bit) or `_arm64.zip` + - or from your own build: `x64\Release\`, `Win32\Release\` or `ARM64\Release\` +- **?** > **About Notepad++** shows whether your Notepad++ is 64-bit, 32-bit or ARM64. Notepad++ can't load a DLL built for another architecture. ### Step 2: Install 1. **Create the plugin directory:** ``` C:\Program Files\Notepad++\plugins\LLMAssistant\ ``` + For 32-bit Notepad++ on 64-bit Windows it's + `C:\Program Files (x86)\Notepad++\plugins\LLMAssistant\`. 2. **Copy the plugin file:** - Place `LLMAssistant.dll` in the directory you just created @@ -52,7 +57,7 @@ After installation, you'll see these 8 options in `Plugins > LLM Assistant`: ### Plugin doesn't appear - Check the directory path: `C:\Program Files\Notepad++\plugins\LLMAssistant\` -- Make sure you have 64-bit Notepad++ +- Make sure the DLL matches your Notepad++ architecture (x64, x86 or ARM64) - Restart Notepad++ completely ### "API key not configured" error @@ -65,8 +70,8 @@ After installation, you'll see these 8 options in `Plugins > LLM Assistant`: ## System Requirements -- **Notepad++**: Version 7.0+ (64-bit recommended) -- **Windows**: 10 or later (64-bit) +- **Notepad++**: Version 7.0+, 64-bit (x64), 32-bit (x86) or ARM64 +- **Windows**: 10 or later - **Internet**: Required for API calls - **OpenAI API Key**: Required for LLM functionality diff --git a/LLMAssistant.vcxproj b/LLMAssistant.vcxproj index 1cdf169..5c280b4 100644 --- a/LLMAssistant.vcxproj +++ b/LLMAssistant.vcxproj @@ -1,5 +1,8 @@ + Debug @@ -9,6 +12,22 @@ Release x64 + + Debug + Win32 + + + Release + Win32 + + + Debug + ARM64 + + + Release + ARM64 + 16.0 @@ -18,13 +37,13 @@ 10.0 - + DynamicLibrary true v145 Unicode - + DynamicLibrary false v145 @@ -36,28 +55,39 @@ - + - + - + + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(ProjectName)\$(Platform)\$(Configuration)\ + + true LLMAssistant .dll - + false LLMAssistant .dll - + Level3 true _DEBUG;LLMASSISTANT_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + + MultiThreadedDebug true /utf-8 %(AdditionalOptions) $(ProjectDir)include;%(AdditionalIncludeDirectories) @@ -72,13 +102,14 @@ $(ProjectDir)src;%(AdditionalIncludeDirectories) - + Level3 true true true NDEBUG;LLMASSISTANT_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreaded true /utf-8 %(AdditionalOptions) $(ProjectDir)include;%(AdditionalIncludeDirectories) diff --git a/README.md b/README.md index 3343cc7..4cb9767 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,10 @@ A powerful Notepad++ plugin that integrates Large Language Model (LLM) capabilit ## 📋 Requirements -- **Notepad++**: Version 7.0 or later (64-bit recommended) +- **Notepad++**: Version 7.0 or later: 64-bit (x64), 32-bit (x86) or ARM64 - **OpenAI API Key**: Get one from [OpenAI Platform](https://platform.openai.com/api-keys) - **Operating System**: Windows 10 or later -- **Architecture**: 64-bit Windows (plugin compiled for x64) +- **Architecture**: each release has one zip per Notepad++ architecture (`_x64`, `_x86`, `_arm64`). Use the one that matches your Notepad++. Plugins Admin picks it for you. ## 📦 Installation @@ -44,8 +44,8 @@ Maintainers: see [`packaging/PLUGINS_ADMIN_SUBMISSION.md`](packaging/PLUGINS_ADM for how releases and the Plugins Admin listing are produced. ### Quick Installation (manual) -1. **Download** the plugin: `LLMAssistant.dll` -2. **Create directory**: `C:\Program Files\Notepad++\plugins\LLMAssistant\` +1. **Download** the zip for your Notepad++ from the [latest release](https://github.com/Gvo87/NotepadPlusPlus-LLM-Plugin/releases/latest) (`_x64`, `_x86` or `_arm64`) and extract `LLMAssistant.dll` +2. **Create directory**: `C:\Program Files\Notepad++\plugins\LLMAssistant\` (32-bit Notepad++ on 64-bit Windows: `C:\Program Files (x86)\Notepad++\plugins\LLMAssistant\`) 3. **Copy file**: Place `LLMAssistant.dll` in the created directory 4. **Restart** Notepad++ 5. **Configure**: Go to `Plugins > LLM Assistant > Settings` and enter your OpenAI API key @@ -90,6 +90,7 @@ The **Custom Prompt** option allows maximum flexibility: ### Prerequisites - **Visual Studio 2022 or later** (any edition, or Build Tools) with the "Desktop development with C++" workload - **Windows SDK** (installed with that workload) +- **For ARM64 builds only**: the "MSVC Build Tools for ARM64/ARM64EC (Latest)" component (on Visual Studio 2022: "MSVC v143 - VS 2022 C++ ARM64/ARM64EC build tools (Latest)"), added under Individual components in the Visual Studio Installer - **Git** (for cloning the repository) ### Build Steps @@ -103,16 +104,22 @@ cd NotepadPlusPlus-LLM-Plugin # The compiled DLL will be in: # x64\Release\LLMAssistant.dll + +# Or build for 32-bit or ARM64 Notepad++: +.\build.bat x86 # Win32\Release\LLMAssistant.dll +.\build.bat arm64 # ARM64\Release\LLMAssistant.dll ``` +Notepad++ only loads a plugin built for its own architecture, so use the DLL that matches your Notepad++ (x64, x86 or ARM64). + ### Development Environment The build script automatically: - Finds the newest Visual Studio with the C++ tools (using `vswhere`) - Sets up the build environment - Compiles with the project's platform toolset (v145), or with the newest installed toolset if v145 is missing (for example v143 on Visual Studio 2022) -- Links required Windows libraries +- Links required Windows libraries, and links the C/C++ runtime statically, so the DLL doesn't need the Visual C++ Redistributable installed -`deploy.bat` builds the same way, then copies the DLL into `C:\Program Files\Notepad++\plugins\LLMAssistant\`. Run it as Administrator. It closes Notepad++ the same way its close button does, so unsaved files are handled as usual: Notepad++ asks whether to save them, or, if session snapshot is on, keeps them in its backup for the next start. It won't copy anything while Notepad++ is still open. +`deploy.bat` builds the x64 DLL the same way, then copies it into `C:\Program Files\Notepad++\plugins\LLMAssistant\`. Run it as Administrator. It closes Notepad++ the same way its close button does, so unsaved files are handled as usual: Notepad++ asks whether to save them, or, if session snapshot is on, keeps them in its backup for the next start. It won't copy anything while Notepad++ is still open. ### Automated Tests The portable request, JSON, and UTF-8 regression tests use Catch2. Configure them with CMake: @@ -172,7 +179,7 @@ API keys are stored in: `HKEY_CURRENT_USER\Software\LLMAssistant\APIKey` **Plugin doesn't appear in menu** - Ensure DLL is in correct directory: `C:\Program Files\Notepad++\plugins\LLMAssistant\` - Restart Notepad++ completely -- Check if you have 64-bit Notepad++ (plugin is compiled for x64) +- Check that the DLL matches your Notepad++ architecture (x64, x86 or ARM64). Notepad++ can't load a DLL built for another one. **?** > **About Notepad++** shows which one you have **"API key not configured" error** - Go to Settings and enter your OpenAI API key @@ -190,7 +197,7 @@ API keys are stored in: `HKEY_CURRENT_USER\Software\LLMAssistant\APIKey` ### Debug Information If you encounter issues, check: 1. Notepad++ version (should be 7.0+) -2. Windows architecture (plugin requires 64-bit) +2. Notepad++ architecture (x64, x86 or ARM64) matches the plugin zip you installed 3. API key validity on OpenAI platform 4. Available API credits/quota diff --git a/build.bat b/build.bat index d635241..fa63356 100644 --- a/build.bat +++ b/build.bat @@ -1,20 +1,47 @@ @echo off setlocal -REM Builds x64\Release\LLMAssistant.dll with the newest Visual Studio (2022 or -REM later, any edition or Build Tools) that has the C++ build tools. -REM build.bat build, then wait for a key press -REM build.bat /nopause build without waiting (used by deploy.bat) +REM Builds \Release\LLMAssistant.dll with the newest Visual Studio +REM (2022 or later, any edition or Build Tools) that has the C++ build tools for +REM that platform. +REM build.bat build for 64-bit Notepad++ (x64\Release), then wait for a key press +REM build.bat x86 build for 32-bit Notepad++ (Win32\Release); Win32 works too +REM build.bat arm64 build for ARM64 Notepad++ (ARM64\Release) +REM build.bat x64 /nopause build without waiting (used by deploy.bat) set "ROOT=%~dp0" +set "PLATFORM=x64" set "NO_PAUSE=" -if /i "%~1"=="/nopause" set "NO_PAUSE=1" +:parse_args +if "%~1"=="" goto :args_done +if /i "%~1"=="/nopause" ( + set "NO_PAUSE=1" +) else if /i "%~1"=="x64" ( + set "PLATFORM=x64" +) else if /i "%~1"=="x86" ( + set "PLATFORM=Win32" +) else if /i "%~1"=="Win32" ( + set "PLATFORM=Win32" +) else if /i "%~1"=="arm64" ( + set "PLATFORM=ARM64" +) else ( + echo ERROR: Unknown argument "%~1". + echo Usage: build.bat [x64^|x86^|arm64] [/nopause] + goto :fail +) +shift +goto :parse_args +:args_done REM Work from the repo folder, also when started elevated (cwd is System32 then) cd /d "%ROOT%" -echo Building Notepad++ LLM Assistant Plugin... +echo Building Notepad++ LLM Assistant Plugin for %PLATFORM%... + +REM x64 and Win32 come from the same Visual Studio component; ARM64 needs its own. +set "VC_COMPONENT=Microsoft.VisualStudio.Component.VC.Tools.x86.x64" +if "%PLATFORM%"=="ARM64" set "VC_COMPONENT=Microsoft.VisualStudio.Component.VC.Tools.ARM64" -REM Find the newest Visual Studio with the x64 C++ compiler +REM Find the newest Visual Studio with the C++ compiler for this platform set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" if not exist "%VSWHERE%" ( echo ERROR: Visual Studio not found: "%VSWHERE%" does not exist. @@ -22,7 +49,14 @@ if not exist "%VSWHERE%" ( goto :fail ) set "VS_PATH=" -for /f "usebackq delims=" %%i in (`"%VSWHERE%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set "VS_PATH=%%i" +for /f "usebackq delims=" %%i in (`"%VSWHERE%" -latest -products * -requires %VC_COMPONENT% -property installationPath`) do set "VS_PATH=%%i" +if not defined VS_PATH if "%PLATFORM%"=="ARM64" ( + echo ERROR: No Visual Studio installation with the ARM64 C++ build tools was found. + echo In the Visual Studio Installer, choose Modify, open Individual components and add + echo "MSVC Build Tools for ARM64/ARM64EC (Latest)". On Visual Studio 2022 it is called + echo "MSVC v143 - VS 2022 C++ ARM64/ARM64EC build tools (Latest)". + goto :fail +) if not defined VS_PATH ( echo ERROR: No Visual Studio installation with the C++ build tools was found. echo Add the "Desktop development with C++" workload in the Visual Studio Installer. @@ -53,7 +87,7 @@ for /f "tokens=2,3 delims=<>" %%a in ('findstr /c:"" LLMAssista set "TOOLSET_FOUND=" set "NEWEST_TOOLSET=" for /d %%v in ("%VS_PATH%\MSBuild\Microsoft\VC\v*") do ( - for /d %%t in ("%%v\Platforms\x64\PlatformToolsets\v*") do call :note_toolset %%~nxt + for /d %%t in ("%%v\Platforms\%PLATFORM%\PlatformToolsets\v*") do call :note_toolset %%~nxt ) set "TOOLSET_ARG=" if defined TOOLSET_FOUND ( @@ -62,27 +96,32 @@ if defined TOOLSET_FOUND ( echo Toolset "%PROJECT_TOOLSET%" from LLMAssistant.vcxproj is not installed, so %NEWEST_TOOLSET% is used instead. set "TOOLSET_ARG=/p:PlatformToolset=%NEWEST_TOOLSET%" ) else ( - echo ERROR: No C++ platform toolset found under "%VS_PATH%\MSBuild\Microsoft\VC". + echo ERROR: No %PLATFORM% C++ platform toolset found under "%VS_PATH%\MSBuild\Microsoft\VC". goto :fail ) +set "DLL=%PLATFORM%\Release\LLMAssistant.dll" echo. -msbuild LLMAssistant.vcxproj /p:Configuration=Release /p:Platform=x64 /p:WindowsTargetPlatformVersion=10.0 %TOOLSET_ARG% +msbuild LLMAssistant.vcxproj /p:Configuration=Release /p:Platform=%PLATFORM% /p:WindowsTargetPlatformVersion=10.0 %TOOLSET_ARG% if errorlevel 1 goto :fail -if not exist "x64\Release\LLMAssistant.dll" ( - echo ERROR: MSBuild finished but x64\Release\LLMAssistant.dll was not produced. +if not exist "%DLL%" ( + echo ERROR: MSBuild finished but %DLL% was not produced. goto :fail ) +REM 32-bit Notepad++ installs to Program Files (x86) on 64-bit Windows +set "NPP_DIR=C:\Program Files\Notepad++" +if "%PLATFORM%"=="Win32" set "NPP_DIR=C:\Program Files (x86)\Notepad++" + echo. echo ======================================== echo BUILD SUCCESSFUL! echo ======================================== -echo The plugin DLL is located at: x64\Release\LLMAssistant.dll +echo The plugin DLL is located at: %DLL% if defined NO_PAUSE exit /b 0 echo. echo Installation steps: -echo 1. Create folder: C:\Program Files\Notepad++\plugins\LLMAssistant\ +echo 1. Create folder: %NPP_DIR%\plugins\LLMAssistant\ echo 2. Copy LLMAssistant.dll to that folder echo 3. Restart Notepad++ echo 4. Configure your OpenAI API key in Plugins ^> LLM Assistant ^> Settings @@ -99,6 +138,7 @@ echo Please check the error messages above. echo Make sure you have: echo - Visual Studio 2022 or later with the "Desktop development with C++" workload echo - A Windows SDK, which that workload installs +echo - For arm64 builds, the ARM64/ARM64EC build tools component echo ======================================== if not defined NO_PAUSE pause exit /b 1 diff --git a/deploy.bat b/deploy.bat index 698f7cf..18f4080 100644 --- a/deploy.bat +++ b/deploy.bat @@ -23,7 +23,7 @@ if errorlevel 1 ( echo. echo [1/4] Building plugin... -call "%~dp0build.bat" /nopause +call "%~dp0build.bat" x64 /nopause if errorlevel 1 ( echo ERROR: Build failed! pause diff --git a/packaging/PLUGINS_ADMIN_SUBMISSION.md b/packaging/PLUGINS_ADMIN_SUBMISSION.md index b38fe0f..68fec03 100644 --- a/packaging/PLUGINS_ADMIN_SUBMISSION.md +++ b/packaging/PLUGINS_ADMIN_SUBMISSION.md @@ -6,8 +6,11 @@ auto-updatable inside **Notepad++ → Plugins → Plugins Admin**. Plugins Admin is driven by the official [`notepad-plus-plus/nppPluginList`](https://github.com/notepad-plus-plus/nppPluginList) repository. A plugin appears there only after a small JSON entry (pointing at a -downloadable release zip) is merged into `src/pl.x64.json`. This repo already -contains everything needed to produce that entry. +downloadable release zip) is merged into the list for that Notepad++ +architecture: `src/pl.x64.json`, `src/pl.x86.json` (32-bit) or +`src/pl.arm64.json`. Each list needs its own zip, because Notepad++ only loads a +DLL built for its own architecture. This repo already contains everything needed +to produce those entries. --- @@ -35,23 +38,32 @@ contains everything needed to produce that entry. ``` 3. The [`build-and-release`](../.github/workflows/build-and-release.yml) workflow - will build the x64 Release DLL, run the test suite, package - `LLMAssistant_v1.0_x64.zip` (DLL at the zip root), publish a **GitHub Release**, - and print the **SHA-256** in both the logs and the release notes. - -> No CI? Build locally with `build.bat`, then run: + will build the x64, Win32 (x86) and ARM64 Release DLLs, run the test suite, + package `LLMAssistant_v1.0_x64.zip`, `LLMAssistant_v1.0_x86.zip` and + `LLMAssistant_v1.0_arm64.zip` (DLL at the zip root), publish a + **GitHub Release** with all three, and print each zip's **SHA-256** in both + the logs and the release notes. + +> No CI? Build locally with `build.bat` (or `build.bat x86`, `build.bat arm64`), +> then run: > > ```powershell > pwsh packaging\make-release-zip.ps1 -Version 1.0 +> pwsh packaging\make-release-zip.ps1 -Version 1.0 -Platform x86 +> pwsh packaging\make-release-zip.ps1 -Version 1.0 -Platform arm64 > ``` > -> It writes `dist\LLMAssistant_v1.0_x64.zip`, prints the SHA-256, and generates the +> Each run checks that the DLL is built for that architecture, carries version +> 1.0 and exports the Notepad++ plugin functions, then writes +> `dist\LLMAssistant_v1.0_.zip`, prints the SHA-256, and generates the > exact JSON entry to paste. ## Step 2 — Fill in the nppPluginList entry Use `packaging/nppPluginList-entry.json` as the template. Replace `id` with the -SHA-256 from Step 1 and make sure `repository` points at the uploaded release zip: +SHA-256 from Step 1 and make sure `repository` points at the uploaded release zip. +The x86 and arm64 entries are the same apart from `id` and `repository`, which +point at that architecture's zip: ```json { @@ -77,11 +89,15 @@ SHA-256 from Step 1 and make sure `repository` points at the uploaded release zi 5. Confirm the plugin shows under **Available**, installs correctly, and appears under **Installed**. +For the x86 and arm64 entries, do the same with that architecture's debug build +of Notepad++ and its list (`src/pl.x86.json`, `src/pl.arm64.json`). + ## Step 4 — Open the PR Fork [`notepad-plus-plus/nppPluginList`](https://github.com/notepad-plus-plus/nppPluginList), -add the entry to `src/pl.x64.json` (keep the array sorted/consistent with -neighbors), commit, and open a PR that **only** modifies that JSON file. Once +add the entry to `src/pl.x64.json`, `src/pl.x86.json` and `src/pl.arm64.json` +(keep each array sorted/consistent with neighbors), commit, and open a PR that +**only** modifies those JSON files. Once merged and the signed `nppPluginList.dll` ships, everyone can search and install LLM Assistant from Plugins Admin. @@ -90,19 +106,20 @@ LLM Assistant from Plugins Admin. ## How auto-update works afterwards Plugins Admin compares the **installed DLL's binary version** with the `version` -in `pl.x64.json`. To ship an update: +in its architecture's list (`pl.x64.json`, `pl.x86.json` or `pl.arm64.json`). +To ship an update: 1. Bump `src/Version.h`. -2. Tag `vX.Y` and push → the workflow builds and publishes a new release zip. +2. Tag `vX.Y` and push → the workflow builds and publishes the new release zips. 3. Open a follow-up PR to `nppPluginList` updating that plugin's `version`, `id` - (new SHA-256), and `repository` URL. + (new SHA-256), and `repository` URL in each of the three lists. Users then see the new version under the **Updates** tab. ## Notes / limits -- This plugin ships **x64 only**, so it goes in `pl.x64.json`. To also list it for - 32-bit or ARM64 Notepad++, add the corresponding build configurations to the - project and workflow and submit entries to `pl.x86.json` / `pl.arm64.json`. +- Each list must point at the zip for its own architecture. The workflow and + `make-release-zip.ps1` refuse to package a DLL whose CPU type doesn't match + the zip it goes in. - If the plugin ever adds/removes Notepad++ API calls with version constraints, set `npp-compatible-versions` (and `old-versions-compatibility`) in the entry. diff --git a/packaging/make-release-zip.ps1 b/packaging/make-release-zip.ps1 index 630c15e..dd01270 100644 --- a/packaging/make-release-zip.ps1 +++ b/packaging/make-release-zip.ps1 @@ -1,7 +1,7 @@ <# .SYNOPSIS Builds a Notepad++ Plugins-Admin-ready zip for LLM Assistant and prints the - SHA-256 + a ready-to-paste nppPluginList (pl.x64.json) entry. + SHA-256 + a ready-to-paste nppPluginList entry for one Notepad++ architecture. .DESCRIPTION Notepad++ Plugins Admin requires: @@ -10,26 +10,46 @@ * named exactly LLMAssistant.dll, * and the SHA-256 of that zip recorded as "id" in nppPluginList. - This script packages an already-built DLL (x64\Release\LLMAssistant.dll by - default) into that exact layout, then emits the metadata you need for the PR. + Each Notepad++ architecture has its own plugin list and needs its own DLL: + + -Platform DLL built from zip nppPluginList + x64 x64\Release LLMAssistant_v_x64.zip src/pl.x64.json + x86 Win32\Release LLMAssistant_v_x86.zip src/pl.x86.json + arm64 ARM64\Release LLMAssistant_v_arm64.zip src/pl.arm64.json + + Before packaging, the script checks that the DLL is built for that + architecture, that its version resource matches -Version, and that it exports + the functions Notepad++ looks up when it loads a plugin. It then packages the + DLL into that exact layout and emits the metadata you need for the PR. + +.PARAMETER Platform + Notepad++ architecture: x64 (default), x86 or arm64. Win32 also means x86. .PARAMETER Version Plugin version, e.g. "1.0". Must match the DLL's binary version resource and - the git tag (vVersion). Defaults to reading src\Version.h. + the git tag (vVersion). Defaults to reading src\Version.h. A version that is + not a number, such as "dev" for a CI test build, only names the zip and skips + the version check. .PARAMETER DllPath - Path to the built DLL. Defaults to x64\Release\LLMAssistant.dll. + Path to the built DLL. Defaults to \Release\LLMAssistant.dll, + e.g. Win32\Release\LLMAssistant.dll for -Platform x86. .PARAMETER OutDir Where to write the zip. Defaults to .\dist. .EXAMPLE pwsh packaging\make-release-zip.ps1 -Version 1.0 + +.EXAMPLE + pwsh packaging\make-release-zip.ps1 -Platform x86 #> [CmdletBinding()] param( + [ValidateSet("x64", "x86", "arm64", "Win32")] + [string]$Platform = "x64", [string]$Version, - [string]$DllPath = "x64\Release\LLMAssistant.dll", + [string]$DllPath, [string]$OutDir = "dist" ) @@ -37,6 +57,19 @@ $ErrorActionPreference = "Stop" $repoRoot = Split-Path -Parent $PSScriptRoot Set-Location $repoRoot +# Notepad++ name -> MSBuild platform (output folder) and PE machine type. +$platforms = @{ + "x64" = @{ MSBuild = "x64"; Machine = 0x8664 } + "x86" = @{ MSBuild = "Win32"; Machine = 0x014C } + "arm64" = @{ MSBuild = "ARM64"; Machine = 0xAA64 } +} +$Platform = $Platform.ToLowerInvariant() +if ($Platform -eq "win32") { $Platform = "x86" } +$target = $platforms[$Platform] + +# The functions Notepad++ looks up with GetProcAddress when it loads a plugin. +$requiredExports = @("beNotified", "getFuncsArray", "getName", "isUnicode", "messageProc", "setInfo") + function Read-VersionFromHeader { $header = Join-Path $repoRoot "src\Version.h" if (-not (Test-Path $header)) { return $null } @@ -47,15 +80,82 @@ function Read-VersionFromHeader { return $null } +# Reads the machine type and the exported function names from a PE file. +function Read-PeInfo([string]$Path) { + $bytes = [System.IO.File]::ReadAllBytes($Path) + $pe = [BitConverter]::ToInt32($bytes, 0x3C) + if ([BitConverter]::ToUInt32($bytes, $pe) -ne 0x00004550) { throw "'$Path' is not a PE file." } + $coff = $pe + 4 + $machine = [BitConverter]::ToUInt16($bytes, $coff) + $sectionCount = [BitConverter]::ToUInt16($bytes, $coff + 2) + $optional = $coff + 20 + $sections = $optional + [BitConverter]::ToUInt16($bytes, $coff + 16) + # The data directories start 96 bytes into a PE32 optional header and 112 + # bytes into a PE32+ (64-bit) one. The first directory is the export table. + $is64 = [BitConverter]::ToUInt16($bytes, $optional) -eq 0x20B + $exportRva = [BitConverter]::ToUInt32($bytes, $optional + $(if ($is64) { 112 } else { 96 })) + + function ConvertTo-FileOffset([long]$Rva) { + for ($i = 0; $i -lt $sectionCount; $i++) { + $section = $sections + 40 * $i + $start = [BitConverter]::ToUInt32($bytes, $section + 12) + $size = [Math]::Max([BitConverter]::ToUInt32($bytes, $section + 8), [BitConverter]::ToUInt32($bytes, $section + 16)) + if ($Rva -ge $start -and $Rva -lt $start + $size) { + return $Rva - $start + [BitConverter]::ToUInt32($bytes, $section + 20) + } + } + throw "RVA $Rva is outside every section of '$Path'." + } + + $exports = @() + if ($exportRva -ne 0) { + $directory = ConvertTo-FileOffset $exportRva + $nameCount = [BitConverter]::ToUInt32($bytes, $directory + 24) + $nameTable = ConvertTo-FileOffset ([BitConverter]::ToUInt32($bytes, $directory + 32)) + for ($i = 0; $i -lt $nameCount; $i++) { + $name = ConvertTo-FileOffset ([BitConverter]::ToUInt32($bytes, $nameTable + 4 * $i)) + $end = [Array]::IndexOf($bytes, [byte]0, [int]$name) + $exports += [System.Text.Encoding]::ASCII.GetString($bytes, $name, $end - $name) + } + } + [pscustomobject]@{ Machine = $machine; Exports = $exports } +} + if (-not $Version) { $Version = Read-VersionFromHeader if (-not $Version) { throw "Could not determine version. Pass -Version explicitly (e.g. -Version 1.0)." } Write-Host "Using version from src\Version.h: $Version" } +if (-not $DllPath) { $DllPath = "$($target.MSBuild)\Release\LLMAssistant.dll" } if (-not (Test-Path $DllPath)) { - throw "DLL not found at '$DllPath'. Build the Release|x64 configuration first (build.bat), or pass -DllPath." + throw "DLL not found at '$DllPath'. Build the Release|$($target.MSBuild) configuration first (build.bat $Platform), or pass -DllPath." +} +$DllPath = (Resolve-Path $DllPath).Path + +# Check the DLL before packaging it: Notepad++ can't load a DLL built for another +# architecture, and Plugins Admin compares the version resource to the entry. +$pe = Read-PeInfo $DllPath +if ($pe.Machine -ne $target.Machine) { + $actual = ($platforms.GetEnumerator() | Where-Object { $_.Value.Machine -eq $pe.Machine } | Select-Object -ExpandProperty Key) + if (-not $actual) { $actual = "machine type 0x{0:X4}" -f $pe.Machine } + throw "'$DllPath' is built for $actual, not $Platform." +} +$missing = $requiredExports | Where-Object { $_ -cnotin $pe.Exports } +if ($missing) { + throw "'$DllPath' does not export $($missing -join ', '). Exports found: $($pe.Exports -join ', ')" +} +$fileInfo = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($DllPath) +$dllVersion = [version]::new($fileInfo.FileMajorPart, $fileInfo.FileMinorPart, $fileInfo.FileBuildPart, $fileInfo.FilePrivatePart) +if ($Version -match '^\d+(\.\d+){0,3}$') { + $expected = [version](($Version.Split('.') + @('0', '0', '0') | Select-Object -First 4) -join '.') + if ($dllVersion -ne $expected) { + throw "'$DllPath' has version $dllVersion, but -Version is $Version. Bump src\Version.h and rebuild, or pass the matching -Version." + } +} else { + Write-Host "Version '$Version' is not a number, so the DLL version ($dllVersion) is not checked against it." } +Write-Host ("Checked {0}: {1} (0x{2:X4}), version {3}, exports {4}" -f $DllPath, $Platform, $pe.Machine, $dllVersion, ($requiredExports -join ', ')) New-Item -ItemType Directory -Force -Path $OutDir | Out-Null @@ -65,7 +165,7 @@ if (Test-Path $staging) { Remove-Item $staging -Recurse -Force } New-Item -ItemType Directory -Force -Path $staging | Out-Null Copy-Item $DllPath (Join-Path $staging "LLMAssistant.dll") -Force -$zipName = "LLMAssistant_v${Version}_x64.zip" +$zipName = "LLMAssistant_v${Version}_${Platform}.zip" $zipPath = Join-Path $OutDir $zipName if (Test-Path $zipPath) { Remove-Item $zipPath -Force } Compress-Archive -Path (Join-Path $staging "*") -DestinationPath $zipPath -Force @@ -88,7 +188,7 @@ Write-Host " Package : $zipPath" Write-Host " SHA-256 : $sha" Write-Host "====================================================================" Write-Host "" -Write-Host "Add this entry to nppPluginList -> src/pl.x64.json (npp-plugins array):" +Write-Host "Add this entry to nppPluginList -> src/pl.$Platform.json (npp-plugins array):" Write-Host "" $entry = [ordered]@{ diff --git a/src/PluginInterface.h b/src/PluginInterface.h index a04c120..421ba13 100644 --- a/src/PluginInterface.h +++ b/src/PluginInterface.h @@ -39,8 +39,8 @@ #define SC_MOD_DELETETEXT 0x2 // Scintilla's position type is pointer-sized (ptrdiff_t), not int. Getting this -// wrong shifts every field after it, so modificationType must be read through a -// struct with the correct 64-bit layout. +// wrong shifts every field after it on 64-bit builds (x64, ARM64), so +// modificationType must be read through a struct with the real layout. typedef intptr_t Sci_Position; // Forward declarations @@ -72,7 +72,7 @@ typedef struct { // SCNotification structure. Field types must match Scintilla's real layout // (Sci_Position is pointer-sized) so that fields such as modificationType are -// read from the correct offsets on x64. +// read from the correct offsets on x86, x64 and ARM64 alike. struct SCNotification { NMHDR nmhdr; Sci_Position position; diff --git a/src/Version.h b/src/Version.h index 791cad1..eb44edc 100644 --- a/src/Version.h +++ b/src/Version.h @@ -5,13 +5,13 @@ // // This version is compiled into the DLL's VERSIONINFO resource. Notepad++'s // Plugins Admin reads that binary version and compares it against the "version" -// field of the entry in nppPluginList (pl.x64.json) to decide whether an update -// is available. When you cut a new release, bump the numbers here, tag the repo -// with a matching "vMAJOR.MINOR" tag, and update the nppPluginList entry so -// auto-update keeps working. +// field of the entry in nppPluginList (pl.x64.json, pl.x86.json, pl.arm64.json) +// to decide whether an update is available. When you cut a new release, bump the +// numbers here, tag the repo with a matching "vMAJOR.MINOR" tag, and update the +// nppPluginList entries so auto-update keeps working. #define LLM_VERSION_MAJOR 1 -#define LLM_VERSION_MINOR 1 +#define LLM_VERSION_MINOR 2 #define LLM_VERSION_PATCH 0 #define LLM_VERSION_BUILD 0