Files
serumalt/build_windows.sh
T
biggy e4cea300db chore: land janitor round 1 and graft integration
Round 1 findings and fixes, all previously uncommitted:
- FXProcessor per-slot DSP history repair (HEAD does not compile without it)
- SynthVoice::getModulationValue, editor control-lock guard
- ExactCompare.h naming the deliberate exact float comparisons
- KnobLookAndFeel replacing the never-installed SerumLookAndFeel
- 55 first-party compiler warnings to 0
- AGENT.md renamed to AGENTS.md across Source/
- graft repository context graph and its hooks
- JANITOR_TASKS.md and UI_UX_AUDIT.md records
2026-10-06 08:50:45 +02:00

168 lines
6.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# ---------------------------------------------------------------------------
# build_windows.sh, cross-compile SerumAlt VST3 for Windows using MinGW-w64
# ---------------------------------------------------------------------------
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
TOOLCHAIN_FILE="$SCRIPT_DIR/mingw64-toolchain.cmake"
BUILD_DIR="${BUILD_DIR:-$SCRIPT_DIR/build_windows}"
BUILD_TYPE="${BUILD_TYPE:-Release}"
OUTPUT_DIR="${OUTPUT_DIR:-$SCRIPT_DIR/SerumAlt_Windows}"
PLUGIN_NAME="SerumAlt"
export CMAKE_BUILD_PARALLEL_LEVEL="${CMAKE_BUILD_PARALLEL_LEVEL:-2}"
if [[ "$(uname -s)" != Linux ]]; then
echo "ERROR: build_windows.sh cross-compiles from Linux using MinGW-w64." >&2
exit 1
fi
# 1. Check for the host tools and MinGW-w64 cross-compiler.
for tool in cmake ninja pkg-config "${CC:-cc}" "${CXX:-c++}" \
x86_64-w64-mingw32-gcc x86_64-w64-mingw32-g++ \
x86_64-w64-mingw32-windres x86_64-w64-mingw32-ar \
x86_64-w64-mingw32-ranlib x86_64-w64-mingw32-strip \
x86_64-w64-mingw32-objdump; do
if ! command -v "$tool" >/dev/null 2>&1; then
echo "ERROR: $tool not found. See README.md prerequisites." >&2
exit 1
fi
done
echo "Found: $(command -v x86_64-w64-mingw32-g++)"
# 2. Use the checked-in CMake toolchain file without overwriting it.
if [[ ! -f "$TOOLCHAIN_FILE" ]]; then
echo "ERROR: Toolchain file not found: $TOOLCHAIN_FILE" >&2
exit 1
fi
echo "Using toolchain file: $TOOLCHAIN_FILE"
# 3. Configure with CMake + Ninja (VST3-only cross build, no test harness).
echo "Configuring Windows VST3 in $BUILD_DIR ($BUILD_TYPE)..."
cmake -S "$SCRIPT_DIR" -B "$BUILD_DIR" -G Ninja \
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN_FILE" \
-DSERUMALT_BUILD_PLUGIN=ON \
-DSERUMALT_BUILD_TESTS=OFF
# 4. Build the VST3 target.
echo "Building Windows VST3..."
cmake --build "$BUILD_DIR" --config "$BUILD_TYPE" --target SerumAlt_VST3
# 5. Verify the linked module can load on a stock Windows host.
# The MinGW C++/threading runtimes are not part of this bundle and do not exist
# on a stock Windows machine, so a module that still imports one of them fails
# to load and the host then omits the plugin from its scan list. The static
# -runtime link options in cmake/Plugin.cmake are meant to prevent that; check
# it here so a stale build tree or a dropped flag fails the build loudly
# instead of shipping a bundle that appears nowhere in the host.
VST3_BUNDLE="$BUILD_DIR/${PLUGIN_NAME}_artefacts/$BUILD_TYPE/VST3/$PLUGIN_NAME.vst3"
VST3_BINARY="$VST3_BUNDLE/Contents/x86_64-win/$PLUGIN_NAME.vst3"
if [[ ! -f "$VST3_BINARY" ]]; then
echo "ERROR: cross-build produced no module at $VST3_BINARY" >&2
exit 1
fi
if ! x86_64-w64-mingw32-objdump -f "$VST3_BINARY" | grep -q 'i386:x86-64'; then
echo "ERROR: $VST3_BINARY is not an x86-64 module" >&2
exit 1
fi
VST3_DUMP="$(x86_64-w64-mingw32-objdump -p "$VST3_BINARY")"
for runtime in libgcc_s_seh-1.dll libstdc++-6.dll libwinpthread-1.dll; do
if grep -qF "DLL Name: $runtime" <<<"$VST3_DUMP"; then
echo "ERROR: $VST3_BINARY still imports $runtime." >&2
echo " A stock Windows host cannot resolve it and will not list the" >&2
echo " plugin. Restore the static-runtime link options in" >&2
echo " cmake/Plugin.cmake and rebuild with a fresh BUILD_DIR." >&2
exit 1
fi
done
# JUCE implements only these three module entry points on Windows; bundleEntry and
# bundleExit are macOS-only, and the VST3 SDK's Windows loader requires only
# GetPluginFactory, treating InitDll/ExitDll as optional.
for entry in GetPluginFactory InitDll ExitDll; do
if ! grep -qE "[[:space:]]${entry}\$" <<<"$VST3_DUMP"; then
echo "ERROR: $VST3_BINARY does not export $entry" >&2
exit 1
fi
done
# 6. Inject the VST3 moduleinfo.json.
# The automatic manifest step is disabled when cross-compiling (see
# cmake/Plugin.cmake), because JUCE's manifest helper is a host tool that would
# otherwise be built as a Windows executable. The moduleinfo content is
# deterministic for this Windows plugin. It depends on the plugin's
# name, manufacturer/plugin codes, and version, so we write the same metadata
# that the native Windows helper generates. Keep it in sync with the metadata
# in CMakeLists.txt and cmake/Plugin.cmake, including the vendored VST3 SDK version.
echo "Writing Windows VST3 manifest..."
mkdir -p "$VST3_BUNDLE/Contents/Resources"
cat > "$VST3_BUNDLE/Contents/Resources/moduleinfo.json" <<'EOF'
{
"Name": "SerumAlt",
"Version": "1.0.0",
"Factory Info": {
"Vendor": "SerumAlt Audio",
"URL": "",
"E-Mail": "",
"Flags": {
"Unicode": true,
"Classes Discardable": false,
"Component Non Discardable": false
}
},
"Classes": [
{
"CID": "ABCDEF019182FAEB53616C7453657261",
"Category": "Audio Module Class",
"Name": "SerumAlt",
"Vendor": "SerumAlt Audio",
"Version": "1.0.0",
"SDKVersion": "VST 3.7.8",
"Sub Categories": [
"Instrument",
"Synth"
],
"Class Flags": 2,
"Cardinality": 2147483647,
"Snapshots": []
},
{
"CID": "ABCDEF011234ABCD53616C7453657261",
"Category": "Component Controller Class",
"Name": "SerumAlt",
"Vendor": "SerumAlt Audio",
"Version": "1.0.0",
"SDKVersion": "VST 3.7.8",
"Sub Categories": [
"Instrument",
"Synth"
],
"Class Flags": 2,
"Cardinality": 2147483647,
"Snapshots": []
},
{
"CID": "ABCDEF01C0DEF00D53616C7453657261",
"Category": "Plugin Compatibility Class",
"Name": "SerumAlt",
"Vendor": "SerumAlt Audio",
"Version": "1.0.0",
"SDKVersion": "VST 3.7.8",
"Class Flags": 0,
"Cardinality": 2147483647,
"Snapshots": []
}
]
}
EOF
# 7. Copy the resulting .vst3 bundle to SerumAlt_Windows/ without deleting files.
echo "Staging Windows VST3 in $OUTPUT_DIR..."
cmake -E copy_directory "$VST3_BUNDLE" "$OUTPUT_DIR/$PLUGIN_NAME.vst3"
echo
echo "Done. Windows VST3 plugin at: $OUTPUT_DIR/$PLUGIN_NAME.vst3"