Skip to content

Commit bc82423

Browse files
authored
Merge 40d0a32 into 3f39401
2 parents 3f39401 + 40d0a32 commit bc82423

File tree

8 files changed

+330
-0
lines changed

8 files changed

+330
-0
lines changed

.github/workflows/native.yml

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Native Builds
2+
on:
3+
pull_request:
4+
types: [opened, edited, synchronize]
5+
permissions:
6+
pull-requests: write
7+
contents: write
8+
env:
9+
# A space-separated list of paths to native libraries to build.
10+
NATIVE_LIBRARY_PATHS: "sources/SDL/Native"
11+
# A space-separated list of submodule paths for each native library path. Use _ if a submodule is not used - this must
12+
# match the number of spaces in NATIVE_LIBRARY_PATHS.
13+
NATIVE_LIBRARY_SUBMODULE_PATHS: "eng/submodules/sdl"
14+
# A space-separated list of shorthands to the native library paths that will build the native library for each native
15+
# library path. This must match the number of spaces in NATIVE_LIBRARY_PATHS. If a shorthand builds multiple native
16+
# binary paths, these will be deduplicated.
17+
NATIVE_LIBRARY_SHORTHANDS: "SDL"
18+
jobs:
19+
prerequisites:
20+
name: PR Check
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v3
24+
- id: parse
25+
name: Determine which native libraries the user has asked to build, and where to look for changes.
26+
run: ./workflow-stage1.sh
27+
working-directory: eng/native/buildsystem
28+
env:
29+
PR_COMMENT: ${{ github.event.pull_request.body }}
30+
- uses: dorny/paths-filter@v3
31+
id: filter
32+
name: Determine which natives need to be rebuilt.
33+
with:
34+
filters: ${{ steps.parse.outputs.workflow_filters }}
35+
- name: Find a warning message from a previous run, if applicable.
36+
uses: peter-evans/find-comment@v3
37+
id: fc
38+
with:
39+
issue-number: ${{ github.event.number }}
40+
comment-author: "github-actions[bot]"
41+
body-includes: "Some of the native library builds modified in this PR were not referenced in the PR description."
42+
- id: strat
43+
name: Create the matrix strategy for the native builds.
44+
run: ./workflow-stage2.sh
45+
working-directory: eng/native/buildsystem
46+
env:
47+
NATIVE_LIBRARY_APPLICABLE_SHORTHANDS: ${{ join(fromJSON(steps.filter.outputs.changes), ' ') }}
48+
NATIVE_LIBRARY_USER_REFERENCED_SHORTHANDS: ${{ steps.parse.outputs.targets_referenced }}
49+
PR_EXISTING_NOTICE_ID: ${{ steps.fc.outputs.comment-id }}
50+
- name: Write a comment if needed.
51+
if: ${{ steps.strat.outputs.comment_to_write }}
52+
uses: peter-evans/create-or-update-comment@v4
53+
with:
54+
comment-id: ${{ steps.fc.outputs.comment-id }}
55+
issue-number: ${{ github.event.number }}
56+
body: ${{ steps.strat.outputs.comment_to_write }}
57+
edit-mode: replace
58+
outputs:
59+
matrix_strategy: ${{ steps.strat.outputs.matrix_strategy }}
60+
targets_referenced: ${{ steps.parse.outputs.targets_referenced }}
61+
build:
62+
needs: [prerequisites]
63+
strategy:
64+
matrix:
65+
flat: ${{ fromJSON(needs.prerequisites.outputs.matrix_strategy) }}
66+
runs-on: ${{ (startsWith(matrix.flat.runtime, 'osx') || startsWith(matrix.flat.runtime, 'ios') || startsWith(matrix.flat.runtime, 'tvos')) && 'macos-latest' || startsWith(matrix.flat.runtime, 'win') && 'windows-latest' || 'ubuntu-latest' }}
67+
name: ${{ matrix.flat.target }} / ${{ matrix.flat.runtime }}
68+
steps:
69+
- uses: actions/checkout@v3
70+
- run: ${{ format('.{0}{1}', startsWith(matrix.flat.runtime, 'win') && '\' || '/', matrix.flat.exec) }}
71+
working-directory: ${{ matrix.flat.dir }}
72+
- uses: actions/upload-artifact@v4
73+
with:
74+
name: natives-${{ matrix.flat.target }}-${{ matrix.flat.runtime }}
75+
path: |
76+
${{ matrix.flat.dir }}/runtimes/${{ matrix.flat.runtime }}/**/*
77+
${{ matrix.flat.dir}}/lib/*${{ matrix.flat.runtime }}*/**/*
78+
commit:
79+
name: Commit Binaries
80+
needs: [prerequisites, build]
81+
runs-on: ubuntu-latest
82+
if: ${{ needs.prerequisites.outputs.targets_referenced }}
83+
steps:
84+
- uses: actions/checkout@v4
85+
with:
86+
ref: ${{ github.head_ref }}
87+
- name: Download All Artifacts
88+
uses: actions/download-artifact@v4
89+
with:
90+
pattern: natives-*
91+
merge-multiple: true
92+
- name: Commit Artifacts
93+
run: |
94+
git config --local user.email "9011267+dotnet-bot@users.noreply.github.com"
95+
git config --local user.name "The Silk.NET Automaton"
96+
git add .
97+
git commit -m "Update native binaries for ${{ github.sha }}"
98+
git push

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,11 @@ src/Website/Silk.NET.Statiq/cache
489489

490490
# Verify
491491
*.received.*
492+
493+
# Native Binaries
494+
!**/runtimes/*/native/*.dylib
495+
!**/runtimes/*/native/*.so
496+
!**/runtimes/*/native/*.dll
497+
!**/lib/**/*.aar
498+
build/
499+
!eng/build/

eng/native/buildsystem/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/usr/bin/env -S bash -eu
2+
3+
export NATIVE_LIBRARY_SHORTHANDS="Sdl Aaaa Sdl B"
4+
export NATIVE_LIBRARY_PATHS="sources/SDL/Native sources/Aaaa/Native sources/SDL-Other/Native sources/B/Native"
5+
export NATIVE_LIBRARY_SUBMODULE_PATHS="eng/submodules/sdl eng/submodules/aaaa eng/submodules/sdl-other eng/submodules/b"
6+
export GITHUB_OUTPUT="test.txt"
7+
export PR_COMMENT=$'Hello\n/build-native sdl aaaa\nworld'
8+
9+
rm -f test.txt
10+
./workflow-stage1.sh
11+
12+
EXPECTED="workflow_filters<<EOF
13+
Aaaa: [\"sources/Aaaa/Native/*\", \"eng/submodules/aaa\"]
14+
B: [\"sources/B/Native/*\", \"eng/submodules/b\"]
15+
Sdl: [\"sources/SDL/Native/*\", \"eng/submodules/sdl\", \"sources/SDL-Other/Native/*\", \"eng/submodules/sdl-other\"]
16+
EOF
17+
targets_referenced=Aaaa Sdl"
18+
19+
if [[ "$(cat test.txt)" == "$EXPECTED" ]]; then
20+
echo stage1 pass
21+
else
22+
echo stage1 fail
23+
cat test.txt
24+
fi
25+
26+
export NATIVE_LIBRARY_APPLICABLE_SHORTHANDS="Sdl Aaaa"
27+
export NATIVE_LIBRARY_USER_REFERENCED_SHORTHANDS="Sdl"
28+
29+
rm -f test.txt
30+
./workflow-stage2.sh
31+
32+
EXPECTED="matrix_strategy<<EOF
33+
[
34+
{
35+
\"target\": \"Sdl\",
36+
\"runtime\": \"osx\",
37+
\"exec\": \"build-osx.sh\",
38+
\"dir\": \"sources/SDL/Native\"
39+
}
40+
]
41+
EOF
42+
comment_to_write=Some of the native library builds modified in this PR were not referenced in the PR description. Please ensure that the PR description contains \`/build-native Sdl Aaaa\`. These libraries won't be rebuilt without this being specified. If you believe this is in error, then please write a comment explaining why and ignore this suggestion. This comment will be automatically updated if rectified."
43+
if [[ "$(cat test.txt)" == "$EXPECTED" ]]; then
44+
echo stage2 with angry comment pass
45+
else
46+
echo stage2 with angry comment fail
47+
cat test.txt
48+
fi
49+
50+
export NATIVE_LIBRARY_APPLICABLE_SHORTHANDS="Sdl Aaaa"
51+
export NATIVE_LIBRARY_USER_REFERENCED_SHORTHANDS="Sdl Aaaa"
52+
53+
rm -f test.txt
54+
./workflow-stage2.sh
55+
56+
EXPECTED="matrix_strategy<<EOF
57+
[
58+
{
59+
\"target\": \"Sdl\",
60+
\"runtime\": \"osx\",
61+
\"exec\": \"build-osx.sh\",
62+
\"dir\": \"sources/SDL/Native\"
63+
}
64+
]
65+
EOF"
66+
if [[ "$(cat test.txt)" == "$EXPECTED" ]]; then
67+
echo stage2 with no angry comment pass
68+
else
69+
echo stage2 with no angry comment fail
70+
cat test.txt
71+
fi
72+
73+
export NATIVE_LIBRARY_APPLICABLE_SHORTHANDS="Sdl Aaaa"
74+
export NATIVE_LIBRARY_USER_REFERENCED_SHORTHANDS="Sdl Aaaa B"
75+
76+
rm -f test.txt
77+
./workflow-stage2.sh
78+
79+
EXPECTED="matrix_strategy<<EOF
80+
[
81+
{
82+
\"target\": \"Sdl\",
83+
\"runtime\": \"osx\",
84+
\"exec\": \"build-osx.sh\",
85+
\"dir\": \"sources/SDL/Native\"
86+
}
87+
]
88+
EOF"
89+
if [[ "$(cat test.txt)" == "$EXPECTED" ]]; then
90+
echo stage2 with no angry comment when we have extra targets pass
91+
else
92+
echo stage2 with no angry comment when we have extra targets fail
93+
cat test.txt
94+
fi
95+
96+
export NATIVE_LIBRARY_APPLICABLE_SHORTHANDS="Sdl Aaaa"
97+
export NATIVE_LIBRARY_USER_REFERENCED_SHORTHANDS="Sdl Aaaa B"
98+
export PR_EXISTING_NOTICE_ID=123
99+
100+
rm -f test.txt
101+
./workflow-stage2.sh
102+
103+
EXPECTED="matrix_strategy<<EOF
104+
[
105+
{
106+
\"target\": \"Sdl\",
107+
\"runtime\": \"osx\",
108+
\"exec\": \"build-osx.sh\",
109+
\"dir\": \"sources/SDL/Native\"
110+
}
111+
]
112+
EOF
113+
comment_to_write=All native library builds modified in this PR shall attempt to be built by CI."
114+
if [[ "$(cat test.txt)" == "$EXPECTED" ]]; then
115+
echo stage2 with updating angry comment to not be angry pass
116+
else
117+
echo stage2 with updating angry comment to not be angry fail
118+
cat test.txt
119+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env -S bash -eu
2+
IFS=' ' read -a NATIVE_LIBRARY_PATHS_ARRAY <<< "$NATIVE_LIBRARY_PATHS"
3+
IFS=' ' read -a NATIVE_LIBRARY_SUBMODULE_PATHS_ARRAY <<< "$NATIVE_LIBRARY_SUBMODULE_PATHS"
4+
IFS=' ' read -a NATIVE_LIBRARY_SHORTHANDS_ARRAY <<< "$NATIVE_LIBRARY_SHORTHANDS"
5+
NATIVE_LIBRARY_UNIQUE_SHORTHANDS=$(printf "%s\n" "${NATIVE_LIBRARY_SHORTHANDS_ARRAY[@]}" | sort -u)
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env -S bash -eu
2+
. workflow-common.sh
3+
WORKFLOW_FILTERS=""
4+
5+
# Get the paths for the workflow filter action.
6+
echo "workflow_filters<<EOF" >> $GITHUB_OUTPUT
7+
for item in $NATIVE_LIBRARY_UNIQUE_SHORTHANDS; do
8+
# Add the submodule paths and a glob for the native folder to the workflow filters
9+
workflow_filter="$item: ["
10+
i=0
11+
filter_delim=""
12+
for target in ${NATIVE_LIBRARY_SHORTHANDS_ARRAY[@]}; do
13+
if [[ "$target" == "$item" ]]; then
14+
workflow_filter="$workflow_filter$filter_delim\"${NATIVE_LIBRARY_PATHS_ARRAY[$i]}/*\", \"${NATIVE_LIBRARY_SUBMODULE_PATHS_ARRAY[$i]}\""
15+
filter_delim=", "
16+
fi
17+
i=$(expr $i + 1)
18+
done
19+
echo "$workflow_filter]" >> $GITHUB_OUTPUT
20+
done
21+
echo EOF >> $GITHUB_OUTPUT
22+
23+
# Get a list of targets referenced by the user - we won't build anything we're not asked to build, but at the same time
24+
# we want to yell at them (in stage 2) if they've built something they've gone and modified.
25+
TARGETS_REFERENCED=""
26+
ref_delim=""
27+
while read line
28+
do
29+
for item in $NATIVE_LIBRARY_UNIQUE_SHORTHANDS; do
30+
if [[ ${line,,} =~ ^/build-native.*[[:space:]]${item,,}([[:space:]].*)?$ ]]; then
31+
TARGETS_REFERENCED="$TARGETS_REFERENCED$ref_delim$item"
32+
ref_delim=" "
33+
continue
34+
fi
35+
done
36+
done <<< "$PR_COMMENT"
37+
echo "targets_referenced=$TARGETS_REFERENCED" >> $GITHUB_OUTPUT
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env -S bash -eu
2+
. workflow-common.sh
3+
4+
# Now we determine the jobs we actually want to run
5+
IFS=' ' read -a NATIVE_LIBRARY_APPLICABLE_SHORTHANDS_ARRAY <<< "$NATIVE_LIBRARY_APPLICABLE_SHORTHANDS"
6+
IFS=' ' read -a NATIVE_LIBRARY_USER_REFERENCED_SHORTHANDS_ARRAY <<< "$NATIVE_LIBRARY_USER_REFERENCED_SHORTHANDS"
7+
8+
COMMENT="Some of the native library builds modified in this PR were not referenced in the PR description. Please ensure that the PR description contains \`/build-native $NATIVE_LIBRARY_APPLICABLE_SHORTHANDS\`. These libraries won't be rebuilt without this being specified. If you believe this is in error, then please write a comment explaining why and ignore this suggestion. This comment will be automatically updated if rectified."
9+
if [[ ${PR_EXISTING_NOTICE_ID:-0} == 0 ]]; then
10+
PR_EXISTING_NOTICE_ID=""
11+
fi
12+
13+
ANGRY_COMMENT=false
14+
if [ "${#NATIVE_LIBRARY_APPLICABLE_SHORTHANDS_ARRAY[@]}" -gt "${#NATIVE_LIBRARY_USER_REFERENCED_SHORTHANDS_ARRAY[@]}" ]; then
15+
ANGRY_COMMENT=true
16+
else
17+
COMMENT="All native library builds modified in this PR shall attempt to be built by CI."
18+
fi
19+
20+
echo "matrix_strategy<<EOF" >> $GITHUB_OUTPUT
21+
echo "[" >> $GITHUB_OUTPUT
22+
json_open="{"
23+
for item in $NATIVE_LIBRARY_USER_REFERENCED_SHORTHANDS; do
24+
i=0
25+
for target in ${NATIVE_LIBRARY_SHORTHANDS_ARRAY[@]}; do
26+
if [[ "$target" == "$item" ]]; then
27+
shopt -s nullglob
28+
for runtime_script in "../../../${NATIVE_LIBRARY_PATHS_ARRAY[$i]}"/build-*.*; do
29+
runtime="$(basename "$runtime_script")"
30+
runtime="${runtime:6}" # trim build- prefix
31+
runtime="${runtime%.*}" # remove extension
32+
echo "$json_open" >> $GITHUB_OUTPUT
33+
json_open=",{"
34+
echo " \"target\": \"$target\"," >> $GITHUB_OUTPUT
35+
echo " \"runtime\": \"$runtime\"," >> $GITHUB_OUTPUT
36+
# :9 trim ../../../ prefix
37+
echo " \"exec\": \"$(basename "$runtime_script")\"," >> $GITHUB_OUTPUT
38+
echo " \"dir\": \"$(dirname "${runtime_script:9}")\"" >> $GITHUB_OUTPUT
39+
echo "}" >> $GITHUB_OUTPUT
40+
done
41+
fi
42+
i=$(expr $i + 1)
43+
done
44+
done
45+
echo "]" >> $GITHUB_OUTPUT
46+
echo EOF >> $GITHUB_OUTPUT
47+
if [[ $PR_EXISTING_NOTICE_ID != 0 && $PR_EXISTING_NOTICE_ID != "" || $ANGRY_COMMENT == true ]]; then
48+
echo "comment_to_write=$COMMENT" >> $GITHUB_OUTPUT
49+
fi

sources/SDL/Native/build-osx.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#/usr/bin/env -S bash -eu
2+
if [ ! -e ../../../eng/submodules/sdl/CMakeLists.txt ]; then
3+
git submodule update --init --recursive --depth 1 ../../../eng/submodules/sdl
4+
fi
5+
6+
rm -rf build
7+
mkdir build
8+
cd build
9+
cmake ../../../../eng/submodules/sdl "-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" -DCMAKE_OSX_DEPLOYMENT_TARGET=10.11 -DCMAKE_BUILD_TYPE=Release
10+
cmake --build . --parallel
11+
cd ..
12+
mkdir -p runtimes/osx/native
13+
cp build/libSDL3.dylib runtimes/osx/native

0 commit comments

Comments
 (0)