Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
3608012
basic debugger stepping test run to completion
NikitaSmith057 Apr 27, 2026
541c267
print out last captured output when a test fails or crashes
NikitaSmith057 Apr 28, 2026
6bb11fb
build debugger without asan
NikitaSmith057 Apr 28, 2026
9571eb2
skip debugger tests (there is no way to launch debugger without window)
NikitaSmith057 Apr 28, 2026
d7db57d
remove safe call so crashes in github actions print out callstack
NikitaSmith057 Apr 28, 2026
c0bea47
capture stderr and print out when test fails/crashes
NikitaSmith057 Apr 29, 2026
ac7ade3
test asan summary print in github actions
NikitaSmith057 Apr 29, 2026
51fe0af
minor fixes to basic stepping test
NikitaSmith057 Apr 29, 2026
d1c5f4d
bifurcate output into stderr and stdout
NikitaSmith057 Apr 29, 2026
d95a4a5
wire non graphical raddbg build target
NikitaSmith057 Apr 29, 2026
cfa4b52
explain failed launch
NikitaSmith057 Apr 29, 2026
ba52345
gen crash dumps
NikitaSmith057 Apr 29, 2026
8a2520b
query binary name in converter command line setup
NikitaSmith057 Apr 30, 2026
f0d6b6a
zip torture artifacts on run fail
NikitaSmith057 Apr 30, 2026
4284de2
simplify timeouts
NikitaSmith057 Apr 30, 2026
1fca6c9
use PID to find and kill running debugger after tests, and add automatic
NikitaSmith057 Apr 30, 2026
a2e566b
extend os info struct with binary file path
NikitaSmith057 Apr 30, 2026
85fc77e
add error messages in script runner and create a global default timeout
NikitaSmith057 May 1, 2026
18de8b8
minor fix
NikitaSmith057 May 1, 2026
49b86f2
clean up stepping test, and remove switch for overriding crash dump path
NikitaSmith057 May 1, 2026
fd3abd1
older bash compatibility improvements and use pkg-config library dete…
NikitaSmith057 May 1, 2026
367afdc
set executable permission bit on build.sh
NikitaSmith057 May 1, 2026
6319d85
set work directory for new process
NikitaSmith057 May 5, 2026
44ad77f
implement semaphore take with timeout
NikitaSmith057 May 5, 2026
94edf2d
fix process reap in the join API
NikitaSmith057 May 5, 2026
a606061
set torture as launch target
NikitaSmith057 May 5, 2026
baed0b5
add non-graphical debugger and torture targets
NikitaSmith057 May 5, 2026
157cea7
implement os wakeup
NikitaSmith057 May 13, 2026
55382b3
add switch to override default logs folder
NikitaSmith057 May 6, 2026
15bf51e
builds
NikitaSmith057 May 6, 2026
29573f8
increase wait time for memory slice in line stepping
NikitaSmith057 May 6, 2026
deebfec
add asan to build.sh
NikitaSmith057 May 7, 2026
52a6d2f
minor fixes
NikitaSmith057 May 8, 2026
8e4a0c8
new launch target
NikitaSmith057 May 6, 2026
0443c77
capture output on linux
NikitaSmith057 May 6, 2026
f218a8b
rename artifact folder so it does not collide with torture program on…
NikitaSmith057 May 6, 2026
a1a8e77
infer path style from top node
NikitaSmith057 May 8, 2026
d17ce87
event shadowing in dbg engine ctrl causes debugger to return incorrect
NikitaSmith057 May 8, 2026
97d6dff
delete unnecessary helper
NikitaSmith057 May 8, 2026
f0a7df6
add file reserve Linux OS API for radlink
NikitaSmith057 May 8, 2026
abc331b
null check semaphore otherwise sem_* crashes
NikitaSmith057 May 8, 2026
98d312e
enable 16-byte CAS intrinsic
NikitaSmith057 May 8, 2026
e629b73
more targets
NikitaSmith057 May 8, 2026
f51942c
headers for Linux OS layer
NikitaSmith057 May 8, 2026
e613960
update stepping test to produce a fixed exe on windows
NikitaSmith057 May 8, 2026
421975a
move linker id helper to the main file so we can use it in other torture
NikitaSmith057 May 8, 2026
974dc79
disable radlink tests for windows
NikitaSmith057 May 8, 2026
80b005c
various fixes in torture for Linux compatibility
NikitaSmith057 May 8, 2026
fcb21b2
make test ignore slashes
NikitaSmith057 May 8, 2026
7c77c97
hack-in temp backslash for windows
NikitaSmith057 May 8, 2026
2a8aea7
switch for launching debugger with window
NikitaSmith057 May 8, 2026
cf26ba9
guard against relative path nodes
NikitaSmith057 May 8, 2026
57d2b2a
workaround os_get_current_path
NikitaSmith057 May 8, 2026
54f50c1
run tests on Linux
NikitaSmith057 May 8, 2026
71b1aee
update nuke
NikitaSmith057 May 8, 2026
88d64e0
enable stepping test
NikitaSmith057 May 8, 2026
55dd674
add Ubuntu build and torture steps to GH actions
NikitaSmith057 May 8, 2026
ab19bb4
on windows test clang in release without asan
NikitaSmith057 May 9, 2026
a16af71
use run_tests.sh to drive builds.yml
NikitaSmith057 May 9, 2026
a8b360e
run_tests -> run
NikitaSmith057 May 9, 2026
1b10c7b
delete debug code
NikitaSmith057 May 9, 2026
b01988c
run
NikitaSmith057 May 9, 2026
a876500
process join
NikitaSmith057 May 9, 2026
52ab501
minor fix
NikitaSmith057 May 9, 2026
7c02560
on error restore PATH
NikitaSmith057 May 9, 2026
305cfe8
tidy up names in builds.yml
NikitaSmith057 May 9, 2026
be69fa6
replace hard-coded visual studio path with vswhere
NikitaSmith057 May 9, 2026
0bd6daa
fill out address
NikitaSmith057 May 9, 2026
9c83063
dbg_engine: bugfix memory fetch in step_over, step_over_inst, and ste…
NikitaSmith057 May 11, 2026
366ba1d
dbg_engine: extend trap-net range across contiguous same-source-line …
NikitaSmith057 May 12, 2026
c4ae256
file endings
NikitaSmith057 May 11, 2026
d31cea7
torture_dbg: reuse Windows env-var expander in the harness compile/li…
NikitaSmith057 May 12, 2026
0289ab7
rebase fixes
NikitaSmith057 May 12, 2026
490df36
gate for dwarf converter
NikitaSmith057 May 12, 2026
bb2dee2
sanity-check scissor region, fix var shadowing bug in blur GLSL shader,
NikitaSmith057 May 12, 2026
6fc10a4
fix regression introduced in aea4a4ff
NikitaSmith057 May 13, 2026
2cec470
update defines for non-graphical debugger build
NikitaSmith057 May 13, 2026
db818ab
run clang build for now
NikitaSmith057 May 13, 2026
93ef560
change make_directory behavior on Linux to match Windows behavior
NikitaSmith057 May 13, 2026
1349837
open generated files as binary so we have consistent line endings across
NikitaSmith057 May 13, 2026
00cf60f
normalize line endings in generated files
NikitaSmith057 May 13, 2026
7aecb71
mismatched type on 'blur_count'
NikitaSmith057 May 13, 2026
728e627
todo
NikitaSmith057 May 13, 2026
e7e7173
rebase
NikitaSmith057 May 14, 2026
e221139
update tests summary
NikitaSmith057 May 16, 2026
61b2ff0
more /OPT:REF tests
NikitaSmith057 May 16, 2026
6f9068f
debug util for PDB section map
NikitaSmith057 May 16, 2026
7648063
rebase fixes
NikitaSmith057 May 19, 2026
d11a01e
first popped value off the stack is right-hand-side
NikitaSmith057 May 19, 2026
6b333c8
wire DWARF expression eval to the unwinder
NikitaSmith057 May 19, 2026
7603aae
debug stats for /OPT:REF
NikitaSmith057 May 19, 2026
ec11346
fix linux build
NikitaSmith057 May 19, 2026
9dacf07
dump RDI local vars
NikitaSmith057 May 20, 2026
8fa2d65
pass over default theme
ryanfleury May 20, 2026
e634de8
p2r: more carefully choose symbol chunk sizes - we were spending dram…
ryanfleury May 20, 2026
1b546d6
project files
ryanfleury May 20, 2026
8645f5c
update .gitattributes to set LF endings on meta files so metagen
NikitaSmith057 May 20, 2026
c426121
cleanup atomic wrappers
mmozeiko May 20, 2026
6c157d4
more aggressively use scratch & limit temporary allocations in rdi baker
ryanfleury May 20, 2026
71de1ad
eval: use resolution qualifiers to express disambiguating debug info,…
ryanfleury May 20, 2026
91c7355
improve error handling in the debugger harness (source file + line
NikitaSmith057 May 21, 2026
7ab508c
step into tests
NikitaSmith057 May 21, 2026
739dcf7
broadcasting a stack pointer and then leaving scope in optimized
NikitaSmith057 May 21, 2026
db4bd47
report radbin errors
NikitaSmith057 May 21, 2026
649c868
remove eval_compiler_basics
NikitaSmith057 May 21, 2026
194c31f
first pass at per-target output log labels
ryanfleury May 21, 2026
e0567d3
show line info on visualizing function evaluations
ryanfleury May 21, 2026
5234bb3
get default symbol path as part of process info; sketch out windows-s…
ryanfleury May 21, 2026
c9e751c
use the make library to generate RDI
NikitaSmith057 May 22, 2026
13cd2a3
fix up scratch conflicts
NikitaSmith057 May 22, 2026
b2ab5c1
use GetForegroundWindow for foucs detection with parented debuggers
NikitaSmith057 May 22, 2026
caac724
only send ack on catch-all path for external driver cmds
ryanfleury May 22, 2026
c54b10e
set CLOCK_MONOTONIC on conditional variables
NikitaSmith057 May 22, 2026
d15cc09
simplify testing ipc driving stuff in raddbg layer; put in formal eva…
ryanfleury May 21, 2026
762d194
send acks always
ryanfleury May 21, 2026
8ff5525
update IPC parser
NikitaSmith057 May 22, 2026
bfe175e
split voff_range into two fields
NikitaSmith057 May 22, 2026
1402517
skip DWARF line table and checksum tests
NikitaSmith057 May 22, 2026
308144e
do not assume nonzero namespace table slots
ryanfleury May 22, 2026
29becc3
export line and column numbers from MD
NikitaSmith057 May 23, 2026
b57653f
review pthread_* return values
debiatan May 23, 2026
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
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*.sh text=auto eol=lf
src/lib_rdi/rdi.h text=auto eol=lf
src/lib_rdi/rdi.c text=auto eol=lf
generated/*.meta.* text=auto eol=lf
215 changes: 144 additions & 71 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
@@ -1,71 +1,144 @@
name: builds

on:
push:
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'

jobs:
build-windows-2022:
runs-on: windows-2025
strategy:
fail-fast: false
matrix:
target:
- raddbg
- radlink
- radbin
- mule_main
compiler:
- msvc
- clang
mode:
- debug
- release
steps:
- name: checkout
uses: actions/checkout@v6
- name: build (vs 2022)
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
call build meta "${{ matrix.target }}" "${{ matrix.compiler }}" "${{ matrix.mode }}" || exit /b 1

run-torture:
runs-on: windows-2025
strategy:
fail-fast: false
matrix:
compiler:
- msvc
- clang
mode:
- debug
- release
exclude:
- { compiler: clang, mode: release } # clang runs OOM in release with ASAN
steps:
- name: checkout
uses: actions/checkout@v6
- name: run-torture
shell: cmd
run: |
rem find path to clang
for /f "tokens=*" %%i in ('where clang') do set clang_path=%%~dpi

call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64

rem set clang path before MSVC's clang path
set PATH=%clang_path%;%PATH%

rem parse out clang version number out of --version to build path to the folder with ASAN DLL
for /f "tokens=3 delims=. " %%v in ('clang -v 2^>^&1 ^| findstr version') do set clang_version=%%v
if "${{matrix.compiler}}" == "clang" set PATH=%clang_path%..\lib\clang\%clang_version%\lib\windows;%PATH%

call build asan meta torture radlink radbin mule_main mule_module "${{matrix.mode}}" "${{matrix.compiler}}" || exit /b 1
cd build
torture || exit /b 1

name: builds

on:
push:
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'

# TODO: fix skips
env:
TORTURE_FLAGS: "--gen_crash_dump -s:d2r::d2r_line_table,d2r::d2r_checksums"

jobs:
build-ubuntu-24-04:
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
target:
- raddbg
- raddbg_non_graphical
- radlink
- radbin
- torture
compiler:
- clang-22
# TODO: - gcc
mode:
- debug
- release
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install Dependencies
shell: bash
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-add-repository -y "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-22 main"
sudo apt-get update
sudo apt-get install -y clang-22 lld-22 llvm-22 gcc-14 pkg-config libfreetype6-dev libx11-dev libxext-dev libgl1-mesa-dev libegl1-mesa-dev
sudo ln -s /usr/bin/llvm-symbolizer-22 /usr/bin/llvm-symbolizer
- name: build
shell: bash
run: |
CC="${{ matrix.compiler }}" ./build.sh "${{ matrix.target }}" "${{ matrix.mode }}"

build-windows-2022:
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
target:
- raddbg
- radlink
- radbin
- mule_main
compiler:
- msvc
- clang
mode:
- debug
- release
steps:
- name: Checkout
uses: actions/checkout@v6
- name: build (vs 2022)
shell: cmd
run: |
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set "VS_INSTALL=%%i"
call "%VS_INSTALL%\VC\Auxiliary\Build\vcvarsall.bat" x64
call build meta "${{ matrix.target }}" "${{ matrix.compiler }}" "${{ matrix.mode }}" || exit /b 1

run-ubuntu-24-04:
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
compiler:
- clang-22
# TODO: - gcc
mode:
- debug
# TODO: - release
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install Dependencies
shell: bash
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-add-repository -y "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-22 main"
sudo apt-get update
sudo apt-get install -y clang-22 lld-22 llvm-22 gcc-14 pkg-config libfreetype6-dev libx11-dev libxext-dev libgl1-mesa-dev libegl1-mesa-dev
# crash callstack symbolizer depends on LLVM
sudo ln -s /usr/bin/llvm-symbolizer-22 /usr/bin/llvm-symbolizer
- name: Run
shell: bash
run: |
CC="${{ matrix.compiler }}" ./run.sh clang "${{ matrix.mode }}" -- $TORTURE_FLAGS
- name: Upload Artifacts
if: failure()
uses: actions/upload-artifact@v7
with:
name: torture-crash-dumps-${{ matrix.compiler }}-${{ matrix.mode }}
path: |
build/*.core
build/*.exe
build/*.pdb
build/torture_artifacts/**
if-no-files-found: ignore

run-windows-2022:
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
compiler:
- msvc
- clang
mode:
- debug
- release
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Run
shell: cmd
run: |
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set "VS_INSTALL=%%i"
call "%VS_INSTALL%\VC\Auxiliary\Build\vcvarsall.bat" x64
call run.bat ${{ matrix.compiler }} ${{ matrix.mode }} -- %TORTURE_FLAGS% || exit /b 1
- name: Upload Artifacts
if: failure()
uses: actions/upload-artifact@v7
with:
name: torture-crash-dumps-${{ matrix.compiler }}-${{ matrix.mode }}
path: |
build/*.dmp
build/*.exe
build/*.pdb
build/torture_artifacts/**
if-no-files-found: ignore
4 changes: 3 additions & 1 deletion build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ set cl_link= /link /MANIFEST:EMBED /INCREMENTAL:NO /pdbaltpath:%%%%_PDB%%%
set cl_out= /out:
set cl_obj_out= /Fo:
set cl_linker=
set clang_common= -I..\src\ -I..\local\ -fdiagnostics-absolute-paths -Wall -Wno-unknown-warning-option -Wno-missing-braces -Wno-unused-function -Wno-unused-parameter -Wno-writable-strings -Wno-missing-field-initializers -Wno-unused-value -Wno-unused-variable -Wno-unused-local-typedef -Wno-deprecated-register -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-single-bit-bitfield-constant-conversion -Wno-compare-distinct-pointer-types -Wno-initializer-overrides -Wno-incompatible-pointer-types-discards-qualifiers -Xclang -flto-visibility-public-std -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf -ferror-limit=10000 -mcx16 -msha
set clang_common= -mcx16 -msha -I..\src\ -I..\local\ -fdiagnostics-absolute-paths -Wall -Wno-unknown-warning-option -Wno-missing-braces -Wno-unused-function -Wno-unused-parameter -Wno-writable-strings -Wno-missing-field-initializers -Wno-unused-value -Wno-unused-variable -Wno-unused-local-typedef -Wno-deprecated-register -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-single-bit-bitfield-constant-conversion -Wno-compare-distinct-pointer-types -Wno-initializer-overrides -Wno-incompatible-pointer-types-discards-qualifiers -Xclang -flto-visibility-public-std -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf -ferror-limit=10000
set clang_debug= call clang -g -O0 -DBUILD_DEBUG=1 -D_DEBUG %clang_common% %auto_compile_flags%
set clang_release= call clang -g -O2 -DBUILD_DEBUG=0 -DNDEBUG %clang_common% %auto_compile_flags%
set clang_link= -fuse-ld=lld -Xlinker /MANIFEST:EMBED -Xlinker /pdbaltpath:%%%%_PDB%%%% -Xlinker /NATVIS:"%~dp0\src\natvis\base.natvis" -Xlinker /opt:ref -Xlinker /opt:noicf
Expand Down Expand Up @@ -140,6 +140,7 @@ popd
:: --- Build Everything (@build_targets) --------------------------------------
pushd build
if "%raddbg%"=="1" set didbuild=1 && %compile% ..\src\raddbg\raddbg_main.c %compile_link% %link_icon% %out%raddbg.exe || exit /b 1
if "%raddbg_non_graphical%"=="1" set didbuild=1 && %compile% -DWM_STUB=1 -DWM_STUB_DEFAULT_REFRESH_RATE=60.f -DR_BACKEND=R_BACKEND_STUB ..\src\raddbg\raddbg_main.c %compile_link% %link_icon% %out%raddbg_non_graphical.exe || exit /b 1
if "%radlink%"=="1" set didbuild=1 && %compile% ..\src\linker\lnk.c %compile_link% %linker% /NOIMPLIB %linker% /NATVIS:"%~dp0\src\linker\linker.natvis" %out%radlink.exe || exit /b 1
if "%radbin%"=="1" set didbuild=1 && %compile% ..\src\radbin\radbin_main.c %compile_link% %out%radbin.exe || exit /b 1
if "%raddump%"=="1" set didbuild=1 && %compile% ..\src\raddump\raddump_main.c %compile_link% %out%raddump.exe || exit /b 1
Expand All @@ -154,6 +155,7 @@ if "%mule_module%"=="1" set didbuild=1 && %compile% ..\src\mule\m
if "%mule_hotload%"=="1" set didbuild=1 && %compile% ..\src\mule\mule_hotload_main.c %compile_link% %out%mule_hotload.exe & %compile% ..\src\mule\mule_hotload_module_main.c %compile_link% %link_dll% %out%mule_hotload_module.dll || exit /b 1
if "%torture%"=="1" set didbuild=1 && %compile% ..\src\torture\torture_main.c %compile_link% %out%torture.exe || exit /b1
if "%dwarf_expr_test%"=="1" set didbuild=1 && %compile% ..\src\torture\dwarf_expr_test.c %compile_link% %out%dwarf_expr_test.exe || exit /b1
if "%unit_sizes_from_pdb%"=="1" set didbuild=1 && %compile% ..\src\scratch\unit_sizes_from_pdb.c %compile_link% %out%unit_sizes_from_pdb.exe || exit /b1
if "%mule_peb_trample%"=="1" (
set didbuild=1
if exist mule_peb_trample.exe move mule_peb_trample.exe mule_peb_trample_old_%random%.exe
Expand Down
83 changes: 41 additions & 42 deletions build.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,73 @@ cd "$(dirname "$0")"

# --- Unpack Arguments --------------------------------------------------------
for arg in "$@"; do declare $arg='1'; done
if [ ! -v gcc ]; then clang=1; fi
if [ ! -v release ]; then debug=1; fi
if [ -v debug ]; then echo "[debug mode]"; fi
if [ -v release ]; then echo "[release mode]"; fi
if [ -v clang ]; then compiler="${CC:-clang}"; echo "[clang compile]"; fi
if [ -v gcc ]; then compiler="${CC:-gcc}"; echo "[gcc compile]"; fi
if [[ "$#" == "0" ]]; then raddbg='1'; fi

# --- Unpack Command Line Build Arguments -------------------------------------
auto_compile_flags=''
cc_sanitize=""
if [[ "${asan:-0}" == "1" ]]; then
echo "[asan enabled]"
cc_sanitize="-fsanitize=address"
fi

# --- Get Current Git Commit Id -----------------------------------------------
git_hash=$(git describe --always --dirty)
git_hash_full=$(git rev-parse HEAD)

# --- Compile/Link Line Definitions -------------------------------------------
clang_common="-I../src/ -I/usr/include/freetype2/ -I../local/ -D_GNU_SOURCE -g -DBUILD_GIT_HASH=\"$git_hash\" -DBUILD_GIT_HASH_FULL=\"$git_hash_full\" -Wno-unknown-warning-option -fdiagnostics-absolute-paths -Wall -Wno-missing-braces -Wno-unused-function -Wno-writable-strings -Wno-unused-value -Wno-unused-variable -Wno-unused-local-typedef -Wno-deprecated-register -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-single-bit-bitfield-constant-conversion -Wno-compare-distinct-pointer-types -Wno-initializer-overrides -Wno-incompatible-pointer-types-discards-qualifiers -Wno-for-loop-analysis -Xclang -flto-visibility-public-std -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf"
clang_debug="$compiler -g -O0 -DBUILD_DEBUG=1 ${clang_common} ${auto_compile_flags}"
clang_release="$compiler -g -O2 -DBUILD_DEBUG=0 ${clang_common} ${auto_compile_flags}"
clang_link="-lpthread -lm -lrt -ldl"
clang_out="-o"
gcc_common="-I../src/ -I../local/ -g -D_GNU_SOURCE -DBUILD_GIT_HASH=\"$git_hash\" -DBUILD_GIT_HASH_FULL=\"$git_hash_full\" -Wno-unknown-warning-option -Wall -Wno-missing-braces -Wno-unused-function -Wno-attributes -Wno-unused-value -Wno-unused-variable -Wno-unused-local-typedef -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-compare-distinct-pointer-types -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf"
gcc_debug="$compiler -g -O0 -DBUILD_DEBUG=1 ${gcc_common} ${auto_compile_flags}"
gcc_release="$compiler -g -O2 -DBUILD_DEBUG=0 ${gcc_common} ${auto_compile_flags}"
gcc_link="-lpthread -lm -lrt -ldl"
gcc_out="-o"
cc_cflags_gcc=""
cc_cflags_clang=${cc_sanitize}" -fdiagnostics-absolute-paths -Wno-for-loop-analysis -Wno-incompatible-pointer-types-discards-qualifiers -Wno-initializer-overrides -Wno-compare-distinct-pointer-types -Wno-single-bit-bitfield-constant-conversion -Wno-deprecated-declarations -Wno-writable-strings -Wno-unknown-warning-option -Wno-deprecated-register -Wno-unused-local-typedef"
cc_common="-mcx16 -I../src/ -I../local/ -D_GNU_SOURCE -g -DBUILD_GIT_HASH=\"$git_hash\" -DBUILD_GIT_HASH_FULL=\"$git_hash_full\" -Wall -Wno-missing-braces -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-value -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf"
cc_debug="-g -O0 -DBUILD_DEBUG=1 ${cc_common}"
cc_release="-g -O2 -DBUILD_DEBUG=0 ${cc_common}"
cc_link="-lpthread -lm -lrt -ldl"

# --- Per-Build Settings ------------------------------------------------------
link_dll="-fPIC"
link_os_gfx="-lX11 -lXext"
link_render="-lGL -lEGL"
link_font_provider="-lfreetype"
cc_link_dll="-fPIC"

# --- External Libraries ------------------------------------------------------
if [[ -x "$(command -v pkg-config)" ]]; then
cc_font_provider="$(pkg-config --cflags --libs freetype2)"
cc_os_gfx="$(pkg-config --cflags --libs x11 xext)"
cc_render="$(pkg-config --cflags --libs gl egl)"
else
cc_font_provider="-I/usr/include/freetype2 -lfreetype"
cc_os_gfx="-lX11 -lXext"
cc_render="-lGL -lEGL"
fi

# --- Choose Compile/Link Lines -----------------------------------------------
if [ -v gcc ]; then compile_debug="$gcc_debug"; fi
if [ -v gcc ]; then compile_release="$gcc_release"; fi
if [ -v gcc ]; then compile_link="$gcc_link"; fi
if [ -v gcc ]; then out="$gcc_out"; fi
if [ -v clang ]; then compile_debug="$clang_debug"; fi
if [ -v clang ]; then compile_release="$clang_release"; fi
if [ -v clang ]; then compile_link="$clang_link"; fi
if [ -v clang ]; then out="$clang_out"; fi
if [ -v debug ]; then compile="$compile_debug"; fi
if [ -v release ]; then compile="$compile_release"; fi
if [[ "${gcc:-0}" == "1" ]]; then compiler="${CC:-gcc} $cc_cflags_gcc"; echo "[gcc compile]";
elif [[ "${clang:-1}" == "1" ]]; then compiler="${CC:-clang} $cc_cflags_clang"; echo "[clang compile]";
fi
if [[ "${release:-0}" == "1" ]]; then echo "[release mode]"; compile="$compiler $cc_release";
elif [[ "${debug:-1}" == "1" ]]; then echo "[debug mode]"; compile="$compiler $cc_debug";
fi

# --- Prep Directories --------------------------------------------------------
mkdir -p build
mkdir -p local
mkdir -p build local

# --- Build & Run Metaprogram -------------------------------------------------
if [ -v meta ]
if [[ "${no_meta:-0}" == "0" ]]
then
echo "[doing metagen]"
echo "[building metagen]"
cd build
$compile_debug ../src/metagen/metagen_main.c $compile_link $out metagen
$compiler $cc_debug ../src/metagen/metagen_main.c $cc_link -o metagen
./metagen
cd ..
fi

# --- Build Everything (@build_targets) ---------------------------------------
cd build
if [ -v raddbg ]; then didbuild=1 && $compile ../src/raddbg/raddbg_main.c $compile_link $link_os_gfx $link_render $link_font_provider $out raddbg; fi
if [ -v radbin ]; then didbuild=1 && $compile ../src/radbin/radbin_main.c $compile_link $out radbin; fi
if [ -v radlink ]; then didbuild=1 && $compile ../src/linker/lnk.c $compile_link $out radlink; fi
if [[ "${raddbg:-0}" == "1" ]]; then didbuild=1 && $compile ../src/raddbg/raddbg_main.c $cc_link $cc_os_gfx $cc_render $cc_font_provider -o raddbg; fi
if [[ "${raddbg_non_graphical:-0}" == "1" ]]; then didbuild=1 && $compile ../src/raddbg/raddbg_main.c -DWM_STUB=1 -DWM_STUB_DEFAULT_REFRESH_RATE=60.f -DR_BACKEND=R_BACKEND_STUB $cc_link $cc_os_gfx $cc_render $cc_font_provider -o raddbg_non_graphical; fi
if [[ "${radbin:-0}" == "1" ]]; then didbuild=1 && $compile ../src/radbin/radbin_main.c $cc_link -o radbin; fi
if [[ "${radlink:-0}" == "1" ]]; then didbuild=1 && $compile ../src/linker/lnk.c $cc_link -o radlink; fi
if [[ "${torture:-0}" == "1" ]]; then didbuild=1 && $compile ../src/torture/torture_main.c $cc_link $cc_os_gfx $cc_render $cc_font_provider -o torture; fi
cd ..

# --- Warn On No Builds -------------------------------------------------------
if [ ! -v didbuild ]
if [[ "${didbuild:-0}" == "0" ]]
then
echo "[WARNING] no valid build target specified; must use build target names as arguments to this script, like \`./build.sh raddbg\` or \`./build.sh rdi_from_pdb\`."
echo "[WARNING] no valid build target specified; must use build target names as arguments to this script, like \`./build.sh raddbg\` or \`./build.sh radlink\`."
exit 1
fi
Loading