Skip to content

Commit e6cf93e

Browse files
Fix issue with slang-embed & include ordering (shader-slang#5680)
* Fix issue with slang-embed & include ordering * Update CMakeLists.txt
1 parent d282701 commit e6cf93e

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

prelude/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ foreach(input ${prelude_headers})
1111
set(output "${CMAKE_CURRENT_BINARY_DIR}/${input_name}.cpp")
1212
add_custom_command(
1313
OUTPUT ${output}
14-
COMMAND slang-embed "${input}" ${output}
14+
COMMAND
15+
slang-embed "${input}" "${CMAKE_CURRENT_LIST_DIR}/../include"
16+
${output}
1517
DEPENDS ${input} slang-embed
1618
VERBATIM
1719
)

prelude/slang-torch-prelude.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// Prelude for PyTorch cpp binding.
22

3+
// clang-format off
4+
#include <torch/extension.h>
5+
// clang-format on
6+
37
#include <ATen/cuda/CUDAContext.h>
48
#include <ATen/cuda/CUDAUtils.h>
59
#include <stdexcept>
610
#include <string>
7-
#include <torch/extension.h>
811
#include <vector>
912

1013
#ifdef SLANG_LLVM

tools/slang-embed/slang-embed.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct App
6363
{
6464
char const* appName = "slang-embed";
6565
char const* inputPath = nullptr;
66+
char const* includeDir = nullptr;
6667
char const* outputPath = nullptr;
6768
Slang::HashSet<Slang::String> includedFiles;
6869

@@ -83,6 +84,12 @@ struct App
8384
argc--;
8485
}
8586

87+
if (argc > 0)
88+
{
89+
includeDir = *argv++;
90+
argc--;
91+
}
92+
8693
if (argc > 0)
8794
{
8895
outputPath = *argv++;
@@ -91,7 +98,7 @@ struct App
9198

9299
if (!inputPath || (argc != 0))
93100
{
94-
fprintf(stderr, "usage: %s inputPath [outputPath]\n", appName);
101+
fprintf(stderr, "usage: %s inputPath includeDir [outputPath]\n", appName);
95102
exit(1);
96103
}
97104
}
@@ -137,7 +144,13 @@ struct App
137144
auto path =
138145
Slang::Path::combine(Slang::Path::getParentDirectory(inputPath), fileName);
139146
if (!Slang::File::exists(path))
140-
goto normalProcess;
147+
{
148+
// Try looking in the include directory.
149+
path = Slang::Path::combine(includeDir, fileName);
150+
151+
if (!Slang::File::exists(path))
152+
goto normalProcess;
153+
}
141154
processInputFile(outputFile, path.getUnownedSlice());
142155
continue;
143156
}

0 commit comments

Comments
 (0)