Refactor justfile

This commit is contained in:
Aoran Zeng 2025-06-20 19:14:56 +08:00
parent 7e629fe96d
commit 765da083da
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
2 changed files with 50 additions and 40 deletions

View File

@ -86,20 +86,22 @@ make clean
### 编译运行
```bash
just # 在Windows上默认使用 gcc 编译在macOS上默认使用 clang 编译,在其他系统上默认使用 cc 编译
just (b) # 在Windows上默认使用 gcc 编译在macOS上默认使用 clang 编译,在其他系统上默认使用 cc 编译
just CC=clang # 使用 clang 编译
just CC=gcc # 使用 gcc 编译
# 编译出 debug 版本: chsrc-debug
just bd
# 编译出 release 版本: chsrc-release
just br
```
```bash
# 启动 GDB 调试
# 重新编译出 ./chsrc-debug启动 GDB 调试 (在macOS上启动 LLDB 调试)
$ just debug
# 使用 LLDB 调试
# 使用其他调试器,如 LLDB 调试
$ just DEBUGGER=lldb debug
# 如果需要单独生成含有编译信息的二进制文件这个不会自己启动debugger
$ just DEBUG=1
```
<br>

View File

@ -9,16 +9,23 @@
# Created On : <2025-06-18>
# Last Modified : <2025-06-20>
#
# just (build)
# 该文件主要用于在原生Windows上执行项目的基本任务而不借助于
# GNU make 以及相应的 MSYS2、Cygwin 环境
# --------------------------------------------------------------
# just (build) -> chsrc.exe
# just bd (build-in-debug-mode) -> chsrc-debug.exe
# just br (build-in-release-mode) -> chsrc-release.exe
# just debug
# just test
# just clean
#
# just STATIC=1 # 静态链接
# just DEBUG=1 # 编译出 debug 版
# just STATIC=1 br 静态链接 (注意只能在 br 任务中使用)
#
# 该文件主要用于在原生Windows上执行项目的基本任务而不借助于
# GNU make 以及相应的 MSYS2、Cygwin 环境
# 不支持 just DEBUG=1请直接使用 just bd (等价于 just build-in-debug-mode)
#
# --------------------------------------------------------------
# 注意,由于我们要在 GitHub Actions 上编译 x32 版的 chsrc所以需要使用 make
# 而不清楚 just 在 MINGW32 中的情况,所以我们在此 justfile 中并不实现关于 CI 的功能
# --------------------------------------------------------------
set windows-shell := ['cmd', '/c']
@ -31,49 +38,53 @@ CC := if os() == 'windows' {
"cc"
}
DEBUGGER := 'gdb'
DEBUGGER := if os() == 'windows' {
"gdb"
} else if os() == 'macos' {
"lldb"
} else {
"gdb"
}
CFLAGS_base := '-Iinclude -Ilib'
CFLAGS_for_Clang := if os() == 'windows' {
CFLAGS_chk_Clang := if os() == 'windows' {
if CC == 'clang' {
'-target x86_64-pc-windows-gnu'
} else {''}
} else {''}
CFLAGS_base := '-Iinclude -Ilib ' + CFLAGS_chk_Clang
WARN := '-Wall -Wextra -Wno-unused-variable -Wno-unused-function -Wno-missing-braces -Wno-misleading-indentation' + ' ' + \
'-Wno-missing-field-initializers -Wno-unused-parameter -Wno-sign-compare'
CFLAGS_warn := WARN
DEBUG := '0'
CFLAGS_debug := if DEBUG != '0' { "-g" } else { "" }
CFLAGS_debug := '-g -DXY_DEBUG'
DevMode-Target-Name := 'chsrc'
DebugMode-Target-Name := 'chsrc-debug'
ReleaseMode-Target-Name := 'chsrc-release'
CI := '0'
CI_ARTIFACT_NAME := 'chsrc'
STATIC := '0'
# 在 GitHub Actions 时的 Linux 环境下just CI=1 时触发
CFLAGS_static := if STATIC == '1' {
"-static"
} else if os() == 'linux' {
if CI == '1' {"-static"} else {''}
} else {''}
CFLAGS_static := "-static"
CFLAGS_chk_static := if STATIC == '1' {
CFLAGS_static
} else { "" }
# CFLAGS := CFLAGS_base + ' ' + CFLAGS_debug + ' ' + CFLAGS_warn + ' ' + CFLAGS_static + ' ' + CFLAGS_for_Clang
CFLAGS_optimization := "-O2"
CFLAGS_dev_mode := CFLAGS_base + ' ' + CFLAGS_warn + ' ' + ' ' + CFLAGS_for_Clang
CFLAGS_debug_mode := CFLAGS_base + ' ' + CFLAGS_debug + ' ' + CFLAGS_warn + ' ' + CFLAGS_for_Clang
CFLAGS_release_mode := CFLAGS_base + ' ' + CFLAGS_warn + ' ' + CFLAGS_static + ' ' + CFLAGS_for_Clang
CFLAGS_prompt := CFLAGS_base + ' ' + CFLAGS_debug + CFLAGS_static + CFLAGS_for_Clang
CFLAGS_dev_mode_prompt := CFLAGS_base
CFLAGS_debug_mode_prompt := CFLAGS_base + ' ' + CFLAGS_debug
CFLAGS_release_mode_prompt := CFLAGS_base + ' ' + CFLAGS_optimization + ' ' + CFLAGS_chk_static
CFLAGS_dev_mode := CFLAGS_dev_mode_prompt + ' ' + CFLAGS_warn
CFLAGS_debug_mode := CFLAGS_debug_mode_prompt + ' ' + CFLAGS_warn
CFLAGS_release_mode := CFLAGS_release_mode_prompt + ' ' + CFLAGS_warn
#=======================
@ -84,29 +95,29 @@ BIN_rm := if os() == 'windows' {'del'} else {'rm'}
alias b := build-in-dev-mode
alias bd:= build-in-debug-mode
alias br:= build-in-release-mode
alias build:=build-in-dev-mode
alias d := debug
alias t := test
alias check := test
alias c := clean
default: build-in-dev-mode
build-in-dev-mode:
@echo Starting: Build in DEV mode: '{{CC}}' {{CFLAGS_prompt}} -o {{DevMode-Target-Name}}
@echo Starting: Build in DEV mode: '{{CC}}' {{CFLAGS_dev_mode_prompt}} -o {{DevMode-Target-Name}}
@{{CC}} src/chsrc-main.c {{CFLAGS_dev_mode}} -o {{DevMode-Target-Name}}
@echo Finished: Build in DEV mode
build-in-debug-mode:
@echo Starting: Build in DEBUG mode: '{{CC}}' {{CFLAGS_prompt}} -o {{DebugMode-Target-Name}}
@echo Starting: Build in DEBUG mode: '{{CC}}' {{CFLAGS_debug_mode_prompt}} -o {{DebugMode-Target-Name}}
@{{CC}} src/chsrc-main.c {{CFLAGS_debug_mode}} -o {{DebugMode-Target-Name}}
@echo Finished: Build in DEBUG mode
build-in-release-mode:
@echo Starting: Build in RELEASE mode: '{{CC}}' {{CFLAGS_prompt}} -o {{ReleaseMode-Target-Name}}
@echo Starting: Build in RELEASE mode: '{{CC}}' {{CFLAGS_release_mode_prompt}} -o {{ReleaseMode-Target-Name}}
@{{CC}} src/chsrc-main.c {{CFLAGS_release_mode}} -o {{ReleaseMode-Target-Name}}
@echo Finished: Build in RELEASE mode
CI: build-in-dev-mode
@mv {{ReleaseMode-Target-Name}} {{CI_ARTIFACT_NAME}}
debug: build-in-debug-mode
@{{DEBUGGER}} {{DebugMode-Target-Name}}
@ -120,9 +131,6 @@ test-fw:
@{{CC}} test/fw.c {{CFLAGS_dev_mode}} -o fw
@{{BIN_fw}}
check: test
fastcheck:
@perl ./test/cli.pl fastcheck