feat: NSIS 安装包脚本 (62MB, 含 LLVM+clang+lld)

This commit is contained in:
2026-06-05 21:51:22 +08:00
parent 143174ee4f
commit 1e161ecfff
3 changed files with 185 additions and 2 deletions
+12 -2
View File
@@ -140,8 +140,8 @@ graph TB
### 从源码构建 ### 从源码构建
```bash ```bash
git clone <repo-url> git clone git@lhy-git.liuhangyv.top:Serendipity/l-language.git
cd "L Language" cd l-language
mkdir build && cd build mkdir build && cd build
cmake .. -G "MinGW Makefiles" -DCMAKE_PREFIX_PATH="D:/settings/Language/LLVM" cmake .. -G "MinGW Makefiles" -DCMAKE_PREFIX_PATH="D:/settings/Language/LLVM"
mingw32-make -j4 mingw32-make -j4
@@ -149,6 +149,16 @@ mingw32-make -j4
生成 `l_lang.exe` 生成 `l_lang.exe`
### 安装包(Windows
下载 [L-Language-x.x.x-setup.exe](https://github.com/LHY0125/l-language/releases),双击安装。包含编译器、LLVM 运行时和 8 个示例程序,无需额外安装 GCC 或 LLVM。
安装包构建:
```bash
cd scripts && build_installer.bat
```
需要 NSIS 3.x。
## 使用 ## 使用
```bash ```bash
+34
View File
@@ -0,0 +1,34 @@
@echo off
REM L Language 安装包构建脚本
REM 前置条件: 已编译 l_lang.exe (cd build && mingw32-make -j4)
set VERSION=0.6.0
set NSIS=D:\Program Files (x86)\NSIS\Bin\makensis.exe
echo === 构建 L Language %VERSION% 安装包 ===
echo.
REM 1. 确保编译器已编译
if not exist "build\l_lang.exe" (
echo 错误: build\l_lang.exe 不存在,请先编译
exit /b 1
)
REM 2. 复制 LICENSE 到 scripts 目录
copy LICENSE scripts\LICENSE.txt >nul 2>&1
REM 3. 添加 BOM 并构建
cd scripts
(
echo // BOM marker
) > _bom.tmp
copy /b _bom.tmp + installer.nsi installer_bom.nsi >nul
del _bom.tmp
"%NSIS%" -DVERSION=%VERSION% installer_bom.nsi
del installer_bom.nsi
cd ..
echo.
echo === 完成 ===
echo 安装包: build\L-Language-%VERSION%-setup.exe
+139
View File
@@ -0,0 +1,139 @@
; L Language 编译器 Windows 安装包
; 构建: makensis -DVERSION=x.y.z installer.nsi
Unicode true
!ifndef VERSION
!define VERSION "0.6.0"
!endif
!define PRODUCT "L Language"
!define PUBLISHER "Liu Hangyu (LHY0125)"
!define EXE "l_lang.exe"
Name "${PRODUCT} ${VERSION}"
OutFile "..\build\L-Language-${VERSION}-setup.exe"
InstallDir "$PROGRAMFILES\L Language"
RequestExecutionLevel admin
SetCompressor /SOLID lzma
SetCompressorDictSize 32
!include "MUI2.nsh"
!define MUI_ABORTWARNING
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "..\LICENSE"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "SimpChinese"
; ── 核心文件 ──
Section "Install"
SetOutPath "$INSTDIR"
; 编译器
File "..\build\${EXE}"
; LLVM 运行时 (编译必须)
File "D:\settings\Language\LLVM\bin\LLVM-C.dll"
; 链接器 (.o -> .exe)
File "D:\settings\Language\LLVM\bin\clang.exe"
File "D:\settings\Language\LLVM\bin\ld.lld.exe"
; MinGW 线程运行时
File "D:\settings\Language\C\mingw64\bin\libmcfgthread-2.dll"
; 示例程序
SetOutPath "$INSTDIR\examples"
File "..\test\programs\01_arithmetic.l"
File "..\test\programs\02_if_else.l"
File "..\test\programs\04_fib_recursive.l"
File "..\test\programs\12_struct.l"
File "..\test\programs\17_enum.l"
File "..\test\programs\27_named_args.l"
File "..\test\programs\28_pipe.l"
File "..\test\programs\29_interp.l"
; 示例说明
FileOpen $0 "$INSTDIR\examples\README.txt" w
FileWrite $0 "L Language 示例程序$\r$\n"
FileWrite $0 "==================$\r$\n$\r$\n"
FileWrite $0 "01_arithmetic.l - 基本算术运算$\r$\n"
FileWrite $0 "02_if_else.l - if/else 分支$\r$\n"
FileWrite $0 "04_fib_recursive.l - 递归斐波那契$\r$\n"
FileWrite $0 "12_struct.l - 结构体定义和使用$\r$\n"
FileWrite $0 "17_enum.l - 枚举类型$\r$\n"
FileWrite $0 "27_named_args.l - 命名参数$\r$\n"
FileWrite $0 "28_pipe.l - 管道运算符 |>$\r$\n"
FileWrite $0 "29_interp.l - 字符串插值$\r$\n$\r$\n"
FileWrite $0 "编译运行:$\r$\n"
FileWrite $0 ' "$INSTDIR\${EXE}" 文件名.l -o 程序.exe$\r$\n'
FileWrite $0 " 程序.exe$\r$\n"
FileClose $0
; 快速入门 bat
FileOpen $0 "$INSTDIR\快速入门.bat" w
FileWrite $0 '@echo off$\r$\n'
FileWrite $0 'title L Language - 快速入门$\r$\n'
FileWrite $0 'echo.$\r$\n'
FileWrite $0 'echo ===================================$\r$\n'
FileWrite $0 'echo L Language ${VERSION} 快速入门$\r$\n'
FileWrite $0 'echo ===================================$\r$\n'
FileWrite $0 'echo.$\r$\n'
FileWrite $0 'echo 编译并运行字符串插值示例:$\r$\n'
FileWrite $0 'echo.$\r$\n'
FileWrite $0 '"$INSTDIR\${EXE}" "$INSTDIR\examples\29_interp.l" -o "$INSTDIR\hello.exe"$\r$\n'
FileWrite $0 'if %errorlevel% equ 0 ($\r$\n'
FileWrite $0 ' echo.$\r$\n'
FileWrite $0 ' echo --- 程序输出 ---$\r$\n'
FileWrite $0 ' "$INSTDIR\hello.exe"$\r$\n'
FileWrite $0 ' echo.$\r$\n'
FileWrite $0 ' echo 编译运行成功!$\r$\n'
FileWrite $0 ') else ($\r$\n'
FileWrite $0 ' echo 编译失败,请检查环境。$\r$\n'
FileWrite $0 ')$\r$\n'
FileWrite $0 'echo.$\r$\n'
FileWrite $0 'pause$\r$\n'
FileClose $0
; 开始菜单
CreateDirectory "$SMPROGRAMS\${PRODUCT}"
CreateShortCut "$SMPROGRAMS\${PRODUCT}\快速入门.lnk" \
"$INSTDIR\快速入门.bat" "" "$INSTDIR\快速入门.bat" 0
CreateShortCut "$SMPROGRAMS\${PRODUCT}\示例目录.lnk" \
"$INSTDIR\examples" "" "$INSTDIR\examples" 0
CreateShortCut "$SMPROGRAMS\${PRODUCT}\卸载.lnk" \
"$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
; 控制面板注册
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\L Language" \
"DisplayName" "${PRODUCT} ${VERSION}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\L Language" \
"UninstallString" "$INSTDIR\uninstall.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\L Language" \
"DisplayVersion" "${VERSION}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\L Language" \
"Publisher" "${PUBLISHER}"
WriteUninstaller "$INSTDIR\uninstall.exe"
SectionEnd
; ── 卸载 ──
Section "Uninstall"
Delete "$INSTDIR\${EXE}"
Delete "$INSTDIR\LLVM-C.dll"
Delete "$INSTDIR\clang.exe"
Delete "$INSTDIR\ld.lld.exe"
Delete "$INSTDIR\libmcfgthread-2.dll"
Delete "$INSTDIR\快速入门.bat"
Delete "$INSTDIR\uninstall.exe"
RMDir /r "$INSTDIR\examples"
RMDir "$INSTDIR"
Delete "$SMPROGRAMS\${PRODUCT}\*"
RMDir "$SMPROGRAMS\${PRODUCT}"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\L Language"
SectionEnd