Skip to content

Commit f168679

Browse files
build: update package workflow (#307)
Co-authored-by: star9029 <hengxings783@gmail.com>
1 parent 4d07bad commit f168679

File tree

8 files changed

+186
-113
lines changed

8 files changed

+186
-113
lines changed

.github/workflows/check-format.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ on:
77
pull_request:
88
branches: [main]
99

10-
1110
jobs:
1211
check:
1312
runs-on: ubuntu-latest

.github/workflows/cmake.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ jobs:
6464
6565
- name: Setup dependencies (MacOS)
6666
if: runner.os == 'macOS'
67+
env:
68+
HOMEBREW_NO_AUTO_UPDATE: 1
6769
run: |
6870
brew install llvm@20 lld@20
6971

.github/workflows/package.yml

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: package
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
push:
8+
tags:
9+
- "v*"
10+
11+
pull_request:
12+
branches: [main]
13+
paths:
14+
- ".github/workflows/package.yml"
15+
16+
jobs:
17+
package:
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
include:
22+
- os: windows-2025
23+
artifact_name: clice.zip
24+
asset_name: clice-x64-windows-msvc.zip
25+
symbol_artifact_name: clice-symbol.zip
26+
symbol_asset_name: clice-x64-windows-msvc-symbol.zip
27+
toolchain: clang-cl
28+
29+
- os: ubuntu-24.04
30+
artifact_name: clice.tar.gz
31+
asset_name: clice-x86_64-linux-gnu.tar.gz
32+
symbol_artifact_name: clice-symbol.tar.gz
33+
symbol_asset_name: clice-x86_64-linux-gnu-symbol.tar.gz
34+
toolchain: clang-20
35+
36+
- os: macos-15
37+
artifact_name: clice.tar.gz
38+
asset_name: clice-arm64-macos-darwin.tar.gz
39+
symbol_artifact_name: clice-symbol.tar.gz
40+
symbol_asset_name: clice-arm64-macos-darwin-symbol.tar.gz
41+
toolchain: clang
42+
43+
runs-on: ${{ matrix.os }}
44+
45+
steps:
46+
- name: Free disk space (Linux)
47+
if: runner.os == 'Linux'
48+
uses: jlumbroso/free-disk-space@main
49+
50+
- name: Increase swap file size (Linux)
51+
if: runner.os == 'Linux'
52+
run: |
53+
echo "===== Initial Status ====="
54+
sudo swapon --show
55+
free -h
56+
57+
echo "===== Creating Swap File ====="
58+
sudo swapoff -a
59+
sudo fallocate -l 16G /mnt/swapfile
60+
sudo chmod 600 /mnt/swapfile
61+
sudo mkswap /mnt/swapfile
62+
sudo swapon /mnt/swapfile
63+
64+
echo "===== Final Status ====="
65+
sudo swapon --show
66+
free -h
67+
df -h
68+
69+
- name: Setup dependencies (Linux)
70+
if: runner.os == 'Linux'
71+
run: |
72+
sudo apt update
73+
sudo apt install -y gcc-14 g++-14 libstdc++-14-dev cmake ninja-build
74+
75+
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 100
76+
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 100
77+
sudo update-alternatives --set gcc /usr/bin/gcc-14
78+
sudo update-alternatives --set g++ /usr/bin/g++-14
79+
80+
wget https://apt.llvm.org/llvm.sh
81+
chmod +x llvm.sh
82+
sudo ./llvm.sh 20 all
83+
84+
- name: Setup dependencies (MacOS)
85+
if: runner.os == 'macOS'
86+
env:
87+
HOMEBREW_NO_AUTO_UPDATE: 1
88+
run: |
89+
brew install llvm@20 lld@20
90+
91+
- name: Checkout repository
92+
uses: actions/checkout@v4
93+
94+
- name: Setup xmake
95+
uses: xmake-io/github-action-setup-xmake@v1
96+
with:
97+
xmake-version: 3.0.4
98+
actions-cache-folder: ".xmake-cache"
99+
actions-cache-key: ${{ matrix.os }}
100+
package-cache: true
101+
package-cache-key: ${{ matrix.os }}-pkg-release-v1
102+
build-cache: true
103+
build-cache-key: ${{ matrix.os }}-build-release-v1
104+
105+
- name: Configure and Package
106+
shell: bash
107+
run: |
108+
if [[ "${{ runner.os }}" == "Windows" ]]; then
109+
xmake config --yes --enable_test=n --dev=n --release=y --mode=releasedbg --toolchain=${{ matrix.toolchain }} -p windows
110+
elif [[ "${{ runner.os }}" == "Linux" ]]; then
111+
xmake config --yes --enable_test=n --dev=n --release=y --mode=releasedbg --toolchain=${{ matrix.toolchain }}
112+
elif [[ "${{ runner.os }}" == "macOS" ]]; then
113+
export PATH="/opt/homebrew/opt/llvm@20/bin:/opt/homebrew/opt/lld@20/bin:$PATH"
114+
xmake config --yes --enable_test=n --dev=n --release=y --mode=releasedbg --toolchain=${{ matrix.toolchain }} --sdk=/opt/homebrew/opt/llvm@20
115+
fi
116+
117+
xmake pack -v
118+
119+
- name: Upload Main Package to Release
120+
if: github.event_name == 'push'
121+
uses: svenstaro/upload-release-action@v2
122+
with:
123+
repo_token: ${{ secrets.GITHUB_TOKEN }}
124+
file: build/xpack/clice/${{ matrix.artifact_name }}
125+
asset_name: ${{ matrix.asset_name }}
126+
tag: ${{ github.ref }}
127+
overwrite: true
128+
129+
- name: Upload Symbol Package to Release
130+
if: github.event_name == 'push'
131+
uses: svenstaro/upload-release-action@v2
132+
with:
133+
repo_token: ${{ secrets.GITHUB_TOKEN }}
134+
file: build/xpack/clice/${{ matrix.symbol_artifact_name }}
135+
asset_name: ${{ matrix.symbol_asset_name }}
136+
tag: ${{ github.ref }}
137+
overwrite: true

.github/workflows/release.yml

Lines changed: 0 additions & 96 deletions
This file was deleted.

.github/workflows/xmake.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ jobs:
4949
5050
- name: Setup dependencies (MacOS)
5151
if: runner.os == 'macOS'
52+
env:
53+
HOMEBREW_NO_AUTO_UPDATE: 1
5254
run: |
5355
brew install llvm@20 lld@20
5456
@@ -66,19 +68,18 @@ jobs:
6668
build-cache: true
6769
build-cache-key: ${{ matrix.os }}-${{ matrix.build_type }}
6870

69-
- name: XMake configure
71+
- name: Build clice
7072
shell: bash
7173
run: |
7274
if [[ "${{ runner.os }}" == "Windows" ]]; then
7375
xmake config --yes --ci=y --mode=${{ matrix.build_type }} --toolchain=clang -p windows
7476
elif [[ "${{ runner.os }}" == "Linux" ]]; then
7577
xmake config --yes --ci=y --mode=${{ matrix.build_type }} --toolchain=clang-20
7678
elif [[ "${{ runner.os }}" == "macOS" ]]; then
79+
export PATH="/opt/homebrew/opt/llvm@20/bin:/opt/homebrew/opt/lld@20/bin:$PATH"
7780
xmake config --yes --ci=y --mode=${{ matrix.build_type }} --toolchain=clang --sdk=/opt/homebrew/opt/llvm@20
7881
fi
7982
80-
- name: Build clice
81-
run: |
8283
xmake build --verbose --diagnosis --all
8384
8485
- name: Install uv for integration tests

config/prebuilt-llvm.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"platform": "Windows",
1212
"build_type": "Release",
1313
"is_lto": true,
14-
"filename": "x64-windows-msvc-release-lto.7z",
14+
"filename": "x64-windows-msvc-releasedbg-lto.7z",
1515
"version": "21.1.4",
1616
"sha256": "7792cfd1e2d9240b49e3db81a6a04f33cbc44afa91e9a637c0490c28d4eee95c"
1717
},
@@ -35,7 +35,7 @@
3535
"platform": "Linux",
3636
"build_type": "Release",
3737
"is_lto": true,
38-
"filename": "x86_64-linux-gnu-release-lto.tar.xz",
38+
"filename": "x86_64-linux-gnu-releasedbg-lto.tar.xz",
3939
"version": "21.1.4",
4040
"sha256": "e5a6c567e30cbe51e4b98151f52071d0013839e7b5eabe7a2a2767c8234d06b2"
4141
},
@@ -59,7 +59,7 @@
5959
"platform": "macosx",
6060
"build_type": "Release",
6161
"is_lto": true,
62-
"filename": "arm64-macosx-apple-release-lto.tar.xz",
62+
"filename": "arm64-macosx-apple-releasedbg-lto.tar.xz",
6363
"version": "21.1.4",
6464
"sha256": "c92d0323ff83e678fec7496c8b024a64b1731c3840752be9a4ade3b99dfd52ff"
6565
}

include/Support/Logging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ template <typename... Args>
8787
void critical [[noreturn]] (logging_format<Args...> fmt, Args&&... args) {
8888
logging::log(spdlog::level::critical, fmt.location, fmt.str, std::forward<Args>(args)...);
8989
spdlog::shutdown();
90-
std::exit(1);
90+
std::abort();
9191
}
9292

9393
} // namespace clice::logging

xmake.lua

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,14 @@ target("clice-core")
118118
target("clice")
119119
set_kind("binary")
120120
add_files("bin/clice.cc")
121-
122121
add_deps("clice-core")
123122

123+
-- workaround
124+
-- @see https://github.com/xmake-io/xmake/issues/7029
125+
if is_plat("macosx") then
126+
set_toolset("dsymutil", "dsymutil")
127+
end
128+
124129
on_config(function(target)
125130
local llvm_dir = target:dep("clice-core"):pkg("llvm"):installdir()
126131
target:add("installfiles", path.join(llvm_dir, "lib/clang/(**)"), {prefixdir = "lib/clang"})
@@ -215,9 +220,9 @@ rule("clice_build_config")
215220
target:add("ldflags", "-fuse-ld=lld-link")
216221
end
217222
elseif target:is_plat("linux") then
218-
target:add("ldflags", "-fuse-ld=lld", "-Wl,--gc-sections")
223+
target:add("ldflags", "-fuse-ld=lld", "-static-libstdc++", "-Wl,--gc-sections")
219224
elseif target:is_plat("macosx") then
220-
target:add("ldflags", "-fuse-ld=lld", "-Wl,-dead_strip")
225+
target:add("ldflags", "-fuse-ld=lld", "-static-libc++", "-Wl,-dead_strip,-object_path_lto,clice.lto.o")
221226
end
222227

223228
if has_config("ci") then
@@ -310,19 +315,44 @@ if has_config("release") then
310315
xpack("clice")
311316
if is_plat("windows") then
312317
set_formats("zip")
313-
set_extension(".7z")
318+
set_extension(".zip")
314319
else
315320
set_formats("targz")
316-
set_extension(".tar.xz")
321+
set_extension(".tar.gz")
317322
end
318323

319324
set_prefixdir("clice")
320325

321326
add_targets("clice")
322-
add_installfiles(path.join(os.projectdir(), "docs/clice.toml"))
327+
-- add_installfiles(path.join(os.projectdir(), "docs/clice.toml"))
328+
329+
on_package(function (package)
330+
import("utils.archive")
331+
332+
local build_dir = path.absolute(package:install_rootdir())
333+
os.tryrm(build_dir)
334+
os.mkdir(build_dir)
335+
336+
local function clice_archive(output_file)
337+
local old_dir = os.cd(build_dir)
338+
local archive_files = os.files("**")
339+
os.cd(old_dir)
340+
os.tryrm(output_file)
341+
cprint("packing %s .. ", output_file)
342+
archive.archive(path.absolute(output_file), archive_files, {curdir = build_dir, compress = "best"})
343+
end
323344

324-
on_load(function(package)
325-
local llvm_dir = package:target("clice"):dep("clice-core"):pkg("llvm"):installdir()
326-
package:add("installfiles", path.join(llvm_dir, "lib/clang/(**)"), {prefixdir = "lib/clang"})
345+
local target = package:target("clice")
346+
os.vcp(target:symbolfile(), build_dir)
347+
clice_archive(path.join(package:outputdir(), "clice-symbol" .. package:extension()))
348+
349+
os.tryrm(build_dir)
350+
os.mkdir(path.join(build_dir, "bin"))
351+
os.vcp(target:targetfile(), path.join(build_dir, "bin"))
352+
os.vcp(path.join(os.projectdir(), "docs/clice.toml"), build_dir)
353+
354+
local llvm_dir = target:dep("clice-core"):pkg("llvm"):installdir()
355+
os.vcp(path.join(llvm_dir, "lib/clang"), path.join(build_dir, "lib/clang"))
356+
clice_archive(path.join(package:outputdir(), "clice" .. package:extension()))
327357
end)
328358
end

0 commit comments

Comments
 (0)