Skip to content

Commit 6fda245

Browse files
committed
Export the three names the new declarations call
`port/*.def` is an explicit list, and the import library generated from it contains exactly those names. I added three declarations to `src/win32.h` for openkal 0.8 and did not add the names, so the import library this package generates for its consumers was missing them. ⚠️ AND THIS PACKAGE'S OWN CI STAYED GREEN, because this package does not link. The failure appeared one repository away, in openkal-llvm-runtime's cross-build: ld.lld: error: undefined symbol: __declspec(dllimport) CreatePipe ld.lld: error: undefined symbol: __declspec(dllimport) GetConsoleScreenBufferInfo ld.lld: error: undefined symbol: __declspec(dllimport) SetConsoleMode which reads as a defect in the consumer and is nothing of the kind. ⭐ IT WAS FOUND BY COMPARING IMPORT LIBRARIES, NOT BY READING THE ERROR. Every copy of a vendor `libkernel32.a` on the machine had all three; the one generated here had `GetConsoleMode` and not `SetConsoleMode`, which is not a shape a vendor's library takes and pointed straight at the generated list. The check added here is the one that would have caught it: every name `src/win32.h` declares must be exported by some `.def`. It belongs in this repository, where the two lists are, rather than in the consumer that trips over the difference. Measured both ways: removing `CreatePipe` from the list makes it red and names the symbol; the lists as committed are 42 declared, 49 exported, none missing. A denominator is asserted on both sides, since two empty lists have an empty difference too.
1 parent 2db18a6 commit 6fda245

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,48 @@ jobs:
163163
echo "under review: $("$built" --version) (from $MCPP_SOURCE_REF)"
164164
fi
165165
166+
# EVERY NAME THE HEADER DECLARES IS EXPORTED BY ONE OF THE .def FILES.
167+
#
168+
# `port/*.def` is an explicit list, and an import library generated from it
169+
# contains exactly those names. So a declaration added to `src/win32.h`
170+
# without a matching line in a `.def` compiles, and fails at the link of a
171+
# CONSUMER --- not of this package, which does not link.
172+
#
173+
# ⚠️ MEASURED. Three declarations were added for openkal 0.8 and the names
174+
# were not, and this package's own CI stayed green: the failure appeared in
175+
# openkal-llvm-runtime's cross-build, one repository away, as
176+
#
177+
# ld.lld: error: undefined symbol: __declspec(dllimport) CreatePipe
178+
#
179+
# which reads as a defect in the consumer. The check belongs here, where
180+
# the two lists are.
181+
- name: Every declared name is exported by a .def
182+
run: |
183+
python3 - <<'PY'
184+
import glob, os, re, sys
185+
declared = set(re.findall(r'OKW_IMPORT\s+\w+\s+OKW_API\s+(\w+)\s*\(',
186+
open("src/win32.h").read()))
187+
exported = set()
188+
for f in glob.glob("port/*.def"):
189+
body = open(f).read().split("EXPORTS", 1)
190+
if len(body) < 2: continue
191+
exported |= {l.strip() for l in body[1].split("\n")
192+
if l.strip() and not l.lstrip().startswith(';')}
193+
# A denominator on both sides: with either list empty the difference is
194+
# vacuously empty too.
195+
if not declared or not exported:
196+
print(f"::error::declared={len(declared)} exported={len(exported)}; nothing was compared")
197+
sys.exit(1)
198+
missing = sorted(declared - exported)
199+
print(f" {len(declared)} declared, {len(exported)} exported across "
200+
f"{len(glob.glob('port/*.def'))} .def files")
201+
if missing:
202+
print("::error::declared in src/win32.h and exported by no .def:")
203+
for m in missing: print(f" {m}")
204+
sys.exit(1)
205+
print(" ok every declared name is exported")
206+
PY
207+
166208
- name: Select the toolchain
167209
run: |
168210
spec='${{ matrix.toolchain }}'

port/kernel32.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ LIBRARY KERNEL32.dll
66
EXPORTS
77
CloseHandle
88
CreateFileW
9+
CreatePipe
910
CreateProcessW
1011
CreateThread
1112
FlushFileBuffers
1213
FreeEnvironmentStringsW
1314
GetCommandLineW
1415
GetConsoleMode
16+
GetConsoleScreenBufferInfo
1517
GetCurrentDirectoryW
1618
GetCurrentProcess
1719
GetCurrentThreadId
@@ -31,6 +33,7 @@ MultiByteToWideChar
3133
QueryPerformanceCounter
3234
QueryPerformanceFrequency
3335
ReadFile
36+
SetConsoleMode
3437
SetFilePointerEx
3538
SetHandleInformation
3639
Sleep

0 commit comments

Comments
 (0)