Skip to content

Commit c423140

Browse files
committed
ci: generate message in pull requests (isledecomp#497)
1 parent e0ac6bc commit c423140

15 files changed

Lines changed: 403 additions & 64 deletions

File tree

.editorconfig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ tab_width = 4
1212
insert_final_newline = true
1313
trim_trailing_whitespace = true
1414

15-
[{CMakeLists.txt,*.cmake}]
15+
[{CMakeLists.txt,*.cmake,*.yml}]
16+
indent_style = space
1617
indent_size = 2
18+
insert_final_newline = true
19+
trim_trailing_whitespace = true
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: 'Setup ninja'
2+
description: 'Download ninja and add it to the PATH environment variable'
3+
inputs:
4+
version:
5+
description: 'Ninja version'
6+
default: '1.13.2'
7+
runs:
8+
using: 'composite'
9+
steps:
10+
- name: 'Calculate variables'
11+
id: calc
12+
shell: sh
13+
run: |
14+
case "${{ runner.os }}-${{ runner.arch }}" in
15+
"Linux-X86" | "Linux-X64")
16+
archive="ninja-linux.zip"
17+
;;
18+
"Linux-ARM64")
19+
archive="ninja-linux-aarch64.zip"
20+
;;
21+
"macOS-X86" | "macOS-X64" | "macOS-ARM64")
22+
archive="ninja-mac.zip"
23+
;;
24+
"Windows-X86" | "Windows-X64")
25+
archive="ninja-win.zip"
26+
;;
27+
"Windows-ARM64")
28+
archive="ninja-winarm64.zip"
29+
;;
30+
*)
31+
echo "Unsupported ${{ runner.os }}-${{ runner.arch }}"
32+
exit 1;
33+
;;
34+
esac
35+
echo "archive=${archive}" >> ${GITHUB_OUTPUT}
36+
echo "cache-key=${archive}-${{ inputs.version }}-${{ runner.os }}-${{ runner.arch }}" >> ${GITHUB_OUTPUT}
37+
- name: 'Restore cached ${{ steps.calc.outputs.archive }}'
38+
id: cache-restore
39+
uses: actions/cache/restore@v5
40+
with:
41+
path: '${{ runner.temp }}/${{ steps.calc.outputs.archive }}'
42+
key: ${{ steps.calc.outputs.cache-key }}
43+
- name: 'Download ninja ${{ inputs.version }} for ${{ runner.os }} (${{ runner.arch }})'
44+
if: ${{ !steps.cache-restore.outputs.cache-hit || steps.cache-restore.outputs.cache-hit == 'false' }}
45+
shell: pwsh
46+
run: |
47+
Invoke-WebRequest "https://github.com/ninja-build/ninja/releases/download/v${{ inputs.version }}/${{ steps.calc.outputs.archive }}" -OutFile "${{ runner.temp }}/${{ steps.calc.outputs.archive }}"
48+
- name: 'Cache ${{ steps.calc.outputs.archive }}'
49+
if: ${{ !steps.cache-restore.outputs.cache-hit || steps.cache-restore.outputs.cache-hit == 'false' }}
50+
uses: actions/cache/save@v5
51+
with:
52+
path: '${{ runner.temp }}/${{ steps.calc.outputs.archive }}'
53+
key: ${{ steps.calc.outputs.cache-key }}
54+
- name: 'Extract ninja'
55+
shell: pwsh
56+
run: |
57+
7z "-o${{ runner.temp }}/ninja-${{ inputs.version }}-${{ runner.arch }}" x "${{ runner.temp }}/${{ steps.calc.outputs.archive }}"
58+
- name: 'Set output variables'
59+
id: final
60+
shell: pwsh
61+
run: |
62+
echo "${{ runner.temp }}/ninja-${{ inputs.version }}-${{ runner.arch }}" >> $env:GITHUB_PATH

.github/workflows/build.yml

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ jobs:
1616
- name: Setup cmake
1717
uses: jwlawson/actions-setup-cmake@v2
1818

19-
- name: Setup ninja
20-
uses: ashutoshvarma/setup-ninja@master
19+
- name: Setup Ninja
20+
uses: ./.github/actions/setup-ninja
2121

2222
- name: Setup vcvars
2323
uses: ilammy/msvc-dev-cmd@v1
@@ -76,6 +76,10 @@ jobs:
7676
name: Verify decomp
7777
needs: [build, fetch-deps]
7878
runs-on: windows-latest
79+
permissions:
80+
actions: read
81+
issues: write
82+
pull-requests: write
7983
steps:
8084
- uses: actions/checkout@v6
8185

@@ -121,8 +125,11 @@ jobs:
121125
curl -fLSs -o LEGORACERSPROGRESS-old.json $RELEASE_URL/LEGORACERSPROGRESS.json || echo "" >LEGORACERSPROGRESS-old.json
122126
curl -fLSs -o GOLDPPROGRESS-old.json $RELEASE_URL/GOLDPPROGRESS.json || echo "" >GOLDPPROGRESS-old.json
123127
124-
reccmp-reccmp --target LEGORACERS --nolib --diff LEGORACERSPROGRESS-old.json || echo "Current master not found"
125-
reccmp-reccmp --target GOLDP --nolib --diff GOLDPPROGRESS-old.json || echo "Current master not found"
128+
(reccmp-reccmp --target LEGORACERS --nolib --diff LEGORACERSPROGRESS-old.json || echo "Current master not found")>"LEGORACERS-diff.txt"
129+
(reccmp-reccmp --target GOLDP --nolib --diff GOLDPPROGRESS-old.json || echo "Current master not found")>"GOLDP-diff.txt"
130+
131+
cat LEGORACERS-diff.txt
132+
cat GOLDP-diff.txt
126133
127134
- name: Check Vtables
128135
if: ${{ steps.detection.conclusion == 'success' && always() }}
@@ -145,6 +152,33 @@ jobs:
145152
python tools/check_folded.py --target LEGORACERS
146153
python tools/check_folded.py --target GOLDP
147154
155+
- name: 'Create comment on PR'
156+
if: ${{ github.event_name == 'pull_request' }}
157+
shell: sh
158+
env:
159+
GH_TOKEN: ${{ github.token }}
160+
run: |
161+
section() {
162+
echo "## $1"
163+
echo '```'
164+
if [ -f "$2" ]; then
165+
python -c "print(open('$2').read().strip())";
166+
else
167+
echo '(no diff available)';
168+
fi
169+
echo '```'
170+
}
171+
172+
{
173+
echo '# reccmp report'
174+
section 'LEGORACERS (LEGORacers.exe)' LEGORACERS-diff.txt
175+
section 'GOLDP (GolDP.dll)' GOLDP-diff.txt
176+
} >reccmp-pr-message.txt
177+
178+
echo "${{ github.event.number }}" >pr-number.txt
179+
180+
cat reccmp-pr-message.txt
181+
148182
- name: Upload Artifact
149183
uses: actions/upload-artifact@main
150184
with:
@@ -153,6 +187,15 @@ jobs:
153187
LEGORACERSPROGRESS*
154188
GOLDPPROGRESS*
155189
190+
- name: Upload PR comment payload
191+
if: ${{ github.event_name == 'pull_request' && always() }}
192+
uses: actions/upload-artifact@main
193+
with:
194+
name: reccmp-pr-comment
195+
path: |
196+
reccmp-pr-message.txt
197+
pr-number.txt
198+
156199
upload:
157200
name: Upload artifacts
158201
needs: [verify]

.github/workflows/pr-comment.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Post reccmp output as PR comment
2+
3+
# Runs after the Build workflow finishes. Triggered via workflow_run so it
4+
# executes in the base-repo context with a writable token, which lets it comment
5+
# on pull requests opened from forks (those builds only get a read-only token).
6+
on:
7+
workflow_run:
8+
workflows: [Build]
9+
types: [completed]
10+
11+
jobs:
12+
comment:
13+
name: Comment reccmp report
14+
runs-on: ubuntu-latest
15+
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
16+
permissions:
17+
actions: read
18+
issues: write
19+
pull-requests: write
20+
steps:
21+
- name: Download PR comment payload
22+
id: download
23+
continue-on-error: true
24+
uses: actions/download-artifact@v8
25+
with:
26+
name: reccmp-pr-comment
27+
run-id: ${{ github.event.workflow_run.id }}
28+
github-token: ${{ github.token }}
29+
30+
- name: Post comment
31+
if: ${{ steps.download.outcome == 'success' }}
32+
env:
33+
GH_TOKEN: ${{ github.token }}
34+
run: |
35+
gh pr comment "$(cat pr-number.txt)" \
36+
--repo "${{ github.repository }}" \
37+
--create-if-none \
38+
--edit-last \
39+
--body-file reccmp-pr-message.txt

3rdparty/libcmt/CMakeLists.txt

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
add_library(patched-libcmt INTERFACE)
2+
3+
set(MSVC_CRT_SRC_PATH "" CACHE PATH "Path of MSVC6 CRT/SRC")
4+
if(MSVC_CRT_SRC_PATH)
5+
enable_language(C)
6+
set(CMAKE_CXX_FLAGS "/W3 /GX /DWIN32 /D_WINDOWS")
7+
set(CMAKE_CXX_FLAGS_DEBUG "/Gm /Od /D_DEBUG")
8+
set(CMAKE_CXX_FLAGS_RELEASE "/O1 /DNDEBUG")
9+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O1 /DNDEBUG")
10+
set(CMAKE_CXX_FLAGS_MINSIZEREL "/Os /DNDEBUG")
11+
12+
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}")
13+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
14+
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
15+
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
16+
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
17+
18+
# Compile our SP3 heap overlay as an OBJECT library so we can patch the
19+
# resulting .obj files into a copy of RTM's LIBCMT.LIB.
20+
add_library(goldp_libcmt_objs OBJECT
21+
"${MSVC_CRT_SRC_PATH}/free.c"
22+
"${MSVC_CRT_SRC_PATH}/calloc.c"
23+
"${MSVC_CRT_SRC_PATH}/malloc.c"
24+
"${MSVC_CRT_SRC_PATH}/realloc.c"
25+
"${MSVC_CRT_SRC_PATH}/expand.c"
26+
"${MSVC_CRT_SRC_PATH}/msize.c"
27+
"${MSVC_CRT_SRC_PATH}/sbheap.c"
28+
"${MSVC_CRT_SRC_PATH}/heapinit.c"
29+
"${MSVC_CRT_SRC_PATH}/heapchk.c"
30+
"${MSVC_CRT_SRC_PATH}/heapmin.c"
31+
"${MSVC_CRT_SRC_PATH}/new.cpp"
32+
"${MSVC_CRT_SRC_PATH}/delete.cpp"
33+
)
34+
target_include_directories(goldp_libcmt_objs PRIVATE "${MSVC_CRT_SRC_PATH}")
35+
target_compile_definitions(goldp_libcmt_objs PRIVATE WIN32_LEAN_AND_MEAN NOSERVICE)
36+
target_compile_definitions(goldp_libcmt_objs PRIVATE _MBCS _MB_MAP_DIRECT)
37+
target_compile_definitions(goldp_libcmt_objs PRIVATE _CRTBLD)
38+
target_compile_definitions(goldp_libcmt_objs PRIVATE WINHEAP)
39+
target_compile_options(goldp_libcmt_objs PRIVATE -Zp8 -GFy -GB -Gi- -Zl)
40+
set_property(TARGET goldp_libcmt_objs PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
41+
# Suppress source-level debug info so the PDB doesn't emit S_GPROC32 entries with C-source
42+
# names for CRT internals — this would shadow PUBLIC symbol names and break reccmp's symbol
43+
# resolution for call targets that LR's PDB only knows by linker-decorated name.
44+
set_property(TARGET goldp_libcmt_objs PROPERTY MSVC_DEBUG_INFORMATION_FORMAT "")
45+
46+
message(STATUS "LIB: $ENV{LIB}")
47+
# Locate the LIBCMT.LIB picked up from the LIB env var
48+
set(libs $ENV{LIB})
49+
if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
50+
string(REPLACE ":" ";" libs ${libs})
51+
endif()
52+
find_file(LIBCMT_ORIGINAL_LIB NAMES LIBCMT.LIB libcmt.lib HINTS ${libs} REQUIRED)
53+
message(STATUS "Original LIBCMT.LIB: ${LIBCMT_ORIGINAL_LIB}")
54+
55+
# Build a patched LIBCMT.LIB: copy lib, strip heap .obj members, add ours.
56+
set(PATCHED_LIBCMT "${CMAKE_CURRENT_BINARY_DIR}/RACERS_LIBCMT.LIB")
57+
set(PRUNED_LIBCMT "${CMAKE_CURRENT_BINARY_DIR}/PRUNED_LIBCMT.LIB")
58+
add_custom_command(
59+
OUTPUT "${PATCHED_LIBCMT}"
60+
BYPRODUCTS "${PRUNED_LIBCMT}"
61+
DEPENDS goldp_libcmt_objs "${LIBCMT_ORIGINAL_LIB}"
62+
COMMAND "${CMAKE_COMMAND}" -E rm -f "${PATCHED_LIBCMT}" "${PRUNED_LIBCMT}"
63+
COMMAND "${CMAKE_COMMAND}" -E copy "${LIBCMT_ORIGINAL_LIB}" "${PRUNED_LIBCMT}"
64+
COMMAND "${CMAKE_AR}" /nologo
65+
/REMOVE:build\\intel\\mt_obj\\free.obj
66+
/REMOVE:build\\intel\\mt_obj\\calloc.obj
67+
/REMOVE:build\\intel\\mt_obj\\malloc.obj
68+
/REMOVE:build\\intel\\mt_obj\\realloc.obj
69+
/REMOVE:build\\intel\\mt_obj\\expand.obj
70+
/REMOVE:build\\intel\\mt_obj\\msize.obj
71+
/REMOVE:build\\intel\\mt_obj\\sbheap.obj
72+
/REMOVE:build\\intel\\mt_obj\\heapinit.obj
73+
/REMOVE:build\\intel\\mt_obj\\heapchk.obj
74+
/REMOVE:build\\intel\\mt_obj\\heapmin.obj
75+
/REMOVE:build\\intel\\mt_obj\\new.obj
76+
/REMOVE:build\\intel\\mt_obj\\delete.obj
77+
"${PATCHPRUNED_LIBCMTED_LIBCMT}"
78+
COMMAND "${CMAKE_AR}" /nologo /NODEFAULTLIB:LIBCMT.LIB "/OUT:${PATCHED_LIBCMT}" "${PRUNED_LIBCMT}" $<TARGET_OBJECTS:goldp_libcmt_objs>
79+
COMMAND_EXPAND_LISTS
80+
VERBATIM
81+
)
82+
add_custom_target(goldp_libcmt_target DEPENDS "${PATCHED_LIBCMT}")
83+
add_dependencies(goldp goldp_libcmt_target)
84+
85+
# Tell the linker to use our patched LIBCMT instead of RTM's
86+
target_link_options(patched-libcmt INTERFACE "/NODEFAULTLIB:LIBCMT.LIB")
87+
target_link_libraries(patched-libcmt INTERFACE "${PATCHED_LIBCMT}")
88+
endif()

CMakeLists.txt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,17 @@ if (MSVC_FOR_DECOMP)
539539
#Embed debug information(/ Z7) for Debug and RelWithDebInfo configuration type
540540
set_property(TARGET goldp legoracers common_goldp common_legoracers PROPERTY MSVC_DEBUG_INFORMATION_FORMAT "$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>")
541541

542-
set(CMAKE_CXX_FLAGS "/W3 /GX /D \"WIN32\" /D \"_WINDOWS\"")
543-
set(CMAKE_CXX_FLAGS_DEBUG "/Gm /Od /D \"_DEBUG\"")
544-
set(CMAKE_CXX_FLAGS_RELEASE "/O2 /D \"NDEBUG\"")
545-
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /D \"NDEBUG\"")
546-
set(CMAKE_CXX_FLAGS_MINSIZEREL "/Os /D \"NDEBUG\"")
542+
set(CMAKE_CXX_FLAGS "/W3 /GX /DWIN32 /D_WINDOWS")
543+
set(CMAKE_CXX_FLAGS_DEBUG "/Gm /Od /D_DEBUG")
544+
set(CMAKE_CXX_FLAGS_RELEASE "/O2 /DNDEBUG")
545+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /DNDEBUG")
546+
set(CMAKE_CXX_FLAGS_MINSIZEREL "/Os /DNDEBUG")
547+
548+
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}")
549+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
550+
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
551+
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
552+
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
547553

548554
set(CMAKE_EXE_LINKER_FLAGS "/machine:I386")
549555
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/incremental:yes /debug")
@@ -632,8 +638,13 @@ foreach(target ${RECCMP_TARGETS})
632638
add_custom_command(OUTPUT "${progress_local}" COMMAND ${download_command})
633639
add_custom_target(show-progress-${reccmp_id}
634640
COMMENT "Compare progress of ${reccmp_id} with current git master"
635-
COMMAND reccmp-reccmp --target ${reccmp_id} --nolib --diff "${progress_local}"
641+
COMMAND reccmp-reccmp --target ${reccmp_id} --diff "${progress_local}"
636642
DEPENDS "${progress_local}"
637643
)
638644
add_dependencies(show-progress show-progress-${reccmp_id})
639645
endforeach()
646+
647+
if(MSVC_FOR_DECOMP)
648+
add_subdirectory(3rdparty/libcmt)
649+
target_link_libraries(goldp PRIVATE patched-libcmt)
650+
endif()

0 commit comments

Comments
 (0)