velxio/build_qemu_step4.sh

110 lines
3.0 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# Step 4: Relink qemu-system-xtensa as libqemu-xtensa.dll
set -euo pipefail
export PATH=/mingw64/bin:/usr/bin:$PATH
refactor: rename wokwi-libs/ → third-party/ The directory grew well beyond Wokwi-only contents: it now hosts lcgamboa's QEMU fork (qemu-lcgamboa), Espressif's esp32-camera, the ngspice WASM build, fritzing-parts, picowi, an alternative QEMU (qemu-esp32), the 100_Days_100_IoT_Projects examples repo, and Wokwi's own avr8js/rp2040js/wokwi-elements/wokwi-features/wokwi-boards. "wokwi-libs" was misleading — half the contents have nothing to do with Wokwi. "third-party/" is the standard convention for vendored external dependencies. Mechanical changes: Path rename: wokwi-libs/ → third-party/ update-wokwi-libs.bat → update-third-party.bat docs/WOKWI_LIBS.md → docs/THIRD_PARTY.md Submodule reconfiguration: .gitmodules — 4 path= and section names updated .git/modules/wokwi-libs/ → .git/modules/third-party/ each submodule's .git file rewired to ../../.git/modules/third-party/<name> Reference updates (~80 files): vite.config.ts aliases, Dockerfile COPY paths, GH Actions workflow steps, build_qemu_*.sh, all docs/* and test/*/autosearch/* entries that mention the path, package-lock.json file: dependencies, .gitignore patterns, sitemap.xml + index.html SEO blurbs, scripts/generate-component-*, .dockerignore, .idea/vcs.xml. Bulk replaced both `wokwi-libs/` (path) and bare `wokwi-libs` (textual mentions in docs/comments). Verified: - npx tsc -b --noEmit produces no new errors related to these paths - vite.config.ts aliases now point at ../third-party/avr8js etc. - All 4 git submodules (avr8js, rp2040js, wokwi-elements, wokwi-features) are linked under third-party/ with their worktrees re-populated and config files referencing the new path - `grep -r wokwi-libs` returns zero hits outside node_modules, .vite, frontend/dist, third-party/ (upstream submodule contents), *.pyc caches, and *.dll.pre-camera rollback binaries Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 10:58:57 +07:00
BUILD="/e/Hardware/wokwi_clon/third-party/qemu-lcgamboa/build"
OUT="/e/Hardware/wokwi_clon/backend/app/services"
cd "$BUILD"
echo "=== Extracting link command from build.ninja ==="
python3 << 'PYEOF'
import re, subprocess, sys, os
with open('build.ninja') as f:
content = f.read()
# Find build block for qemu-system-xtensa.exe
idx = content.find('build qemu-system-xtensa.exe:')
if idx < 0:
print('Target not found!'); sys.exit(1)
block = content[idx:]
end = block.find('\nbuild ', 1)
if end > 0:
block = block[:end]
# Extract LINK_ARGS and LINK_PATH
link_args = ''
link_path = ''
for line in block.split('\n'):
line = line.strip()
if line.startswith('LINK_ARGS ='):
link_args = line.split('=', 1)[1].strip()
elif line.startswith('LINK_PATH ='):
link_path = line.split('=', 1)[1].strip()
# Extract all input objects (everything after c_LINKER_RSP on line 1, excluding the | deps part)
first_line = block.split('\n')[0]
# Remove "build qemu-system-xtensa.exe: c_LINKER_RSP "
objs_raw = first_line.split('c_LINKER_RSP ', 1)[1]
# Remove pipe section (| implicit deps)
if ' | ' in objs_raw:
objs_raw = objs_raw.split(' | ')[0]
objs = objs_raw.split()
# Remove softmmu_main.c.obj (contains main())
objs = [o for o in objs if 'softmmu_main' not in o]
# Also add qemu-system-xtensa.exe.p objects (target-specific .obj files)
# Find them in the .p directory
p_dir = 'qemu-system-xtensa.exe.p'
if os.path.isdir(p_dir):
for f in os.listdir(p_dir):
if f.endswith('.obj') and 'softmmu_main' not in f:
path = f'{p_dir}/{f}'
if path not in objs:
objs.append(path)
print(f'Objects count: {len(objs)}')
print(f'LINK_ARGS: {link_args[:200]}')
print(f'LINK_PATH: {link_path}')
# Build the DLL link command
cmd = (
f'cc -m64 -mcx16 -shared -Wl,--export-all-symbols -Wl,--allow-multiple-definition '
f'-o libqemu-xtensa.dll '
f'{" ".join(objs)} '
f'{link_path} '
f'{link_args}'
)
print(f'\nLink command length: {len(cmd)}')
# Write to a response file to avoid command line length issues
with open('dll_link.rsp', 'w') as f:
f.write(
f'-shared -Wl,--export-all-symbols -Wl,--allow-multiple-definition '
f'-o libqemu-xtensa.dll '
f'{" ".join(objs)} '
f'{link_path} '
f'{link_args}'
)
print('Written to dll_link.rsp')
PYEOF
echo ""
echo "=== Linking libqemu-xtensa.dll ==="
cc -m64 -mcx16 @dll_link.rsp 2>&1
echo "=== Link exit code: $? ==="
if [ -f libqemu-xtensa.dll ]; then
echo ""
echo "=== SUCCESS: libqemu-xtensa.dll ==="
ls -lh libqemu-xtensa.dll
echo ""
echo "=== Checking picsimlab exports ==="
objdump -p libqemu-xtensa.dll 2>/dev/null | grep -iE "picsimlab|qemu_init|qemu_main" | head -20
echo ""
echo "=== Copying to backend/app/services ==="
cp libqemu-xtensa.dll "$OUT/"
echo "Copied!"
else
echo "FAILED - DLL not produced"
exit 1
fi