build.sh: build SDL3 with CMake (#2060)

* build.sh: support building SDL3 with cmake

* ci: install cmake

* ci: make msvc use bash to build again

* ci: use get-command to get link.exe

* build.sh: revert back to CMAKE_INSTALL_PREFIX

* ci: hardcode CMAKE_INSTALL_LIBDIR

* ci: set cc_ld to not step on cmake

* build.sh: less messing with cwd

* build.sh: fix prefix once and for all

* ci: skip installing cmake on macos to avoid warnings

* build.sh: pass MACOSX_DEPLOYMENT_TARGET to cmake

* build.sh: remove extra .. in configure command

* build.sh: remove unused variable

* build.sh: allow SIMD runtime detection

* build.sh: propagate LTO to SDL3
This commit is contained in:
Takase
2025-05-18 23:16:07 +08:00
committed by takase1121
parent 5ff596aff2
commit 6d686e78db
3 changed files with 63 additions and 37 deletions
+10 -25
View File
@@ -111,7 +111,7 @@ jobs:
# installing md5sha1sum will eliminate a warning with arm64 and libusb
- name: Install Dependencies
run: |
brew install bash md5sha1sum sdl3
brew install bash md5sha1sum
pip install meson ninja dmgbuild
- name: Build
@@ -206,10 +206,10 @@ jobs:
pacboy: >-
gcc:p
meson:p
ca-certificates:p
cmake:p
ninja:p
pkg-config:p
sdl3:p
ca-certificates:p
- name: Set Environment Variables
run: |
@@ -254,6 +254,7 @@ jobs:
uses: actions/checkout@v4
- name: Setup MSVC
id: msvc-dev-cmd
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.arch.target }}
@@ -273,34 +274,18 @@ jobs:
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Install SDL
- name: Install pkgconf
env: { VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" }
run: vcpkg install sdl3:x64-windows-static pkgconf:x64-windows-release
run: vcpkg install pkgconf:x64-windows-release
- name: Add environment variables
# https://github.com/ilammy/msvc-dev-cmd?tab=readme-ov-file#name-conflicts-with-shell-bash
- name: Set environment variables
run: |
echo "PKG_CONFIG_PATH=C:\vcpkg\installed\x64-windows-static\lib\pkgconfig" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "PKG_CONFIG=C:\vcpkg\installed\x64-windows-release\tools\pkgconf\pkgconf.exe" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Set up environment variables
run: |
"INSTALL_NAME=lite-xl-$($env:GITHUB_REF -replace ".*/")-windows-msvc-${{ matrix.arch.name }}" >> $env:GITHUB_ENV
"INSTALL_REF=$($env:GITHUB_REF -replace ".*/")" >> $env:GITHUB_ENV
"LUA_SUBPROJECT_PATH=subprojects/$(awk -F ' *= *' '/directory/ { printf $2 }' subprojects/lua.wrap)" >> $env:GITHUB_ENV
- name: Download and patch subprojects
shell: bash
run: |
meson subprojects download
cat resources/windows/001-lua-unicode.diff | patch -Np1 -d "$LUA_SUBPROJECT_PATH"
- name: Configure
run: |
meson setup --wrap-mode=forcefallback build
echo "CC_LD=$((Get-Command link.exe).Source)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Build
run: |
meson install -C build --destdir="../lite-xl"
run: bash scripts/build.sh --addons --debug --forcefallback --lto --portable --mode ${{ needs.version.outputs.buildtype }} -b build
- name: Package
run: |
+2 -2
View File
@@ -164,7 +164,7 @@ jobs:
- name: Install Dependencies
run: |
brew install bash md5sha1sum sdl3
brew install bash md5sha1sum cmake
pip install meson ninja dmgbuild
- name: Build
@@ -276,7 +276,7 @@ jobs:
ca-certificates:p
ninja:p
pkg-config:p
sdl3:p
cmake:p
- name: Set Environment Variables
run: |
+51 -10
View File
@@ -44,6 +44,10 @@ main() {
local build_dir="$(get_default_build_dir)"
local build_type="debug"
local prefix=/
local build_type="release"
local sdl3_version="${SDL3_VERSION:-3.2.8}"
local pkg_config_path
local cmake_build_type
local force_fallback
local bundle
local portable
@@ -170,7 +174,11 @@ main() {
arch="${cross_arch:-$arch}"
cross_file=("--cross-file" "${cross_file:-resources/cross/$platform-$arch.txt}")
# reload build_dir because platform and arch might change
build_dir="$(get_default_build_dir "$platform" "$arch")"
if [[ "${build_dir}" == "" ]]; then
build_dir="$(get_default_build_dir "$platform" "$arch")"
fi
elif [[ "${build_dir}" == "" ]]; then
build_dir="$(get_default_build_dir)"
fi
# arch and platform specific stuff
@@ -186,16 +194,48 @@ main() {
export LDFLAGS="-mmacosx-version-min=$macos_version_min"
fi
rm -rf "${build_dir}"
if [[ $should_reconfigure == true ]] && [[ -d "${build_dir}" ]]; then
reconfigure="--reconfigure"
elif [[ -d "${build_dir}" ]]; then
rm -rf "${build_dir}"
fi
if [[ $patch_lua == "true" ]] && [[ ! -z $force_fallback ]]; then
# download the subprojects so we can start patching before configure.
# this will prevent reconfiguring the project.
meson subprojects download
lua_subproject_path="subprojects/$(awk -F ' *= *' '/directory/ { printf $2 }' subprojects/lua.wrap)"
if [[ -d $lua_subproject_path ]]; then
patch -d $lua_subproject_path -p1 --forward < resources/windows/001-lua-unicode.diff
mkdir -p "${build_dir}"
if [[ -n "$force_fallback" ]]; then
# download, build and add SDL3 to the pkgconfig search path
pushd "${build_dir}"
[[ ! -f "SDL3-$sdl3_version.tar.gz" ]] && curl --insecure -L -o "SDL3-$sdl3_version.tar.gz" \
"https://github.com/libsdl-org/SDL/releases/download/release-$sdl3_version/SDL3-$sdl3_version.tar.gz"
[[ ! -f "SDL3-$sdl3_version/CMakeLists.txt" ]] && tar -xzf "SDL3-$sdl3_version.tar.gz"
case "$build_type" in
"release"|"debug") cmake_build_type="$build_type";;
"debugoptimized") cmake_build_type="RelWithDebInfo";;
"minsize") cmake_build_type="MinSizeRel";;
*) cmake_build_type="Release";;
esac
# use -DCMAKE_INSTALL_LIBDIR to work around possibility of cmake using lib64 instead of lib
cmake -S "SDL3-$sdl3_version" -B "SDL3-$sdl3_version/build" -GNinja \
-DCMAKE_OSX_DEPLOYMENT_TARGET="$MACOSX_DEPLOYMENT_TARGET" -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=$([[ -n $lto ]] && echo ON || echo OFF) \
-DCMAKE_BUILD_TYPE=$cmake_build_type -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_PREFIX="$(pwd -P)/prefix" \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DSDL_INSTALL=ON -DSDL_INSTALL_DOCS=OFF -DSDL_DEPS_SHARED=ON \
-DSDL_DBUS=ON -DSDL_IBUS=ON -DSDL_AUDIO=OFF -DSDL_GPU=OFF -DSDL_RPATH=OFF -DSDL_PIPEWIRE=OFF \
-DSDL_CAMERA=OFF -DSDL_JOYSTICK=OFF -DSDL_HAPTIC=OFF -DSDL_HIDAPI=OFF -DSDL_DIALOG=OFF \
-DSDL_POWER=OFF -DSDL_SENSOR=OFF -DSDL_VULKAN=OFF -DSDL_LIBUDEV=OFF -DSDL_SHARED=OFF -DSDL_STATIC=ON \
-DSDL_X11=ON -DSDL_WAYLAND=ON -DSDL_TESTS=OFF -DSDL_EXAMPLES=OFF -DSDL_VENDOR_INFO=lite-xl
cmake --build "SDL3-$sdl3_version/build" && cmake --install "SDL3-$sdl3_version/build"
pkg_config_path="--pkg-config-path=$(pwd -P)/prefix/lib/pkgconfig"
popd
fi
if [[ -n "$plugins" ]] && [[ -z `command -v lpm` ]]; then
mkdir -p "${build_dir}"
lpm_path="$(pwd -P)/${build_dir}/lpm$(get_executable_extension)"
if [[ ! -e "$lpm_path" ]]; then
curl --insecure -L -o "$lpm_path" \
"https://github.com/lite-xl/lite-xl-plugin-manager/releases/download/${LPM_VERSION:-latest}/lpm.$(get_platform_tuple)$(get_executable_extension)"
chmod u+x "$lpm_path"
fi
export PATH="$(dirname "$lpm_path"):$PATH"
fi
CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS meson setup \
@@ -208,7 +248,8 @@ main() {
$pgo \
$lto \
$lto_mode \
"${build_dir}"
"${build_dir}" \
$pkg_config_path
meson compile -C "${build_dir}"