yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
fe87a39e4
master
Building Slang From Source
TLDR
cmake --workflow --preset release to configure, build, and package a release
version of Slang.
Prerequisites:
Please install:
- CMake (3.26 preferred, but 3.22 works[^1])
- A C++ compiler with support for C++17. GCC, Clang and MSVC are supported
- A CMake compatible backend, for example Visual Studio or Ninja
- Python3 (a dependency for building spirv-tools)
Optional dependencies for tests include
- CUDA
- OptiX
- NVAPI
- Aftermath
- X11
Other dependencies are sourced from submodules in the ./external directory.
Get the Source Code
Clone this repository. Make sure to fetch the submodules also.
git clone https://github.com/shader-slang/slang--recursive
Configure and build
This section assumes cmake 3.25 or greater, if you're on a lower version please see building with an older cmake
For a Ninja based build system (all platforms) run:
cmake --preset defaultcmake --build --preset releaseWithDebugInfo# or --preset debug, or --preset release
For Visual Studio run:
cmake --preset vs2022# or 'vs2019' or `vs2022-dev` start devenv ./build/slang.sln# to optionally open the project in Visual Studio cmake --build --preset releaseWithDebugInfo# to build from the CLI, could also use --preset release or --preset debug
There also exists a vs2022-dev preset which turns on features to aid
debugging.
WebAssembly build
In order to build WebAssembly build of Slang, Slang needs to be compiled with Emscripten SDK. You can find more information about Emscripten.
You need to clone the EMSDK repo. And you need to install and activate the latest.
git clone https://github.com/emscripten-core/emsdk.gitcd emsdk
For non-Windows platforms
./emsdk install latest./emsdk activate latest
For Windows
emsdk .bat install latest emsdk .bat activate latest
After EMSDK is activated, Slang needs to be built in a cross compiling setup:
- build the
generatorstarget for the build platform - configure the build with
emcmakefor the host platform - build for the host platform.
Note: For more details on cross compiling please refer to the cross-compiling section.
# Build generators. cmake --workflow --preset generators--fresh mkdir generatorscmake --install build--prefix generators--component generators# Configure the build with emcmake. # emcmake is available only when emsdk_env setup the environment correctly. pushd ../emsdksource ./emsdk_env# For Windows, emsdk_env.bat popd emcmake cmake-DSLANG_GENERATORS_PATH=generators/bin --preset emscripten-G "Ninja" # Build slang-wasm.js and slang-wasm.wasm in build.em/Release/bin cmake --build --preset emscripten--target slang-wasm
Note: If the last build step fails, try running the command that
emcmakeoutputs, directly.
Installing
Build targets may be installed using cmake:
cmake --build .--target install
This should install SlangConfig.cmake that should allow find_package to work.
SlangConfig.cmake defines SLANG_EXECUTABLE variable that will point to slangc
executable and also define slang::slang target to be linked to.
For now, slang::slang is the only exported target defined in the config which can
be linked to.
Example usage
find_package ( slang REQUIRED PATHS $ { your_cmake_install_prefix_path } NO_DEFAULT_PATH ) # slang_FOUND should be automatically set target_link_libraries ( yourLib PUBLIC slang::slang )
Testing
build/Debug/bin/slang-test
See the documentation on testing for more information.
Debugging
See the documentation on debugging.
More niche topics
CMake options
| Option | Default | Description |
|---|---|---|
SLANG_VERSION | Latest v* tag | The project version, detected using git if available |
SLANG_EMBED_CORE_MODULE | TRUE | Build slang with an embedded version of the core module |
SLANG_EMBED_CORE_MODULE_SOURCE | TRUE | Embed the core module source in the binary |
SLANG_ENABLE_DXIL | TRUE | Enable generating DXIL using DXC |
SLANG_ENABLE_ASAN | FALSE | Enable ASAN (address sanitizer) |
SLANG_ENABLE_FULL_IR_VALIDATION | FALSE | Enable full IR validation (SLOW!) |
SLANG_ENABLE_IR_BREAK_ALLOC | FALSE | Enable IR BreakAlloc functionality for debugging. |
SLANG_ENABLE_GFX | TRUE | Enable gfx targets |
SLANG_ENABLE_SLANGD | TRUE | Enable language server target |
SLANG_ENABLE_SLANGC | TRUE | Enable standalone compiler target |
SLANG_ENABLE_SLANGI | TRUE | Enable Slang interpreter target |
SLANG_ENABLE_SLANGRT | TRUE | Enable runtime target |
SLANG_ENABLE_SLANG_GLSLANG | TRUE | Enable glslang dependency and slang-glslang wrapper target |
SLANG_ENABLE_TESTS | TRUE | Enable test targets, requires SLANG_ENABLE_GFX, SLANG_ENABLE_SLANGD and SLANG_ENABLE_SLANGRT |
SLANG_ENABLE_EXAMPLES | TRUE | Enable example targets, requires SLANG_ENABLE_GFX |
SLANG_LIB_TYPE | SHARED | How to build the slang library |
SLANG_ENABLE_RELEASE_DEBUG_INFO | TRUE | Enable generating debug info for Release configs |
SLANG_ENABLE_RELEASE_LTO | FALSE | Enable LTO for Release builds |
SLANG_ENABLE_SPLIT_DEBUG_INFO | TRUE | Enable generating split debug info for Debug and RelWithDebInfo configs |
SLANG_SLANG_LLVM_FLAVOR | FETCH_BINARY_IF_POSSIBLE | How to set up llvm support |
SLANG_SLANG_LLVM_BINARY_URL | System dependent | URL specifying the location of the slang-llvm prebuilt library |
SLANG_GENERATORS_PATH | `` | Path to an installed all-generators target for cross compilation |
The following options relate to optional dependencies for additional backends
and running additional tests. Left unchanged they are auto detected, however
they can be set to OFF to prevent their usage, or set to ON to make it an
error if they can't be found.
| Option | CMake hints | Notes |
|---|---|---|
SLANG_ENABLE_CUDA | CUDAToolkit_ROOT CUDA_PATH | Enable running tests with the CUDA backend, doesn't affect the targets Slang itself supports |
SLANG_ENABLE_OPTIX | Optix_ROOT_DIR | Requires CUDA |
SLANG_ENABLE_NVAPI | NVAPI_ROOT_DIR | Only available for builds targeting Windows |
SLANG_ENABLE_AFTERMATH | Aftermath_ROOT_DIR | Enable Aftermath in GFX, and add aftermath crash example to project |
SLANG_ENABLE_XLIB |
Advanced options
| Option | Default | Description |
|---|---|---|
SLANG_ENABLE_DX_ON_VK | FALSE | Enable running the DX11 and DX12 tests on non-warning Windows platforms via vkd3d-proton, requires system-provided d3d headers |
SLANG_ENABLE_SLANG_RHI | TRUE | Enable building and using slang-rhi for tests |
SLANG_USE_SYSTEM_MINIZ | FALSE | Build using system Miniz library instead of the bundled version in ./external |
SLANG_USE_SYSTEM_LZ4 | FALSE | Build using system LZ4 library instead of the bundled version in ./external |
SLANG_USE_SYSTEM_VULKAN_HEADERS | FALSE | Build using system Vulkan headers instead of the bundled version in ./external |
SLANG_USE_SYSTEM_SPIRV_HEADERS | FALSE | Build using system SPIR-V headers instead of the bundled version in ./external |
SLANG_USE_SYSTEM_UNORDERED_DENSE | FALSE | Build using system unordered dense instead of the bundled version in ./external |
SLANG_SPIRV_HEADERS_INCLUDE_DIR | `` | Use this specific path to SPIR-V headers instead of the bundled version in ./external |
LLVM Support
There are several options for getting llvm-support:
- Use a prebuilt binary slang-llvm library:
-DSLANG_SLANG_LLVM_FLAVOR=FETCH_BINARYor-DSLANG_SLANG_LLVM_FLAVOR=FETCH_BINARY_IF_POSSIBLE(this is the default)- You can set
SLANG_SLANG_LLVM_BINARY_URLto point to a locallibslang-llvm.so/slang-llvm.dllor set it to a URL of an zip/archive containing such a file - If this isn't set then the build system tries to download it from the release on github matching the current tag. If such a tag doesn't exist or doesn't have the correct os*arch combination then the latest release will be tried.
- If
SLANG_SLANG_LLVM_BINARY_URLisFETCH_BINARY_IF_POSSIBLEthen in the case that a prebuilt binary can't be found then the build will proceed as thoughDISABLEwas chosen
- You can set
- Use a system supplied LLVM:
-DSLANG_SLANG_LLVM_FLAVOR=USE_SYSTEM_LLVM, you must have llvm-14.0 and a matching libclang installed. It's important that either:- You don't end up linking to a dynamic libllvm.so, this will almost
certainly cause multiple versions of LLVM to be loaded at runtime,
leading to errors like
opt: CommandLine Error: Option 'asm-macro-max-nesting-depth' registered more than once!. Avoid this by compiling LLVM without the dynamic library. - Anything else which may be linked in (for example Mesa, also dynamically loads the same llvm object)
- You don't end up linking to a dynamic libllvm.so, this will almost
certainly cause multiple versions of LLVM to be loaded at runtime,
leading to errors like
- Do not enable LLVM support:
-DSLANG_SLANG_LLVM_FLAVOR=DISABLE
To build only a standalone slang-llvm, you can run:
cmake --workflow --preset slang-llvm
This will generate build/dist-release/slang-slang-llvm.zip containing the
library. This, of course, uses the system LLVM to build slang-llvm, otherwise
it would just be a convoluted way to download a prebuilt binary.
Cross compiling
Slang generates some code at build time, using generators build from this
codebase. Due to this, for cross compilation one must already have built these
generators for the build platform. Build them with the generators preset, and
pass the install path to the cross building CMake invocation using
SLANG_GENERATORS_PATH
Non-Windows platforms:
# build the generators cmake --workflow --preset generators--fresh mkdir build-platform-generatorscmake --install build--config Release--prefix build-platform-generators--component generators# reconfigure, pointing to these generators # Here is also where you should set up any cross compiling environment cmake \--preset default \--fresh \-DSLANG_GENERATORS_PATH=build-platform-generators/bin \-Dwhatever-other-necessary-options-for-your-cross-build \# for example \ -DCMAKE_C_COMPILER =my-arch-gcc \-DCMAKE_CXX_COMPILER =my-arch-g++ # perform the final build cmake --workflow --preset release
Windows
# build the generators cmake --workflow --preset generators--fresh mkdir build-platform-generatorscmake --install build--config Release--prefix build-platform-generators--component generators# reconfigure, pointing to these generators # Here is also where you should set up any cross compiling environment # For example ./vcvarsamd64_arm64.bat cmake \--preset default \--fresh \-DSLANG_GENERATORS_PATH=build-platform-generators/bin \-Dwhatever-other-necessary-options-for-your-cross-build # perform the final build cmake --workflow --preset release
Example cross compiling with MSVC to windows-aarch64
One option is to build using the ninja generator, which requires providing the
native and cross environments via vcvarsall.bat
vcvarsall.bat cmake --workflow --preset generators--fresh mkdir generatorscmake --install build--prefix generators--component generatorsvsvarsall.bat x64_arm64cmake --preset default--fresh -DSLANG_GENERATORS_PATH=generators/bin cmake --workflow --preset release
Another option is to build using the Visual Studio generator which can find this automatically
cmake --preset vs2022 # or --preset vs2019 cmake --build --preset generators # to build from the CLI cmake --install build --prefix generators --component generators rm -rf build # The Visual Studio generator will complain if this is left over from a previous build cmake --preset vs2022 --fresh -A arm64 -DSLANG_GENERATORS_PATH=generators/bin cmake --build --preset release
Nix
This repository contains a Nix flake (not officially supported or tested), which provides the necessary prerequisites for local development. Also, if you use direnv, you can run the following commands to have the Nix environment automatically activate when you enter your clone of this repository:
echo 'use flake' > .envrcdirenv allow
Building with an older CMake
Because older CMake versions don't support all the features we want to use in CMakePresets, you'll have to do without the presets. Something like the following
cmake -B build-G Ninjacmake --build build-j
Specific supported compiler versions
<!--- Please keep the exact formatting '_Foo_ xx.yy is tested in CI' as there is a script which checks that this is still up to date. -->GCC 11.4 and 13.3 are tested in CI and is the recommended minimum version. GCC 10 is supported on a best-effort basis, i.e. PRs supporting this version are encouraged but it isn't a continuously maintained setup.
MSVC 19 is tested in CI and is the recommended minimum version.
Clang 17.0 is tested in CI and is the recommended minimum version.
Static linking against libslang
If linking against a static libslang.a you will need to link against some
dependencies also if you're not already incorporating them into your project.
You will need to link against:
${SLANG_DIR}/build/Release/lib/libslang.a
${SLANG_DIR}/build/Release/lib/libcompiler-core.a
${SLANG_DIR}/build/Release/lib/libcore.a
${SLANG_DIR}/build/external/miniz/libminiz.a
${SLANG_DIR}/build/external/lz4/build/cmake/liblz4.a
Notes
[^1] below 3.25, CMake lacks the ability to mark directories as being
system directories (https://cmake.org/cmake/help/latest/prop_tgt/SYSTEM.html#prop_tgt:SYSTEM),
this leads to an inability to suppress warnings originating in the
dependencies in ./external, so be prepared for some additional warnings.
1# Building Slang From Source 2 3### TLDR 4 5`cmake --workflow --preset release` to configure, build, and package a release 6version of Slang. 7 8## Prerequisites: 9 10Please install: 11 12- CMake (3.26 preferred, but 3.22 works[^1]) 13- A C++ compiler with support for C++17. GCC, Clang and MSVC are supported 14- A CMake compatible backend, for example Visual Studio or Ninja 15- Python3 (a dependency for building spirv-tools) 16 17Optional dependencies for tests include 18 19- CUDA 20- OptiX 21- NVAPI 22- Aftermath 23- X11 24 25Other dependencies are sourced from submodules in the [./external](./external) 26directory. 27 28## Get the Source Code 29 30Clone [this](https://github.com/shader-slang/slang) repository. Make sure to 31fetch the submodules also. 32 33``` bash 34git clone https://github.com/shader-slang/slang --recursive 35``` 36 37## Configure and build 38 39> This section assumes cmake 3.25 or greater, if you're on a lower version 40> please see [building with an older cmake](#building-with-an-older-cmake) 41 42For a Ninja based build system (all platforms) run: 43``` bash 44cmake --preset default 45cmake --build --preset releaseWithDebugInfo # or --preset debug, or --preset release 46``` 47 48For Visual Studio run: 49``` bash 50cmake --preset vs2022 # or 'vs2019' or `vs2022-dev` 51start devenv ./build/slang.sln # to optionally open the project in Visual Studio 52cmake --build --preset releaseWithDebugInfo # to build from the CLI, could also use --preset release or --preset debug 53``` 54 55There also exists a `vs2022-dev` preset which turns on features to aid 56debugging. 57 58### WebAssembly build 59 60In order to build WebAssembly build of Slang, Slang needs to be compiled with 61[Emscripten SDK](https://github.com/emscripten-core/emsdk). You can find more 62information about [Emscripten](https://emscripten.org/). 63 64You need to clone the EMSDK repo. And you need to install and activate the latest. 65 66 67``` bash 68git clone https://github.com/emscripten-core/emsdk.git 69cd emsdk 70``` 71 72For non-Windows platforms 73``` bash 74./emsdk install latest 75./emsdk activate latest 76``` 77 78For Windows 79``` cmd 80emsdk.bat install latest 81emsdk.bat activate latest 82``` 83 84After EMSDK is activated, Slang needs to be built in a cross compiling setup: 85 86- build the `generators` target for the build platform 87- configure the build with `emcmake` for the host platform 88- build for the host platform. 89 90> Note: For more details on cross compiling please refer to the 91> [cross-compiling](docs/building.md#cross-compiling) section. 92 93``` bash 94# Build generators. 95cmake --workflow --preset generators --fresh 96mkdir generators 97cmake --install build --prefix generators --component generators 98 99# Configure the build with emcmake. 100# emcmake is available only when emsdk_env setup the environment correctly. 101pushd ../emsdk 102source ./emsdk_env # For Windows, emsdk_env.bat 103popd 104emcmake cmake -DSLANG_GENERATORS_PATH=generators/bin --preset emscripten -G "Ninja" 105 106# Build slang-wasm.js and slang-wasm.wasm in build.em/Release/bin 107cmake --build --preset emscripten --target slang-wasm 108``` 109 110> Note: If the last build step fails, try running the command that `emcmake` 111> outputs, directly. 112 113## Installing 114 115Build targets may be installed using cmake: 116 117``` bash 118cmake --build . --target install 119``` 120 121This should install `SlangConfig.cmake` that should allow `find_package` to work. 122SlangConfig.cmake defines `SLANG_EXECUTABLE` variable that will point to `slangc` 123executable and also define `slang::slang` target to be linked to. 124 125For now, `slang::slang` is the only exported target defined in the config which can 126be linked to. 127 128Example usage 129 130``` cmake 131find_package( slang REQUIRED PATHS ${ your_cmake_install_prefix_path } NO_DEFAULT_PATH ) 132# slang_FOUND should be automatically set 133target_link_libraries( yourLib PUBLIC 134slang::slang 135) 136``` 137 138## Testing 139 140``` bash 141build/Debug/bin/slang-test 142``` 143 144See the [documentation on testing](../tools/slang-test/README.md) for more information. 145 146## Debugging 147 148See the [documentation on debugging](/docs/debugging.md). 149 150## More niche topics 151 152### CMake options 153 154| Option | Default | Description | 155|-----------------------------------|----------------------------|----------------------------------------------------------------------------------------------| 156| `SLANG_VERSION` | Latest `v*` tag | The project version, detected using git if available | 157| `SLANG_EMBED_CORE_MODULE` | `TRUE` | Build slang with an embedded version of the core module | 158| `SLANG_EMBED_CORE_MODULE_SOURCE` | `TRUE` | Embed the core module source in the binary | 159| `SLANG_ENABLE_DXIL` | `TRUE` | Enable generating DXIL using DXC | 160| `SLANG_ENABLE_ASAN` | `FALSE` | Enable ASAN (address sanitizer) | 161| `SLANG_ENABLE_FULL_IR_VALIDATION` | `FALSE` | Enable full IR validation (SLOW!) | 162| `SLANG_ENABLE_IR_BREAK_ALLOC` | `FALSE` | Enable IR BreakAlloc functionality for debugging. | 163| `SLANG_ENABLE_GFX` | `TRUE` | Enable gfx targets | 164| `SLANG_ENABLE_SLANGD` | `TRUE` | Enable language server target | 165| `SLANG_ENABLE_SLANGC` | `TRUE` | Enable standalone compiler target | 166| `SLANG_ENABLE_SLANGI` | `TRUE` | Enable Slang interpreter target | 167| `SLANG_ENABLE_SLANGRT` | `TRUE` | Enable runtime target | 168| `SLANG_ENABLE_SLANG_GLSLANG` | `TRUE` | Enable glslang dependency and slang-glslang wrapper target | 169| `SLANG_ENABLE_TESTS` | `TRUE` | Enable test targets, requires SLANG_ENABLE_GFX, SLANG_ENABLE_SLANGD and SLANG_ENABLE_SLANGRT | 170| `SLANG_ENABLE_EXAMPLES` | `TRUE` | Enable example targets, requires SLANG_ENABLE_GFX | 171| `SLANG_LIB_TYPE` | `SHARED` | How to build the slang library | 172| `SLANG_ENABLE_RELEASE_DEBUG_INFO` | `TRUE` | Enable generating debug info for Release configs | 173| `SLANG_ENABLE_RELEASE_LTO` | `FALSE` | Enable LTO for Release builds | 174| `SLANG_ENABLE_SPLIT_DEBUG_INFO` | `TRUE` | Enable generating split debug info for Debug and RelWithDebInfo configs | 175| `SLANG_SLANG_LLVM_FLAVOR` | `FETCH_BINARY_IF_POSSIBLE` | How to set up llvm support | 176| `SLANG_SLANG_LLVM_BINARY_URL` | System dependent | URL specifying the location of the slang-llvm prebuilt library | 177| `SLANG_GENERATORS_PATH` | `` | Path to an installed `all-generators` target for cross compilation | 178 179The following options relate to optional dependencies for additional backends 180and running additional tests. Left unchanged they are auto detected, however 181they can be set to `OFF` to prevent their usage, or set to `ON` to make it an 182error if they can't be found. 183 184| Option | CMake hints | Notes | 185|--------------------------|--------------------------------|----------------------------------------------------------------------------------------------| 186| `SLANG_ENABLE_CUDA` | `CUDAToolkit_ROOT` `CUDA_PATH` | Enable running tests with the CUDA backend, doesn't affect the targets Slang itself supports | 187| `SLANG_ENABLE_OPTIX` | `Optix_ROOT_DIR` | Requires CUDA | 188| `SLANG_ENABLE_NVAPI` | `NVAPI_ROOT_DIR` | Only available for builds targeting Windows | 189| `SLANG_ENABLE_AFTERMATH` | `Aftermath_ROOT_DIR` | Enable Aftermath in GFX, and add aftermath crash example to project | 190| `SLANG_ENABLE_XLIB` | | | 191 192### Advanced options 193 194| Option | Default | Description | 195|------------------------------------|---------|--------------------------------------------------------------------------------------------------------------------------------| 196| `SLANG_ENABLE_DX_ON_VK` | `FALSE` | Enable running the DX11 and DX12 tests on non-warning Windows platforms via vkd3d-proton, requires system-provided d3d headers | 197| `SLANG_ENABLE_SLANG_RHI` | `TRUE` | Enable building and using [slang-rhi](https://github.com/shader-slang/slang-rhi) for tests | 198| `SLANG_USE_SYSTEM_MINIZ` | `FALSE` | Build using system Miniz library instead of the bundled version in [./external](./external) | 199| `SLANG_USE_SYSTEM_LZ4` | `FALSE` | Build using system LZ4 library instead of the bundled version in [./external](./external) | 200| `SLANG_USE_SYSTEM_VULKAN_HEADERS` | `FALSE` | Build using system Vulkan headers instead of the bundled version in [./external](./external) | 201| `SLANG_USE_SYSTEM_SPIRV_HEADERS` | `FALSE` | Build using system SPIR-V headers instead of the bundled version in [./external](./external) | 202| `SLANG_USE_SYSTEM_UNORDERED_DENSE` | `FALSE` | Build using system unordered dense instead of the bundled version in [./external](./external) | 203| `SLANG_SPIRV_HEADERS_INCLUDE_DIR` | `` | Use this specific path to SPIR-V headers instead of the bundled version in [./external](./external) | 204 205### LLVM Support 206 207There are several options for getting llvm-support: 208 209- Use a prebuilt binary slang-llvm library: 210`-DSLANG_SLANG_LLVM_FLAVOR=FETCH_BINARY` or `-DSLANG_SLANG_LLVM_FLAVOR=FETCH_BINARY_IF_POSSIBLE` (this is the default) 211- You can set `SLANG_SLANG_LLVM_BINARY_URL` to point to a local 212`libslang-llvm.so/slang-llvm.dll` or set it to a URL of an zip/archive 213containing such a file 214- If this isn't set then the build system tries to download it from the 215release on github matching the current tag. If such a tag doesn't exist 216or doesn't have the correct os*arch combination then the latest release 217will be tried. 218- If `SLANG_SLANG_LLVM_BINARY_URL` is `FETCH_BINARY_IF_POSSIBLE` then in 219the case that a prebuilt binary can't be found then the build will proceed 220as though `DISABLE` was chosen 221- Use a system supplied LLVM: `-DSLANG_SLANG_LLVM_FLAVOR=USE_SYSTEM_LLVM`, you 222must have llvm-14.0 and a matching libclang installed. It's important that 223either: 224- You don't end up linking to a dynamic libllvm.so, this will almost 225certainly cause multiple versions of LLVM to be loaded at runtime, 226leading to errors like `opt: CommandLine Error: Option 227'asm-macro-max-nesting-depth' registered more than once!`. Avoid this by 228compiling LLVM without the dynamic library. 229- Anything else which may be linked in (for example Mesa, also dynamically 230loads the same llvm object) 231- Do not enable LLVM support: `-DSLANG_SLANG_LLVM_FLAVOR=DISABLE` 232 233To build only a standalone slang-llvm, you can run: 234 235``` bash 236cmake --workflow --preset slang-llvm 237``` 238 239This will generate `build/dist-release/slang-slang-llvm.zip` containing the 240library. This, of course, uses the system LLVM to build slang-llvm, otherwise 241it would just be a convoluted way to download a prebuilt binary. 242 243### Cross compiling 244 245Slang generates some code at build time, using generators build from this 246codebase. Due to this, for cross compilation one must already have built these 247generators for the build platform. Build them with the `generators` preset, and 248pass the install path to the cross building CMake invocation using 249`SLANG_GENERATORS_PATH` 250 251Non-Windows platforms: 252 253``` bash 254# build the generators 255cmake --workflow --preset generators --fresh 256mkdir build-platform-generators 257cmake --install build --config Release --prefix build-platform-generators --component generators 258# reconfigure, pointing to these generators 259# Here is also where you should set up any cross compiling environment 260cmake \ 261--preset default \ 262--fresh \ 263-DSLANG_GENERATORS_PATH=build-platform-generators/bin \ 264-Dwhatever-other-necessary-options-for-your-cross-build \ 265# for example \ 266-DCMAKE_C_COMPILER =my-arch-gcc \ 267-DCMAKE_CXX_COMPILER =my-arch-g++ 268# perform the final build 269cmake --workflow --preset release 270``` 271 272Windows 273 274``` bash 275# build the generators 276cmake --workflow --preset generators --fresh 277mkdir build-platform-generators 278cmake --install build --config Release --prefix build-platform-generators --component generators 279# reconfigure, pointing to these generators 280# Here is also where you should set up any cross compiling environment 281# For example 282./vcvarsamd64_arm64.bat 283cmake \ 284--preset default \ 285--fresh \ 286-DSLANG_GENERATORS_PATH=build-platform-generators/bin \ 287-Dwhatever-other-necessary-options-for-your-cross-build 288# perform the final build 289cmake --workflow --preset release 290``` 291 292### Example cross compiling with MSVC to windows-aarch64 293 294One option is to build using the ninja generator, which requires providing the 295native and cross environments via `vcvarsall.bat` 296 297``` bash 298vcvarsall.bat 299cmake --workflow --preset generators --fresh 300mkdir generators 301cmake --install build --prefix generators --component generators 302vsvarsall.bat x64_arm64 303cmake --preset default --fresh -DSLANG_GENERATORS_PATH=generators/bin 304cmake --workflow --preset release 305``` 306 307Another option is to build using the Visual Studio generator which can find 308this automatically 309 310``` 311cmake --preset vs2022 # or --preset vs2019 312cmake --build --preset generators # to build from the CLI 313cmake --install build --prefix generators --component generators 314rm -rf build # The Visual Studio generator will complain if this is left over from a previous build 315cmake --preset vs2022 --fresh -A arm64 -DSLANG_GENERATORS_PATH=generators/bin 316cmake --build --preset release 317``` 318 319### Nix 320 321This repository contains a [Nix](https://nixos.org/) 322[flake](https://wiki.nixos.org/wiki/Flakes) (not officially supported or 323tested), which provides the necessary prerequisites for local development. Also, 324if you use [direnv](https://direnv.net/), you can run the following commands to 325have the Nix environment automatically activate when you enter your clone of 326this repository: 327 328``` bash 329echo 'use flake' > .envrc 330direnv allow 331``` 332 333## Building with an older CMake 334 335Because older CMake versions don't support all the features we want to use in 336CMakePresets, you'll have to do without the presets. Something like the following 337 338``` bash 339cmake -B build -G Ninja 340cmake --build build -j 341``` 342 343## Specific supported compiler versions 344 345<!--- 346Please keep the exact formatting '_Foo_ xx.yy is tested in CI' as there is a 347script which checks that this is still up to date. 348--> 349 350_GCC_ 11.4 and 13.3 are tested in CI and is the recommended minimum version. GCC 10 is 351supported on a best-effort basis, i.e. PRs supporting this version are 352encouraged but it isn't a continuously maintained setup. 353 354_MSVC_ 19 is tested in CI and is the recommended minimum version. 355 356_Clang_ 17.0 is tested in CI and is the recommended minimum version. 357 358## Static linking against libslang 359 360If linking against a static `libslang.a` you will need to link against some 361dependencies also if you're not already incorporating them into your project. 362 363You will need to link against: 364 365``` 366${SLANG_DIR}/build/Release/lib/libslang.a 367${SLANG_DIR}/build/Release/lib/libcompiler-core.a 368${SLANG_DIR}/build/Release/lib/libcore.a 369${SLANG_DIR}/build/external/miniz/libminiz.a 370${SLANG_DIR}/build/external/lz4/build/cmake/liblz4.a 371``` 372 373## Notes 374 375[^1] below 3.25, CMake lacks the ability to mark directories as being 376system directories (https://cmake.org/cmake/help/latest/prop_tgt/SYSTEM.html#prop_tgt:SYSTEM), 377this leads to an inability to suppress warnings originating in the 378dependencies in `./external`, so be prepared for some additional warnings.