shader-slang / slang

Making it easier to work with shaders
MIT License
1.78k stars 158 forks source link

cmake build does not build examples #4383

Open kaizhangNV opened 1 week ago

kaizhangNV commented 1 week ago

Our cmake build seems still unfinished for building examples. Even though there are flags to enable them

option(SLANG_ENABLE_GFX "Enable gfx targets" ON)
option(SLANG_ENABLE_EXAMPLES "Enable example targets, requires SLANG_ENABLE_GFX" ON)

it still doesn't build the examples.

We need to enable the examples build to make it a default in our CI.

chaoticbob commented 1 week ago

Is this just using the cmake commands to build or when using project generation?

kaizhangNV commented 1 week ago

What do you mean by when using project generation? ?

kaizhangNV commented 1 week ago
            cmake --preset default --fresh \
              -DSLANG_SLANG_LLVM_FLAVOR=FETCH_BINARY \
              -DSLANG_SLANG_LLVM_BINARY_URL=$(pwd)/build/dist-release/slang-slang-llvm.zip \
              -DCMAKE_COMPILE_WARNING_AS_ERROR=${{matrix.warnings-as-errors}}

this is for the project generation

cmake --workflow --preset "${{matrix.config}}"

this is for the project build.

If you're asking about why the examples are not built, I think it's the project generation. Because I noticed that the examples directory under build folder is always empty.

jkwak-work commented 17 hours ago

@venkataram-nv told me that the current CMake setting is to skip the examples by default. It seems that there are some unexpected behavior based on how you build.

Makefile build system doesn't build the examples by default. You can build examples with the following command.

make all-examples

Visual Studio, however, builds examples when the solution is generated by the following command and you "build solution (F7)" in the Visual Studio IDE.

cmake.exe --preset vs2019

Interestingly, if you use cmake to build with the visual studio solution, it doesn't build the examples,

cmake.exe --preset vs2019
cmake.exe --build --preset release    # <== DOESN'T BUILD EXAMPLES.

What I like to propose is that we should build the example by default on all build system including Makefile/Ninja/VisualStudio/Whatever. Our current CMake setting already has a way to skip the examples.

cmake.exe --preset vs2019 -DSLANG_ENABLE_EXAMPLES=OFF

This excludes the examples from the generated Visual Studio solution file entirely. In this case, even when you hit "F7" in the Visual Studio IDE, it wouldn't build the examples.

Once we make the change, we should make sure some of CI tests doesn't waste building the examples when they are not used. Note that at least one CI test per platform should build the examples to prevent any regressions.