Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: xmake optional #1360

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 81 additions & 11 deletions .github/workflows/commit-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@ on:
pull_request:

jobs:
build:
lint:
runs-on: windows-2019
env:
boost_version: 1.84.0
BOOST_ROOT: ${{ github.workspace }}\deps\boost_1_84_0
steps:
- name: Checkout last commit
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install llvm if necessary
shell: pwsh
run: |
Expand All @@ -48,11 +42,27 @@ jobs:
Write-Host "clang-format not installed"
choco install llvm --version=18.1.6
}

- name: Code style lint
shell: bash
run: ./clang-format.sh -i

build:
needs: lint
runs-on: windows-2019
env:
boost_version: 1.84.0
BOOST_ROOT: ${{ github.workspace }}\deps\boost_1_84_0
steps:

- name: Checkout last commit
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- name: Fetch all tags
run: git fetch --tags

- name: Configure build environment
shell: bash
run: |
Expand All @@ -67,19 +77,16 @@ jobs:
${{ env.BOOST_ROOT }}
key: ${{ runner.os }}-boost-${{ env.boost_version }}

# install boost if not cached
- name: Install Boost
if: steps.cache-boost.outputs.cache-hit != 'true'
shell: bash
run: |
./install_boost.bat
./build.bat boost arm64

# add msbuild to PATH
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v2

# use upper stream released librime files if stable release
- name: Copy Rime files
run: |
.\github.install.bat
Expand All @@ -106,3 +113,66 @@ jobs:
path: |
.\output\archives\weasel*.exe
.\output\archives\debug_symbols.7z

xbuild:
needs: lint
runs-on: windows-2019
env:
boost_version: 1.84.0
BOOST_ROOT: ${{ github.workspace }}\deps\boost_1_84_0
steps:

- name: Checkout last commit
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- name: Fetch all tags
run: git fetch --tags

- name: Configure build environment
shell: bash
run: |
cp env.vs2019.bat env.bat
echo git_ref_name="$(git describe --always)" >> $GITHUB_ENV

- name: Cache Boost
id: cache-boost
uses: actions/cache@v4
with:
path: |
${{ env.BOOST_ROOT }}
key: ${{ runner.os }}-boost-${{ env.boost_version }}

- name: Install Boost
if: steps.cache-boost.outputs.cache-hit != 'true'
shell: bash
run: |
./install_boost.bat
./build.bat boost arm64

# xmake 2.9.4 or later
- uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: '2.9.4'
actions-cache-folder: '.xmake-cache'

- uses: ilammy/msvc-dev-cmd@v1

- name: Copy Rime files
shell: pwsh
run: |
.\github.install.bat

- name: Build data
run: |
$ErrorActionPreference = 'Stop'
.\build.bat data

- name: Build Weasel
id: build_weasel
shell: cmd
run: |
.\xbuild.bat arm64 installer

5 changes: 5 additions & 0 deletions RimeWithWeasel/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target("RimeWithWeasel")
set_kind("static")
add_files("./*.cpp")
add_rules("use_weaselconstants")

24 changes: 24 additions & 0 deletions WeaselDeployer/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
target("WeaselDeployer")
set_kind("binary")
add_files("./*.cpp")
add_rules("add_rcfiles", "use_weaselconstants", "subwin")
add_links("imm32", "kernel32", "rime")
add_deps("WeaselIPC", "RimeWithWeasel")
add_files("$(projectdir)/PerMonitorHighDPIAware.manifest")
add_ldflags("/DEBUG /OPT:ICF /LARGEADDRESSAWARE /ERRORREPORT:QUEUE")
before_build(function(target)
local target_dir = path.join(target:targetdir(), target:name())
if not os.exists(target_dir) then
os.mkdir(target_dir)
end
target:set("targetdir", target_dir)
end)
after_build(function(target)
if is_arch("x86") then
os.cp(path.join(target:targetdir(), "WeaselDeployer.exe"), "$(projectdir)/output/Win32")
os.cp(path.join(target:targetdir(), "WeaselDeployer.pdb"), "$(projectdir)/output/Win32")
else
os.cp(path.join(target:targetdir(), "WeaselDeployer.exe"), "$(projectdir)/output")
os.cp(path.join(target:targetdir(), "WeaselDeployer.pdb"), "$(projectdir)/output")
end
end)
30 changes: 30 additions & 0 deletions WeaselIME/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
target("WeaselIME")
set_kind("shared")
add_files("./*.cpp")
add_rules("add_rcfiles")
add_links("advapi32", "imm32", "user32", "gdi32")
add_deps("WeaselIPC", "WeaselUI")
local fname = ''

before_build(function(target)
local target_dir = path.join(target:targetdir(), target:name())
if not os.exists(target_dir) then
os.mkdir(target_dir)
end
target:set("targetdir", target_dir)
end)

after_build(function(target)
os.cp(path.join(target:targetdir(), "*.ime"), "$(projectdir)/output")
end)
if is_arch("x86") then
fname = "weasel.ime"
elseif is_arch("x64") then
fname = "weaselx64.ime"
elseif is_arch("arm") then
fname = "weaselARM.ime"
elseif is_arch("arm64") then
fname = "weaselARM64.ime"
end
set_filename(fname)

4 changes: 4 additions & 0 deletions WeaselIPC/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target("WeaselIPC")
set_kind("static")
add_files("./*.cpp")

4 changes: 4 additions & 0 deletions WeaselIPCServer/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target("WeaselIPCServer")
set_kind("static")
add_files("./*.cpp")

27 changes: 27 additions & 0 deletions WeaselServer/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
target("WeaselServer")
set_kind("binary")
add_files("./*.cpp")
add_rules("add_rcfiles", "subwin")
add_links("imm32", "kernel32", "rime")
add_deps("WeaselUI", "WeaselIPC", "RimeWithWeasel", "WeaselIPCServer")

add_files("$(projectdir)/PerMonitorHighDPIAware.manifest")
add_ldflags("/DEBUG /OPT:REF /OPT:ICF /LARGEADDRESSAWARE /ERRORREPORT:QUEUE")
set_policy("windows.manifest.uac", "invoker")
before_build(function(target)
local target_dir = path.join(target:targetdir(), target:name())
if not os.exists(target_dir) then
os.mkdir(target_dir)
end
target:set("targetdir", target_dir)
end)
after_build(function(target)
if is_arch("x86") then
os.cp(path.join(target:targetdir(), "WeaselServer.exe"), "$(projectdir)/output/Win32")
os.cp(path.join(target:targetdir(), "WeaselServer.pdb"), "$(projectdir)/output/Win32")
else
os.cp(path.join(target:targetdir(), "WeaselServer.exe"), "$(projectdir)/output")
os.cp(path.join(target:targetdir(), "WeaselServer.pdb"), "$(projectdir)/output")
end
end)

33 changes: 33 additions & 0 deletions WeaselSetup/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
target("WeaselSetup")
set_kind("binary")
add_files("./*.cpp")
add_rules("add_rcfiles", "use_weaselconstants", "subwin")
add_links("imm32", "kernel32")

set_policy("windows.manifest.uac", "admin")
add_files("$(projectdir)/PerMonitorHighDPIAware.manifest")
add_ldflags("/DEBUG /OPT:REF /OPT:ICF /LARGEADDRESSAWARE /ERRORREPORT:QUEUE")

before_build(function(target)
local target_dir = path.join(target:targetdir(), target:name())
if not os.exists(target_dir) then
os.mkdir(target_dir)
end
target:set("targetdir", target_dir)
local level = target:policy("windows.manifest.uac")
if level then
local level_maps = {
invoker = "asInvoker",
admin = "requireAdministrator",
highest = "highestAvailable"
}
assert(level_maps[level], "unknown uac level %s, please set invoker, admin or highest", level)
local ui = target:policy("windows.manifest.uac.ui") or false
target:add("ldflags", "/manifest:embed", {("/manifestuac:level='%s' uiAccess='%s'"):format(level_maps[level], ui)}, {force = true, expand = false})
end
end)

after_build(function(target)
os.cp(path.join(target:targetdir(), "WeaselSetup.exe"), "$(projectdir)/output")
os.cp(path.join(target:targetdir(), "WeaselSetup.pdb"), "$(projectdir)/output")
end)
31 changes: 31 additions & 0 deletions WeaselTSF/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
target("WeaselTSF")
set_kind("shared")
add_files("./*.cpp", "WeaselTSF.def")
add_rules("add_rcfiles", "use_weaselconstants")
add_deps("WeaselIPC", "WeaselUI")
local fname = ''
if is_arch("x86") then
fname = "weasel.dll"
elseif is_arch("x64") then
fname = "weaselx64.dll"
elseif is_arch("arm") then
fname = "weaselARM.dll"
elseif is_arch("arm64") then
fname = "weaselARM64.dll"
end
set_filename(fname)

add_files("$(projectdir)/PerMonitorHighDPIAware.manifest")
add_shflags("/DEBUG /OPT:REF /OPT:ICF")
before_build(function(target)
local target_dir = path.join(target:targetdir(), target:name())
if not os.exists(target_dir) then
os.mkdir(target_dir)
end
target:set("targetdir", target_dir)
end)

after_build(function(target)
os.cp(path.join(target:targetdir(), "weasel*.dll"), "$(projectdir)/output")
os.cp(path.join(target:targetdir(), "weasel*.pdb"), "$(projectdir)/output")
end)
4 changes: 4 additions & 0 deletions WeaselUI/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target("WeaselUI")
set_kind("static")
add_files("./*.cpp")

16 changes: 8 additions & 8 deletions install-clang-format.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
rem 64 bit system
rem powershell -Command "(New-Object Net.WebClient).DownloadFile('https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.6/LLVM-17.0.6-win64.exe', 'LLVM-17.0.6-win64.exe')"
rem LLVM-17.0.6-win64.exe /S
rem powershell -Command "(New-Object Net.WebClient).DownloadFile('https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.6/LLVM-18.1.6-win64.exe', 'LLVM-18.1.6-win64.exe')"
rem LLVM-18.1.6-win64.exe /S
rem or maybe
rem output/7z.exe e LLVM-17.0.6-win64.exe bin/clang-format.exe -o.
rem rm LLVM-17.0.6-win64.exe
rem output/7z.exe e LLVM-18.1.6-win64.exe bin/clang-format.exe -o.
rem rm LLVM-18.1.6-win64.exe
) else (
rem 32 bit system
rem powershell -Command "(New-Object Net.WebClient).DownloadFile('https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.6/LLVM-17.0.6-win32.exe', 'LLVM-17.0.6-win32.exe')"
rem LLVM-17.0.6-win32.exe /S
rem powershell -Command "(New-Object Net.WebClient).DownloadFile('https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.6/LLVM-18.1.6-win32.exe', 'LLVM-18.1.6-win32.exe')"
rem LLVM-18.1.6-win32.exe /S
rem or maybe
rem output/7z.exe e LLVM-17.0.6-win32.exe bin/clang-format.exe -o.
rem rm LLVM-17.0.6-win32.exe
rem output/7z.exe e LLVM-18.1.6-win32.exe bin/clang-format.exe -o.
rem rm LLVM-18.1.6-win32.exe
)
pause
12 changes: 12 additions & 0 deletions test/TestResponseParser/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
target("TestResponseParser")
set_kind("binary")
add_files("./*.cpp")
add_deps("WeaselIPC", "WeaselIPCServer")
add_rules("subcmd")
before_build(function(target)
local target_dir = path.join(target:targetdir(), target:name())
if not os.exists(target_dir) then
os.mkdir(target_dir)
end
target:set("targetdir", target_dir)
end)
12 changes: 12 additions & 0 deletions test/TestWeaselIPC/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
target("TestWeaselIPC")
set_kind("binary")
add_files("./*.cpp")
add_deps("WeaselIPC", "WeaselIPCServer")
add_rules("subcmd")
before_build(function(target)
local target_dir = path.join(target:targetdir(), target:name())
if not os.exists(target_dir) then
os.mkdir(target_dir)
end
target:set("targetdir", target_dir)
end)
Loading