build-bridge32.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/env bash
  2. # Cross build of LYNX-bridge32.exe (round 176a): the 32-bit plugin bridge, Windows x86, with Zig (clang + MinGW-w64).
  3. # LYNX.exe (64-bit) runs every 32-bit VST2 / VST3 plugin in one of these processes (src/bridge/Bridge32Main.cpp).
  4. #
  5. # scripts/build-bridge32.sh -> $OUT/LYNX-bridge32.exe (OUT defaults to build-win; objects in $OUT/x86)
  6. #
  7. # Called by scripts/build-windows-zig.sh after LYNX.exe (it reuses that script's patched JUCE copies, the version header
  8. # and the shared object cache when it runs from there). Only the JUCE modules a plugin host needs are compiled.
  9. set -euo pipefail
  10. cd "$(dirname "$0")/.."
  11. ZIG="${ZIG:-$HOME/opt/zig-x86_64-linux-0.14.1/zig}"
  12. JUCE_DIR="${JUCE_DIR:-$HOME/opt/juce-8.0.4}"
  13. OUT="${OUT:-build-win}"
  14. JOBS="${JOBS:-$(nproc)}"
  15. TARGET=x86-windows-gnu
  16. B="$OUT/x86"
  17. mkdir -p "$B/juce" "$B/app" "$OUT/shim"
  18. echo '#include <dbghelp.h>' > "$OUT/shim/Dbghelp.h"
  19. VERSION="$(sed -n 's/^project(LYNX VERSION \([0-9]*\.[0-9]*\.[0-9]*\(\.[0-9]*\)\{0,1\}\).*/\1/p' CMakeLists.txt)"
  20. MODULES=(juce_core juce_data_structures juce_events juce_graphics juce_gui_basics juce_gui_extra juce_audio_basics juce_audio_processors)
  21. {
  22. echo '#pragma once'
  23. echo '#define JUCE_GLOBAL_MODULE_SETTINGS_INCLUDED 1'
  24. echo '#define JUCE_STANDALONE_APPLICATION 1'
  25. echo '#define JUCE_USE_CURL 0'
  26. echo '#define JUCE_WEB_BROWSER 0'
  27. echo '#define JUCE_PLUGINHOST_VST3 1'
  28. echo '#define JUCE_APPLICATION_NAME_STRING "LYNX-bridge32"'
  29. echo "#define JUCE_APPLICATION_VERSION_STRING \"$VERSION\""
  30. for m in "${MODULES[@]}"; do echo "#define JUCE_MODULE_AVAILABLE_$m 1"; done
  31. } > "$B/JuceConfig.h.new"
  32. cmp -s "$B/JuceConfig.h.new" "$B/JuceConfig.h" 2>/dev/null && rm "$B/JuceConfig.h.new" || mv "$B/JuceConfig.h.new" "$B/JuceConfig.h"
  33. # 32-bit x86 only: JUCE hands lambdas to Win32 calls that take __stdcall callbacks (MSVC converts a lambda to any calling
  34. # convention, clang only to the default one): those modules are compiled from copies with a static CALLBACK function
  35. # instead (scripts/bridge32_patch_juce.py). Then the patched JUCE copies scripts/build-windows-zig.sh made (VST3 note
  36. # ids, the dispatch hook...), else the checkout.
  37. python3 -I scripts/bridge32_patch_juce.py "$JUCE_DIR/modules" "$OUT/juce-patched/modules" "$B/juce-x86/modules"
  38. src_of() {
  39. local m="$1"
  40. if [[ -f "$B/juce-x86/modules/$m/$m.cpp" ]]; then echo "$B/juce-x86/modules/$m"
  41. elif [[ -f "$OUT/juce-patched/modules/$m/$m.cpp" ]]; then echo "$OUT/juce-patched/modules/$m"
  42. else echo "$JUCE_DIR/modules/$m"; fi
  43. }
  44. COMMON=(-target "$TARGET" -std=c++20 -O2 -DNDEBUG=1 -fno-sanitize=undefined -DLYNX_BRIDGE32=1
  45. -include "$B/JuceConfig.h" -include cmake/mingw/mingw_compat.h
  46. -I"$OUT/shim" -I"$JUCE_DIR/modules" -I"$JUCE_DIR/modules/juce_audio_processors/format_types/VST3_SDK" -Ithird_party/sse2neon -Isrc)
  47. # the object cache of scripts/build-windows-zig.sh when it calls this script (exported there); alone: plain compiles
  48. if ! declare -F cached > /dev/null; then
  49. cached() { while [[ "$1" != -- ]]; do shift; done; shift; "$@"; }
  50. cached_pp() { shift 2; "$@"; }
  51. export -f cached cached_pp
  52. fi
  53. JUCE_KEY="$JUCE_DIR $(cat "$B/JuceConfig.h" cmake/mingw/mingw_compat.h "$JUCE_DIR/modules/juce_core/system/juce_StandardHeader.h" | sha256sum | cut -c1-64)"
  54. export ZIG TARGET B JUCE_KEY COMMON_STR="${COMMON[*]}"
  55. export -f src_of
  56. export OUT JUCE_DIR
  57. echo "Bridge32: JUCE modules (x86, cached)..."
  58. for m in "${MODULES[@]}" juce_core_CompilationTime juce_graphics_Harfbuzz juce_graphics_Sheenbidi; do echo "$m"; done | xargs -P "$JOBS" -I{} bash -c '
  59. m={}; obj="$B/juce/$m.o"
  60. [[ -f "$obj" && ! "$B/JuceConfig.h" -nt "$obj" ]] && exit 0
  61. echo " JUCE x86 $m"
  62. case "$m" in
  63. juce_core_CompilationTime) src="$JUCE_DIR/modules/juce_core/$m.cpp"; key="$JUCE_KEY" ;;
  64. juce_graphics_Harfbuzz) src="$JUCE_DIR/modules/juce_graphics/$m.cpp"; key="$JUCE_KEY" ;;
  65. juce_graphics_Sheenbidi)
  66. cached "$obj" "$JUCE_DIR x86" -- "$ZIG" cc -target "$TARGET" -O2 -w -DJUCE_GLOBAL_MODULE_SETTINGS_INCLUDED=1 -I"$JUCE_DIR/modules" -c "$JUCE_DIR/modules/juce_graphics/juce_graphics_Sheenbidi.c" -o "$obj"
  67. exit $? ;;
  68. *) d="$(src_of "$m")"; src="$d/$m.cpp"; key="$JUCE_KEY $(cd "$d" && find . -type f | LC_ALL=C sort | xargs -d "\n" sha256sum | sha256sum | cut -c1-64)" ;;
  69. esac
  70. cached "$obj" "$key" -- $ZIG c++ $COMMON_STR -w -c "$src" -o "$obj"'
  71. # (src/flp/Flp.cpp: FlWrapper.cpp reads Fruity Wrapper presets with flp::parseProject since d6dcbc568)
  72. SOURCES=(src/bridge/Bridge32Main.cpp src/engine/SandboxWorker.cpp src/engine/Vst2Format.cpp src/core/FlWrapper.cpp src/flp/Flp.cpp src/platform/NativeEmbed.cpp src/platform/MingwFixes.cpp)
  73. echo "Bridge32: sources..."
  74. printf '%s\n' "${SOURCES[@]}" | xargs -P "$JOBS" -I{} bash -c '
  75. src={}; obj="$B/app/$(echo "$src" | tr / _).o"
  76. cached_pp "$obj" -- $ZIG c++ $COMMON_STR -Wall -Wextra -c "$src" -o "$obj"'
  77. OBJECTS=()
  78. for src in "${SOURCES[@]}"; do OBJECTS+=("$B/app/$(echo "$src" | tr / _).o"); done
  79. echo "Bridge32: resources and link..."
  80. OUT_ABS="$(cd "$OUT" && pwd)"
  81. if [[ ! -f "$OUT/lynx_version.h" ]]; then
  82. IFS=. read -r VMAJ VMIN VPAT VREV <<< "$VERSION"
  83. printf '#pragma once\n#define LYNX_VERSION_MAJOR %s\n#define LYNX_VERSION_MINOR %s\n#define LYNX_VERSION_PATCH %s\n#define LYNX_VERSION_REVISION %s\n#define LYNX_VERSION_STR "%s"\n' "$VMAJ" "$VMIN" "$VPAT" "${VREV:-0}" "$VERSION" > "$OUT/lynx_version.h"
  84. fi
  85. ( cd resources && "$ZIG" rc /i "$OUT_ABS" /fo "$OUT_ABS/x86/LYNX-bridge32.res" LYNX-bridge32.rc )
  86. "$ZIG" c++ -target "$TARGET" -O2 -o "$OUT/LYNX-bridge32.exe" "$B"/juce/*.o "${OBJECTS[@]}" "$B/LYNX-bridge32.res" \
  87. -Wl,--subsystem,windows \
  88. -lole32 -loleaut32 -luuid -lwinmm -lws2_32 -lshlwapi -lversion -lwininet -limm32 -lcomdlg32 \
  89. -lgdi32 -luser32 -lcomctl32 -lshell32 -ladvapi32 -lrpcrt4 -ldbghelp -lsetupapi -luxtheme -ldwmapi \
  90. -ld2d1 -ldcomp -ldwrite -ldxgi -ld3d11 -ldxguid -lwsock32 -lopengl32 -lpropsys -lmfplat -lmfuuid -lksuser
  91. # large-address aware: 4 GB for big sample-based 32-bit instruments (zig's linker has no flag for it)
  92. python3 -I scripts/pe_set_laa.py "$OUT/LYNX-bridge32.exe"
  93. ls -la "$OUT/LYNX-bridge32.exe"