Alien-SDL3
view release on metacpan or search on metacpan
recipes/packages/l/libsdl3/xmake.lua view on Meta::CPAN
if package:config("wayland") == nil and not package:is_cross() then
package:config_set("wayland", true)
end
end
if package:is_plat("wasm") and package:config("threads") then
package:add("cxflags", "-pthread", "-matomics", "-mbulk-memory")
package:add("ldflags", "-pthread")
end
if package:is_plat("windows") then
package:add("deps", "ninja")
package:set("policy", "package.cmake_generator.ninja", true)
end
if package:is_plat("linux", "bsd", "cross") and package:config("x11") then
local deplibs = {"libx11", "libxcb", "libxext", "libxcursor", "libxfixes", "libxi", "libxrandr", "libxrender", "libxss"}
local depconfig = package:config("x11_shared") and {private = true, configs = {shared = true}} or nil
for _, lib in ipairs(deplibs) do
package:add("deps", lib, depconfig)
end
end
if package:is_plat("linux", "bsd", "cross") and package:config("wayland") then
if package:config("wayland_shared") then
package:add("deps", "wayland", {private = true, configs = {shared = true}})
else
package:add("deps", "wayland")
end
end
if package:is_plat("linux") and not package:is_cross() then
-- Fail fast with the apt command instead of letting xrepo bootstrap
-- the whole X11 stack from source: those builds are slow and flaky
-- (libtool relink races under parallel jobs have wedged CI for hours).
-- Each X11 library decides system-vs-source via its own upstream
-- recipe's add_extsources, so presence of these -dev packages is
-- what makes xrepo use the system libs.
local probes = {
{"libx11-dev", "/usr/include/X11/Xlib.h"},
{"libxcb1-dev", "/usr/include/xcb/xcb.h"},
{"libxext-dev", "/usr/include/X11/extensions/shape.h"},
{"libxfixes-dev", "/usr/include/X11/extensions/Xfixes.h"},
-- Debian/Ubuntu ships this header under X11/Xcursor/; there is
-- no /usr/include/X11/Xcursor.h to probe for.
{"libxcursor-dev", "/usr/include/X11/Xcursor/Xcursor.h"},
{"libxrandr-dev", "/usr/include/X11/extensions/Xrandr.h"},
{"libxi-dev", "/usr/include/X11/extensions/XInput2.h"},
{"libxrender-dev", "/usr/include/X11/extensions/Xrender.h"},
{"libxss-dev", "/usr/include/X11/extensions/scrnsaver.h"},
{"libxkbcommon-dev", "/usr/include/xkbcommon/xkbcommon.h"},
{"libwayland-dev", "/usr/include/wayland-client.h"},
}
local missing = {}
for _, probe in ipairs(probes) do
if not os.isfile(probe[2]) then
table.insert(missing, probe[1])
end
end
if #missing > 0 then
raise("libsdl3 requires the system X11/Wayland development packages. Missing: %s.\nInstall them with:\n sudo apt-get update && sudo apt-get install -y %s",
table.concat(missing, ", "),
"libx11-dev libxcb1-dev libxext-dev libxfixes-dev libxcursor-dev libxrandr-dev libxi-dev libxrender-dev libxss-dev libxkbcommon-dev libwayland-dev")
end
end
local libsuffix = package:is_debug() and "d" or ""
if not package:config("shared") then
if package:is_plat("windows", "mingw") then
package:add("syslinks", "user32", "gdi32", "winmm", "imm32", "ole32", "oleaut32", "version", "uuid", "advapi32", "setupapi", "shell32")
elseif package:is_plat("linux", "bsd") then
package:add("syslinks", "pthread", "dl")
if package:is_plat("bsd") then
package:add("syslinks", "usbhid")
end
elseif package:is_plat("android") then
package:add("syslinks", "dl", "log", "android", "GLESv1_CM", "GLESv2", "OpenSLES")
elseif package:is_plat("iphoneos", "macosx") then
package:add("frameworks", "AudioToolbox", "AVFoundation", "CoreAudio", "CoreHaptics", "CoreMedia", "CoreVideo", "Foundation", "GameController", "Metal", "QuartzCore", "CoreFoundation", "UniformTypeIdentifiers")
package:add("syslinks", "iconv")
if package:is_plat("macosx") then
package:add("frameworks", "Cocoa", "Carbon", "ForceFeedback", "IOKit")
else
package:add("frameworks", "CoreBluetooth", "CoreGraphics", "CoreMotion", "OpenGLES", "UIKit")
end
end
end
end)
on_install(function (package)
-- Windows has no working from-source story for this family yet
-- (https://github.com/Perl-SDL3/Alien-SDL3.pm/issues/3: the toolchain in play is
-- x64 gcc running under emulation on windows-11-arm, and xmake picks the ARM64
-- host arch, which no part of the toolchain can actually produce). The Alien is
-- consumed through FFI, which needs only a shared library and its headers, so
-- install the matching official prebuilt package instead of compiling:
-- * MSVC -> <prefix>-devel-<ver>-VC.zip root/lib/{x86,x64,arm64}
-- * MinGW -> <prefix>-devel-<ver>-mingw.zip <triple>/{bin,include,lib}
-- The flavour follows the *toolchain*, not the OS, so that on_test -- which
-- compiles and links a probe after every install -- gets an import library the
-- active linker can use: gcc wants the mingw .dll.a, cl wants the VC .lib. The
-- archive for the other toolchain is never fetched. The sub-arch comes from
-- package:arch(), which Alien::SDL3's install_opts() pins to $Config{archname},
-- so the DLL handed back is the one the running Perl can load.
-- This helper is deliberately defined *inside* the callback: sandbox.new()
-- setfenv()s only the script itself (core/sandbox/sandbox.lua:239), so a
-- chunk-level local function keeps the package script's read-only `os`
-- (isfile/isdir/files/dirs only -- no mkdir/cp/rm) and dies on first use.
local function _install_windows_prebuilt(package, github_repo, asset_prefix, linkname)
local ver = package:version_str()
local msvc = package:has_tool("cxx", "cl")
local flavour = msvc and "VC" or "mingw"
local url = string.format(
"https://github.com/libsdl-org/%s/releases/download/release-%s/%s-devel-%s-%s.zip",
github_repo, ver, asset_prefix, ver, flavour)
local cachedir = package:cachedir()
os.mkdir(cachedir)
local zipfile = path.join(cachedir, string.format("%s-devel-%s-%s.zip", asset_prefix, ver, flavour))
if not os.isfile(zipfile) then
import("net.http.download")(url, zipfile)
end
local workdir = path.join(package:builddir(), "prebuilt")
os.tryrm(workdir)
os.mkdir(workdir)
import("utils.archive.extract")(zipfile, workdir)
recipes/packages/l/libsdl3/xmake.lua view on Meta::CPAN
raise("package(%s): no mingw prebuilt for arch %q; use the MSVC toolchain instead",
package:name(), package:arch() or "?")
end
if is_arm then
raise("package(%s): SDL publishes no mingw arm64 prebuilt; use the MSVC toolchain instead",
package:name())
end
local triple = "x86_64-w64-mingw32"
incdir = path.join(root, triple, "include")
libdir = path.join(root, triple, "lib")
bindir = path.join(root, triple, "bin")
end
if not os.isdir(libdir) then
raise("package(%s): prebuilt archive has no %s for arch %q", package:name(), libdir, package:arch() or "?")
end
local installdir = package:installdir()
local incdst = path.join(installdir, "include")
local libdst = path.join(installdir, "lib")
local bindst = path.join(installdir, "bin")
os.mkdir(incdst); os.mkdir(libdst); os.mkdir(bindst)
-- Copy the *contents* of include/: a bare-dir cp would nest it as include/SDL3-3.4.18.
os.cp(path.join(incdir, "*"), incdst)
-- Import libraries for the linker.
for _, pattern in ipairs({"*.lib", "*.dll.a", "*.a"}) do
os.cp(path.join(libdir, pattern), libdst)
end
-- Runtime DLLs. Alien::Xrepo picks libpath -- the file FFI dlopens, which
-- t/affix.t load_library()s -- from the first .dll found in linkdirs, so the
-- DLL must live in lib/ as well as in bin/, which is what puts it on the
-- PATH that xmake builds for on_test.
os.cp(path.join(libdir, "*.dll"), libdst)
os.cp(path.join(bindir, "*.dll"), bindst)
os.cp(path.join(bindir, "*.dll"), libdst)
-- image/mixer ship codec DLLs in a side directory of the VC layout only.
local optional = path.join(libdir, "optional")
if os.isdir(optional) then
os.cp(path.join(optional, "*.dll"), libdst)
os.cp(path.join(optional, "*.dll"), bindst)
end
-- CMake normally publishes these; a manual install has to declare them, or
-- _generate_configs() raises "links not found!" for every consumer (including
-- this package's own on_test). The dir entries must be relative: the manifest
-- reader joins them onto the installdir itself
-- (modules/package/manager/xmake/find_package.lua:81,144), so an absolute path
-- would come back as installdir/C:/... and find_library would find nothing.
package:add("includedirs", "include")
package:add("linkdirs", "lib")
package:add("bindirs", "bin")
package:add("links", linkname)
end
if package:is_plat("windows") then
_install_windows_prebuilt(package, "SDL", "SDL3", "SDL3")
return
end
local configs = {}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DSDL_TEST_LIBRARY=OFF")
table.insert(configs, "-DSDL_EXAMPLES=OFF")
if package:is_plat("linux", "bsd", "cross") then
table.insert(configs, "-DSDL_X11=" .. (package:config("x11") and "ON" or "OFF"))
table.insert(configs, "-DSDL_X11_SHARED=" .. (package:config("x11_shared") and "ON" or "OFF"))
table.insert(configs, "-DSDL_X11_XTEST=OFF")
table.insert(configs, "-DSDL_WAYLAND=" .. (package:config("wayland") and "ON" or "OFF"))
table.insert(configs, "-DSDL_WAYLAND_SHARED=" .. (package:config("wayland_shared") and "ON" or "OFF"))
end
if package:is_plat("solaris") then
-- xmake reads a 64-bit Solaris host's arch as i386 (uname -m is the
-- unhelpful "i86pc"), so the `-a x86_64` this Alien passes looks like
-- a cross-compile: cmake.lua takes its cross branch, where
-- CMAKE_SYSTEM_NAME becomes package:targetos() -- literally
-- "solaris" -- and cmake dies with
-- System is unknown to cmake, create: Platform/solaris
-- That branch exists to keep cmake from searching the host's
-- include/library paths, which is exactly wrong for what is really
-- a native build. Pin the platform to the name cmake knows, and undo
-- the system/prefix search suppression. cmake.lua only inserts its
-- own value for a key the recipe has not already set as -D<key>=,
-- so these win.
table.insert(configs, "-DCMAKE_SYSTEM_NAME=SunOS")
table.insert(configs, "-DCMAKE_FIND_USE_CMAKE_SYSTEM_PATH=ON")
table.insert(configs, "-DCMAKE_FIND_USE_INSTALL_PREFIX=ON")
end
if package:is_plat("wasm") and package:config("threads") then
table.insert(configs, "-DSDL_PTHREADS=ON")
end
local cflags
local packagedeps
if not package:is_plat("wasm") then
packagedeps = table.join2(packagedeps or {}, {"egl-headers", "opengl-headers"})
end
if package:is_plat("linux", "bsd", "cross") then
packagedeps = table.join2(packagedeps or {}, {"libxcursor", "libxext", "libxfixes", "libxcb", "libx11", "libxi", "libxrandr", "libxrender", "libxss", "xorgproto", "wayland"})
elseif package:is_plat("wasm") then
-- emscripten enables USE_SDL by default which will conflict with libsdl headers
cflags = {"-sUSE_SDL=0"}
end
local includedirs = {}
for _, depname in ipairs(packagedeps) do
local dep = package:dep(depname)
if dep then
local depfetch = dep:fetch()
if depfetch then
for _, includedir in ipairs(depfetch.includedirs or depfetch.sysincludedirs) do
table.insert(includedirs, includedir)
end
end
end
end
if #includedirs > 0 then
includedirs = table.unique(includedirs)
table.insert(configs, "-DCMAKE_INCLUDE_PATH=" .. table.concat(includedirs, ";"))
( run in 0.785 second using v1.01-cache-2.11-cpan-c32d3c3b8f1 )