Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sokol #10381

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
71 changes: 71 additions & 0 deletions S/Sokol/build_tarballs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using BinaryBuilder
import Pkg: PackageSpec

name = "Sokol"
version = v"2025.28.1" # Use the commit date or tag of Sokol you're targeting

# Use the latest commit or a specific tag from the Sokol repository
sources = [
GitSource("https://github.com/floooh/sokol.git", "db9ebdf24243572c190affde269b92725942ddd0"),
DirectorySource("./bundled"),
]

# Build script
script = raw"""
cd $WORKSPACE/srcdir/sokol*
export CFLAGS="-I${includedir}"
cp ${WORKSPACE}/srcdir/files/CMakeLists.txt ./CMakeLists.txt
cp ${WORKSPACE}/srcdir/files/sokol.c ./sokol.c

if [[ ${target} == aarch64-apple-* ]]; then
# `libclang_rt.osx.a` from LLVM compiler-rt.
FLAGS+=(-DCMAKE_SHARED_LINKER_FLAGS="-L${libdir}/darwin -lclang_rt.osx"
-DCMAKE_EXE_LINKER_FLAGS="-L${libdir}/darwin -lclang_rt.osx"
-DUSE_METAL=ON
)
fi

cmake -B build \
-DCMAKE_INSTALL_PREFIX=$prefix \
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} \
-DCMAKE_BUILD_TYPE=Release \
"${FLAGS[@]}"

cmake --build build

install -Dm 755 "build/libsokol.${dlext}" "${libdir}/libsokol.${dlext}"
VarLad marked this conversation as resolved.
Show resolved Hide resolved
install -Dm 755 "sokol_gfx.h" "${includedir}/sokol_gfx.h"
install -Dm 755 "sokol_app.h" "${includedir}/sokol_app.h"
install -Dm 755 "sokol_audio.h" "${includedir}/sokol_audio.h"
install -Dm 755 "sokol_time.h" "${includedir}/sokol_time.h"
install -Dm 755 "sokol_glue.h" "${includedir}/sokol_glue.h"
install -Dm 755 "sokol_log.h" "${includedir}/sokol_log.h"
install -Dm 755 "sokol_args.h" "${includedir}/sokol_args.h"
install -Dm 755 "sokol_fetch.h" "${includedir}/sokol_fetch.h"
VarLad marked this conversation as resolved.
Show resolved Hide resolved
"""

# Supported platforms
platforms = supported_platforms(exclude=p->arch(p)=="armv6l"||Sys.isfreebsd(p)||arch(p)=="riscv64")
llvm_version = v"13.0.1+1"

# Platform-specific dependencies
dependencies = [
# Linux dependencies
Dependency("Xorg_libX11_jll"; platforms=filter(Sys.islinux, platforms)),
Dependency("Xorg_libXrandr_jll"; platforms=filter(Sys.islinux, platforms)),
Dependency("Xorg_libXi_jll"; platforms=filter(Sys.islinux, platforms)),
Dependency("Xorg_libXcursor_jll"; platforms=filter(Sys.islinux, platforms)),
Dependency("Xorg_libXinerama_jll"; platforms=filter(Sys.islinux, platforms)),
Dependency("Libglvnd_jll"; platforms=filter(Sys.islinux, platforms)),
Dependency("alsa_jll"; platforms=filter(Sys.islinux, platforms)),
BuildDependency("Xorg_xorgproto_jll"; platforms=filter(Sys.islinux, platforms)),
BuildDependency(PackageSpec(name="LLVMCompilerRT_jll", uuid="4e17d02c-6bf5-513e-be62-445f41c75a11", version=llvm_version);
platforms=[Platform("aarch64", "macos")])
]

# Library products
products = [
LibraryProduct("libsokol", :libsokol)
]

build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies; julia_compat="1.6", preferred_gcc_version=v"7", preferred_llvm_version=llvm_version)
44 changes: 44 additions & 0 deletions S/Sokol/bundled/files/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.0)
project(game)
set(CMAKE_C_STANDARD 11)
if (CMAKE_SYSTEM_NAME STREQUAL Emscripten)
set(CMAKE_EXECUTABLE_SUFFIX ".html")
endif()
option(USE_METAL "Enable/disable Metal" OFF)
# Linux -pthread shenanigans
if (CMAKE_SYSTEM_NAME STREQUAL Linux)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
endif()
#=== LIBRARY: sokol
# add headers to the the file list because they are useful to have in IDEs
set(SOKOL_HEADERS
sokol_gfx.h
sokol_app.h
sokol_audio.h
sokol_time.h
sokol_glue.h
sokol_log.h
sokol_args.h
sokol_fetch.h
)
add_library(sokol SHARED sokol.c ${SOKOL_HEADERS})
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(exe_type MACOSX_BUNDLE)
# compile sokol.c as Objective-C
target_compile_options(sokol PRIVATE -x objective-c)
if(USE_METAL)
target_link_libraries(sokol "-framework QuartzCore" "-framework Cocoa" "-framework MetalKit" "-framework Metal" "-framework AudioToolbox")
else()
target_link_libraries(sokol "-framework OpenGLES" "-framework GLKit")
endif()
else()
if (CMAKE_SYSTEM_NAME STREQUAL Linux)
target_link_libraries(sokol INTERFACE X11 Xi Xcursor GL asound dl m)
target_link_libraries(sokol PUBLIC Threads::Threads)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
set(exe_type WIN32)
endif()
endif()
target_include_directories(sokol INTERFACE sokol)
22 changes: 22 additions & 0 deletions S/Sokol/bundled/files/sokol.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#define SOKOL_IMPL
#if defined(_MSC_VER)
#define SOKOL_D3D11
#define SOKOL_LOG(str) OutputDebugStringA(str)
#elif defined(__EMSCRIPTEN__)
#define SOKOL_GLES2
#elif defined(__APPLE__)
// NOTE: on macOS, sokol.c is compiled explicitly as ObjC
#include <TargetConditionals.h>
#define SOKOL_METAL
#else
#define SOKOL_GLCORE
#endif
#define SOKOL_WIN32_FORCE_MAIN
#include "sokol_audio.h"
#include "sokol_app.h"
#include "sokol_gfx.h"
#include "sokol_time.h"
#include "sokol_glue.h"
#include "sokol_fetch.h"
#include "sokol_log.h"
#include "sokol_args.h"