Skip to content

Commit 063df43

Browse files
committed
Start of linux-x64 SDL build
1 parent 22af898 commit 063df43

20 files changed

+176
-1
lines changed

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
*.7z binary
5454
*.ttf binary
5555
*.stout binary
56+
*.so binary
57+
*.dll binary
58+
*.dylib binary
59+
5660

5761
# Verify
5862
*.verified.txt text eol=lf working-tree-encoding=UTF-8

.github/workflows/native.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,5 @@ jobs:
9494
git config --local user.email "9011267+dotnet-bot@users.noreply.github.com"
9595
git config --local user.name "The Silk.NET Automaton"
9696
git add .
97-
git commit -m "Update native binaries for ${{ github.sha }}"
97+
git commit -m "Update native binaries for $(git rev-parse HEAD)"
9898
git push

eng/native/buildsystem/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
test.txt
2+
zig/
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python3
2+
3+
import json
4+
import urllib.request
5+
import os.path
6+
import os
7+
import shutil
8+
import sys
9+
import platform
10+
import tarfile
11+
12+
zig_path = os.path.join(os.path.dirname(__file__), "zig")
13+
if os.path.exists(zig_path):
14+
shutil.rmtree(zig_path)
15+
os.mkdir(zig_path)
16+
tarfile.open(
17+
fileobj=urllib.request.urlopen(
18+
json.load(urllib.request.urlopen("https://ziglang.org/download/index.json"))[
19+
"master"
20+
][
21+
{
22+
"linux": (
23+
"x86_64-linux" if platform.processor() != "arm" else "aarch64-linux"
24+
),
25+
"linux2": (
26+
"x86_64-linux" if platform.processor() != "arm" else "aarch64-linux"
27+
),
28+
"darwin": (
29+
"x86_64-macos" if platform.processor() != "arm" else "aarch64-macos"
30+
),
31+
"win32": (
32+
"x86_64-windows"
33+
if platform.processor() != "arm"
34+
else "aarch64-windows"
35+
),
36+
}[sys.platform]
37+
][
38+
"tarball"
39+
]
40+
),
41+
mode="r|xz",
42+
).extractall(zig_path)
43+
for x in os.scandir(next(f.path for f in os.scandir(zig_path) if f.is_dir())):
44+
shutil.move(x, os.path.join(zig_path, os.path.basename(x)))

eng/native/cmake/fudge.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Origignal script from https://github.com/ziglang/zig/issues/4911
4+
# Modified to add SILKDOTNET_ paths in response to some issues with SwiftShader
5+
6+
args=""
7+
for arg in "$@"
8+
do
9+
parg="$arg"
10+
11+
option=${arg%=*}
12+
target=${arg#*=}
13+
if [[ $option == "-march" || $option == "-mcpu" || $option == "-mtune" ]]; then
14+
moveon=0
15+
for replace in $SILKDOTNET_ReplaceArchitectureZigCcFlags
16+
do
17+
replacetarget=${replace%=*}
18+
replacement=${replace#*=}
19+
# echo $replacetarget A $replacement B $target END
20+
if [[ $replacetarget == $target ]]; then
21+
if [[ "$replacement" == "" ]]; then
22+
moveon=1
23+
else
24+
target="$replacement"
25+
fi
26+
fi
27+
done
28+
if [[ $moveon == 1 || "$SILKDOTNET_RemoveAllPotentiallyProblematicZigCcFlags" == "1" ]]; then
29+
continue
30+
else
31+
fixedTarget=${target//-/_}
32+
parg="$option=$fixedTarget"
33+
fi
34+
fi
35+
args="$args $parg"
36+
done

eng/native/cmake/zig-ar.cmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@echo off
2+
zig ar %*

eng/native/cmake/zig-ar.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
zig ar "$@"

eng/native/cmake/zig-c++.cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
: TODO add -march/-mtune handling if necessary
3+
zig c++ %*

eng/native/cmake/zig-c++.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
. "$(dirname ${BASH_SOURCE[0]})/fudge.sh" $args
3+
zig c++ $args

eng/native/cmake/zig-cc.cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
: TODO add -march/-mtune handling if necessary
3+
zig cc %*

eng/native/cmake/zig-cc.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
. "$(dirname ${BASH_SOURCE[0]})/fudge.sh" $args
3+
zig cc $args

eng/native/cmake/zig-ranlib.cmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@echo off
2+
zig ranlib %*

eng/native/cmake/zig-ranlib.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
zig ranlib "$@"

eng/native/cmake/zig-rc.cmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@echo off
2+
zig rc %*

eng/native/cmake/zig-rc.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
zig rc "$@"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set(ZIG_TARGET "aarch64-linux-gnu.2.17")
2+
include(${CMAKE_CURRENT_LIST_DIR}/zig-toolchain.cmake)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set(ZIG_TARGET "arm-linux-gnueabihf.2.17")
2+
include(${CMAKE_CURRENT_LIST_DIR}/zig-toolchain.cmake)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set(ZIG_TARGET "x86_64-linux-gnu.2.17")
2+
include(${CMAKE_CURRENT_LIST_DIR}/zig-toolchain.cmake)

eng/native/cmake/zig-toolchain.cmake

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
include_guard()
2+
3+
if(CMAKE_GENERATOR MATCHES "Visual Studio")
4+
message(FATAL_ERROR "Visual Studio generator not supported, use: cmake -G Ninja")
5+
endif()
6+
7+
if(NOT ZIG_TARGET MATCHES "^([a-zZ-Z0-9_]+)-([a-zZ-Z0-9_]+)-([a-zZ-Z0-9_.]+)$")
8+
message(FATAL_ERROR "Expected -DZIG_TARGET=<arch>-<os>-<abi>")
9+
endif()
10+
11+
set(ZIG_ARCH ${CMAKE_MATCH_1})
12+
set(ZIG_OS ${CMAKE_MATCH_2})
13+
set(ZIG_ABI ${CMAKE_MATCH_3})
14+
15+
if(ZIG_OS STREQUAL "linux")
16+
set(CMAKE_SYSTEM_NAME "Linux")
17+
elseif(ZIG_OS STREQUAL "windows")
18+
set(CMAKE_SYSTEM_NAME "Windows")
19+
elseif(ZIG_OS STREQUAL "macos")
20+
set(CMAKE_SYSTEM_NAME "Darwin")
21+
else()
22+
message(WARNING "Unknown OS: ${ZIG_OS}")
23+
endif()
24+
25+
set(CMAKE_SYSTEM_VERSION 1)
26+
set(CMAKE_SYSTEM_PROCESSOR ${ZIG_ARCH})
27+
28+
if(WIN32)
29+
set(SCRIPT_SUFFIX ".cmd")
30+
else()
31+
set(SCRIPT_SUFFIX ".sh")
32+
endif()
33+
34+
# This is working (thanks to Simon for finding this trick)
35+
set(CMAKE_AR "${CMAKE_CURRENT_LIST_DIR}/zig-ar${SCRIPT_SUFFIX}")
36+
set(CMAKE_RANLIB "${CMAKE_CURRENT_LIST_DIR}/zig-ranlib${SCRIPT_SUFFIX}")
37+
set(CMAKE_RC_COMPILER "${CMAKE_CURRENT_LIST_DIR}/zig-rc${SCRIPT_SUFFIX}")
38+
set(CMAKE_ASM_COMPILER "${CMAKE_CURRENT_LIST_DIR}/zig-cc${SCRIPT_SUFFIX}" -target ${ZIG_TARGET})
39+
set(CMAKE_C_COMPILER "${CMAKE_CURRENT_LIST_DIR}/zig-cc${SCRIPT_SUFFIX}" -target ${ZIG_TARGET})
40+
set(CMAKE_CXX_COMPILER "${CMAKE_CURRENT_LIST_DIR}/zig-c++${SCRIPT_SUFFIX}" -target ${ZIG_TARGET})

sources/SDL/Native/build-linux-x64.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env -S bash -eu
2+
if [[ ! -z ${GITHUB_ACTIONS+x} ]]; then
3+
../../../eng/native/buildsystem/download-zig.py
4+
export PATH="$PATH:$(readlink -f "../../../eng/native/buildsystem/zig/zig")"
5+
apt-get install build-essential git make \
6+
pkg-config cmake ninja-build gnome-desktop-testing libasound2-dev libpulse-dev \
7+
libaudio-dev libjack-dev libsndio-dev libx11-dev libxext-dev \
8+
libxrandr-dev libxcursor-dev libxfixes-dev libxi-dev libxss-dev \
9+
libxkbcommon-dev libdrm-dev libgbm-dev libgl1-mesa-dev libgles2-mesa-dev \
10+
libegl1-mesa-dev libdbus-1-dev libibus-1.0-dev libudev-dev fcitx-libs-dev \
11+
libpipewire-0.3-dev libwayland-dev libdecor-0-dev liburing-dev
12+
fi
13+
rm -rf build
14+
mkdir build
15+
cd build
16+
cmake ../../../../eng/submodules/sdl -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../../../../eng/native/cmake/zig-toolchain-x86_64-linux-gnu.2.17.cmake
17+
cmake --build . --parallel
18+
cd ..
19+
mkdir -p runtimes/linux-x64/native
20+
cp build/libSDL3.so runtimes/linux-x64/native

0 commit comments

Comments
 (0)