跳到正文
本頁目錄

構建指南

本指南涵蓋從源代碼構建 LeviLamina,包括環境設置、構建命令、依賴項和版本管理。

前置要求

必需工具

  • XMake 3.0.0+ — 構建系統 (xmake.io)
  • LLVM/Clang — Windows 構建使用 clang-cl 工具鏈
  • MSVC 2022+ — 提供 clang-cl 所依賴的 Windows SDK 與標準庫
  • Git — 用於版本控制和版本號生成
  • Windows 10/11 x64 — 主要構建平臺。服務端構建也可以面向 Linux x86_64(-p linux,使用 clang 工具鏈);客戶端只能在 Windows 上構建

具體的工具和依賴版本以 xmake.lua 為準;.github/workflows/build.yml 中的工作流展示了當前實際 驗證過的組合。

安裝 XMake

PowerShell
# 使用 PowerShell
Invoke-Expression (Invoke-Webrequest 'https://xmake.io/psget.text' -UseBasicParsing).Content

# 或使用 Scoop
scoop install xmake

安裝 MSVC

安裝 Visual Studio 2022 並選擇"使用 C++ 的桌面開發"工作負載,或安裝 Visual Studio 2022 生成工具。

安裝 LLVM

從 releases.llvm.org 下載安裝,或使用 scoop install llvm,並確保 clang-cl 已加入 PATH。

構建命令

基本構建

PowerShell
# 克隆仓库
git clone https://github.com/LiteLDev/LeviLamina.git
cd LeviLamina

# 构建服务端(默认)
xmake

# 或显式指定服务端
xmake f --target_type=server
xmake

構建客戶端

PowerShell
xmake f --target_type=client
xmake

構建並啟用測試

PowerShell
xmake f --tests=y
xmake

發佈構建

PowerShell
xmake f --publish=y
xmake

清理構建

PowerShell
xmake c
xmake

構建選項

選項值默認值說明
--target_typeserver, clientserver構建目標類型
--testsy, nn啟用基於 GTest 的測試
--publishy, nn標記為發佈版本(影響版本字符串)
--levimc_repoURL-自定義 xmake-repo URL

示例

PowerShell
# 服务端构建并启用测试
xmake f --target_type=server --tests=y
xmake

# 客户端发布构建
xmake f --target_type=client --publish=y
xmake

# 自定义仓库
xmake f --levimc_repo=https://custom.repo.url
xmake

依賴項

LeviLamina 依賴 25+ 個外部庫,全部通過 xmake.lua 中的 add_requires 聲明,由 XMake 自動下載。 版本以 xmake.lua 為唯一來源,因此本頁只說明各依賴的用途。執行 xmake require --list 可查看 當前配置下實際解析到的版本。

核心庫

庫用途
entt實體組件系統
fmt字符串格式化
nlohmann_jsonJSON 解析
rapidjson快速 JSON 解析
leveldb鍵值數據庫
gsl指南支持庫

性能

庫用途
mimalloc高性能內存分配器
parallel-hashmap快速哈希表
concurrentqueue無鎖隊列

工具

庫用途
ctre編譯期正則表達式
magic_enum枚舉反射
type_safe類型安全工具
expected-liteExpected/Result 類型
glm數學庫
cprHTTP 客戶端
stb圖像與字體解碼

LeviLamina 專用

這些依賴來自 levimc-repo xmake 倉庫,可通過 --levimc_repo 覆蓋。

庫用途
pcg_cpp隨機數生成
pfr反射
demanglerC++ 名稱反修飾
levibuildscript構建腳本
preloaderDLL 預加載
symbolprovider符號解析
trampoline函數鉤子

平臺特定

庫平臺用途
libhatWindows內存操作
bedrockdataWindowsMC 二進制與數據,按 --target_type
gtest-測試框架,僅在 --tests=y 時需要

bedrockdata 與 LeviLamina 當前適配的 Minecraft 版本鎖定,其 -server / -client 變體由 --target_type 選擇。升級它屬於適配新 Minecraft 版本的工作,而非常規依賴更新。

版本號生成

LeviLamina 的版本號從 Git 標籤自動生成:

版本格式

Text Only
v{major}.{minor}.{patch}{-prerelease}+{commit_hash}

示例

  • 正式版: v26.51.8
  • 預發佈版: v26.51.8-rc.2
  • 開發版: v26.51.8-rc.2+ce09050f05(--publish=n 時包含提交哈希)

主版本號與次版本號跟隨所適配的 Minecraft 版本,當前版本參見 tooth.json 與 CHANGELOG.md。

版本來源優先級

  1. Git 標籤 — 如果當前提交有匹配 v*.*.* 的標籤
  2. tooth.json — 回退到 tooth.json 中的 version 字段

版本注入

版本在構建期間注入到 src/ll/core/Version.h.in:

C++
// 生成的 Version.h
#define LL_VERSION_MAJOR 26
#define LL_VERSION_MINOR 51
#define LL_VERSION_PATCH 8
#define LL_VERSION_PRERELEASE "rc.2"
#define LL_VERSION_BUILD "ce09050f05"

編譯器設置

C++ 標準

  • C++20 必需
  • C++23 特性通過 _HAS_CXX23=1 啟用

編譯器標誌

Windows 構建使用 clang-cl,採用兼容 MSVC 的標誌。完整列表以 xmake.lua 中 target("LeviLamina") 塊為準。

  • 運行時: /MD(動態,非調試)
  • 異常: /EHa 與 /EHs,並在 xmake 層面關閉異常
  • 警告: /W4 及特定升級:
  • /w44265 — 虛函數無 override
  • /w44289 — 循環變量在循環外使用
  • /w44296 — 表達式始終為真/假
  • /w45263 — 對臨時對象調用 std::move
  • /w44738 — 在內存中存儲浮點數

構建輸出

目錄結構

Text Only
LeviLamina/
├── build/
│   └── windows/
│       └── x64/
│           └── release/
│               └── LeviLamina.dll
└── bin/
    └── LeviLamina/
        ├── LeviLamina.dll
        └── manifest.json

產物

  • LeviLamina.dll — 主加載器 DLL
  • manifest.json — 包含版本信息的模組元數據

CI/CD

LeviLamina 使用 GitHub Actions 進行持續集成:

自動化構建

  • 觸發器: 任意分支的推送,以及改動源碼或 xmake.lua 的拉取請求
  • 平臺: Windows x64
  • 構建矩陣: 服務端與客戶端,各含 debug 與 release,測試開關各一份

發佈流程

  1. 為提交打標籤: git tag v26.51.8
  2. 推送標籤: git push origin v26.51.8
  3. CI 使用 --publish=y 構建
  4. 產物上傳到 GitHub Releases

故障排除

XMake 緩存問題

PowerShell
xmake c -a  # 清理所有
xmake f -c  # 重新配置

依賴下載失敗

PowerShell
# 使用镜像
xmake g --proxy_pac=github_mirror.lua

找不到工具鏈

確保已安裝 Visual Studio 2022 或生成工具以提供 Windows SDK,已安裝 LLVM 使 clang-cl 可在 PATH 中解析,並從"VS 2022 開發人員命令提示符"運行。

相關文檔