Skip to content

bottlenoselabs.SDL.ShaderCross.Native: the SDL_shadercross library for apps - #32

Merged
lithiumtoast merged 2 commits into
mainfrom
shadercross-native-package
Dec 1, 2026
Merged

lithiumtoast merged 2 commits into
mainfrom
shadercross-native-package

Conversation

@lithiumtoast

Copy link
Copy Markdown
Member

A native package for SDL_shadercross, as SDL.Native is for SDL, for .NET apps that compile shaders while they run, such as editors or modding tools. Load it with [LibraryImport("SDL3_shadercross")]. C# bindings could come later, generated like SDL's.

This doesn't make Assetyard smaller: a .NET tool package can't have package dependencies, so a tool always carries what it needs. Assetyard keeps its per-platform packages, 11–27 MB each.

The package

  • Contents: runtimes/<rid>/native/ holds SDL3_shadercross, DirectXShaderCompiler (dxcompiler, dxil) and SPIRV-Cross, from lib/shadercross/<platform>/ (Build SDL_shadercross for every platform #27). It leaves out the shadercross tool and SDL.
  • SDL: it depends on bottlenoselabs.SDL.Native for SDL, so an app loads one SDL.
  • Runtime identifiers: the same as SDL.Native's, so both packages' files share a folder in an app's output, and SDL_shadercross finds SDL next to itself (@loader_path / $ORIGIN). A plain runtimes/osx/ didn't work for this.
  • macOS: the universal build is packed for both osx-arm64 and osx-x64. That's about 24 MB extra; it could be thinned per architecture later.
  • Size: about 100 MB with all platforms, which nuget.org allows.
  • License: Zlib AND Apache-2.0 AND NCSA, with the license files in licenses/.
  • Missing platforms: like SDL.Native, it packs whatever platforms are built, and releases set RequireShaderCrossTools to require all of them.

ext/build-shadercross.sh: the libraries now use the names .NET looks for and SDL.Native's name for SDL: libSDL3.dylib and libSDL3_shadercross.dylib (were .0.dylib), and libSDL3.so and libSDL3_shadercross.so (were .so.0). Their load commands, install names and sonames are updated to match. Windows names were already right. The tool folder uses the same files, so the next build needs no extra step. The script changed, so CI rebuilds SDL_shadercross once, including about 40 minutes for macOS.

Tests

  • src/cs/tests/ShaderCrossNative: an app that references the packed package from a local feed, compiles HLSL to SPIR-V through SDL_shadercross's C API, and checks the SPIR-V magic number. It also checks that the process loaded exactly one SDL library, from its own output, using dyld's image list on macOS and /proc/self/maps on Linux.
  • CI: a new job packs SDL.Native and the package with every platform required. It checks each runtime folder has the library and no SDL, that the package depends on SDL.Native, and that the licenses are there, then runs the app on Linux x64.
  • Release: the dry run checks for the package, and the release packs it from main's passing run.

Checked locally on macOS (with the renames applied to the existing macOS build)

  • ext/test-shadercross.sh passes.
  • The test app passes, in a build and as a published osx-arm64 app. One SDL is loaded, SDL.Native's.
  • Assetyard's install test passes, and the solution builds.

…or apps that compile shaders while they run

The libraries from lib/shadercross/<platform>/ (SDL_shadercross, DirectXShaderCompiler, SPIRV-Cross), without the tool or SDL, in runtimes/<rid>/native/ for the same runtime identifiers as bottlenoselabs.SDL.Native, which it depends on. The universal macOS build is packed for osx-arm64 and osx-x64.

ext/build-shadercross.sh now names the libraries as .NET and SDL.Native do (libSDL3.dylib, libSDL3_shadercross.dylib; libSDL3.so, libSDL3_shadercross.so) and relinks them, so SDL_shadercross loads the app's own SDL. CI packs it with every platform, checks it has no SDL and depends on SDL.Native, and runs src/cs/tests/ShaderCrossNative, an app that compiles HLSL to SPIR-V through it and checks it loaded one SDL.
SDL's commit is no longer part of SDL_shadercross's cache key: the tool keeps the SDL it was built with, and apps using bottlenoselabs.SDL.ShaderCross.Native load SDL.Native's newer SDL, which SDL 3's stable binary interface allows. An SDL update no longer costs a 40-minute macOS build of DXC.
@lithiumtoast
lithiumtoast merged commit 496db78 into main Dec 1, 2026
31 checks passed
@lithiumtoast
lithiumtoast deleted the shadercross-native-package branch December 1, 2026 01:07
lithiumtoast added a commit that referenced this pull request Dec 1, 2026
…again for the same inputs (#34)

Actions caches are deleted after 7 days unused, and a branch can only
read its own and the default branch's. So a quiet week, or any change to
a cache's key, means building SDL_shadercross again: about 40 minutes on
a scarce macOS runner. This keeps every finished native build where it
doesn't expire.

**The store**
- `ext/native-store.sh` keeps each platform's finished build of SDL or
SDL_shadercross as a `.tar.gz` asset of one pre-release,
`native-builds`, named after a hash of its inputs: for example
`shadercross-native-osx-<hash>.tar.gz`.
- Release assets don't expire, and every branch can read them. A
`.tar.gz` also keeps the tool's executable permission.
- The script creates the release the first time it uploads. It's marked
as a pre-release and says it isn't a release of this repository.

**The workflows**
- `sdl-native.yml` and `shadercross-native.yml` look for each platform
in the store first, then in an Actions cache, and only then build it.
- **Writing:** runs on the default branch put builds into the store,
including ones they found only in a cache, so existing caches move into
the store without building again. Pull requests only read the store, so
code that wasn't reviewed never puts binaries there.
- **SDL** now builds and caches each platform on its own, like
SDL_shadercross. It reads its old combined cache (`sdl-native-all-...`)
once more, so the store gets SDL without building it again. That part
can go once the store has this SDL commit.
- **Permissions:** `main.yml` gives both native workflows `contents:
write`, for the store, and `actions: read`, to list caches.

**Checked**
- **`ext/native-store.sh`:** `asset-name`, `has` against the real
repository (no release yet) and an unknown command. `upload` and
`download` first run on `main`, since pull requests don't write.
- **Both lookup steps,** run locally against the real repository: SDL
finds all six platforms in the combined cache, so no SDL builds, macOS
included. SDL_shadercross finds `main`'s new caches, saved by `main`'s
run after #32, which finished before this PR was opened.
- `actionlint`.

**After merging:** `main`'s next run uploads all eleven builds (6 SDL, 5
SDL_shadercross) from the caches into the store. After that, a build
only happens when its inputs change.

**To watch at the next release:** whether GitHub's automatic release
notes compare against the `native-builds` pre-release instead of the
previous version.

Co-authored-by: Lucas Girouard-Stranks <lithiumtoast@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant