Skip to content

Commit

Permalink
Fix issue with slang-embed & include ordering (shader-slang#5680)
Browse files Browse the repository at this point in the history
* Fix issue with slang-embed & include ordering

* Update CMakeLists.txt
  • Loading branch information
saipraveenb25 authored Nov 26, 2024
1 parent d282701 commit e6cf93e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 3 additions & 1 deletion prelude/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ foreach(input ${prelude_headers})
set(output "${CMAKE_CURRENT_BINARY_DIR}/${input_name}.cpp")
add_custom_command(
OUTPUT ${output}
COMMAND slang-embed "${input}" ${output}
COMMAND
slang-embed "${input}" "${CMAKE_CURRENT_LIST_DIR}/../include"
${output}
DEPENDS ${input} slang-embed
VERBATIM
)
Expand Down
5 changes: 4 additions & 1 deletion prelude/slang-torch-prelude.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Prelude for PyTorch cpp binding.

// clang-format off
#include <torch/extension.h>
// clang-format on

#include <ATen/cuda/CUDAContext.h>
#include <ATen/cuda/CUDAUtils.h>
#include <stdexcept>
#include <string>
#include <torch/extension.h>
#include <vector>

#ifdef SLANG_LLVM
Expand Down
17 changes: 15 additions & 2 deletions tools/slang-embed/slang-embed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct App
{
char const* appName = "slang-embed";
char const* inputPath = nullptr;
char const* includeDir = nullptr;
char const* outputPath = nullptr;
Slang::HashSet<Slang::String> includedFiles;

Expand All @@ -83,6 +84,12 @@ struct App
argc--;
}

if (argc > 0)
{
includeDir = *argv++;
argc--;
}

if (argc > 0)
{
outputPath = *argv++;
Expand All @@ -91,7 +98,7 @@ struct App

if (!inputPath || (argc != 0))
{
fprintf(stderr, "usage: %s inputPath [outputPath]\n", appName);
fprintf(stderr, "usage: %s inputPath includeDir [outputPath]\n", appName);
exit(1);
}
}
Expand Down Expand Up @@ -137,7 +144,13 @@ struct App
auto path =
Slang::Path::combine(Slang::Path::getParentDirectory(inputPath), fileName);
if (!Slang::File::exists(path))
goto normalProcess;
{
// Try looking in the include directory.
path = Slang::Path::combine(includeDir, fileName);

if (!Slang::File::exists(path))
goto normalProcess;
}
processInputFile(outputFile, path.getUnownedSlice());
continue;
}
Expand Down

0 comments on commit e6cf93e

Please sign in to comment.