Skip to content

Commit

Permalink
Replace stdlib with core-module on files and projects (shader-slang#5411
Browse files Browse the repository at this point in the history
)

This commit renames the files and projects to prefer "core-module" over
"stdlib".

The directory name `source/slang-stdlib` needs to be renamed too, and
there will be another commit for it soon.
  • Loading branch information
jkwak-work authored Oct 25, 2024
1 parent 4bad669 commit d8969d8
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ prelude/*.h.cpp
/docs/Gemfile.lock
/docs/Gemfile
/docs/stdlib-reference
/source/slang/slang-stdlib-generated.h
/source/slang/slang-core-module-generated.h

/examples/heterogeneous-hello-world/shader.cpp
/multiple-definitions.hlsl
Expand Down
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ auto_option(
advanced_option(SLANG_ENABLE_DX_ON_VK "Use dxvk and vkd3d-proton for DirectX support" OFF)
advanced_option(SLANG_ENABLE_SLANG_RHI "Use slang-rhi as dependency" ON)

option(SLANG_EMBED_STDLIB_SOURCE "Embed stdlib source in the binary" ON)
option(SLANG_EMBED_STDLIB "Build slang with an embedded version of the stdlib")
option(SLANG_EMBED_CORE_MODULE_SOURCE "Embed core module source in the binary" ON)
option(SLANG_EMBED_CORE_MODULE "Build slang with an embedded version of the core module")

option(SLANG_ENABLE_FULL_IR_VALIDATION "Enable full IR validation (SLOW!)")
option(SLANG_ENABLE_IR_BREAK_ALLOC, "Enable _debugUID on IR allocation")
Expand Down Expand Up @@ -201,10 +201,10 @@ endif()
# Option validation
#

if(NOT SLANG_EMBED_STDLIB AND NOT SLANG_EMBED_STDLIB_SOURCE)
if(NOT SLANG_EMBED_CORE_MODULE AND NOT SLANG_EMBED_CORE_MODULE_SOURCE)
message(
SEND_ERROR
"One of SLANG_EMBED_STDLIB and SLANG_EMBED_STDLIB_SOURCE must be enabled"
"One of SLANG_EMBED_CORE_MODULE and SLANG_EMBED_CORE_MODULE_SOURCE must be enabled"
)
endif()

Expand Down
4 changes: 2 additions & 2 deletions docs/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ See the [documentation on testing](../tools/slang-test/README.md) for more infor
| Option | Default | Description |
|-----------------------------------|----------------------------|----------------------------------------------------------------------------------------------|
| `SLANG_VERSION` | Latest `v*` tag | The project version, detected using git if available |
| `SLANG_EMBED_STDLIB` | `FALSE` | Build slang with an embedded version of the stdlib |
| `SLANG_EMBED_STDLIB_SOURCE` | `TRUE` | Embed stdlib source in the binary |
| `SLANG_EMBED_CORE_MODULE` | `FALSE` | 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_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. |
Expand Down
90 changes: 45 additions & 45 deletions source/slang-stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
#
# In this file, for stdlib source embed and stdlib embed itself, we define two
# In this file, for core module source embed and core module embed itself, we define two
# targets, one which includes the embed and one which does not, these are
# linked in as needed to libslang and libslang-without-embedded-stdlib (for
# linked in as needed to libslang and libslang-without-embedded-core-module (for
# slang-bootstrap)
#
# If MSVC supported weak linking we could just have a single library for each
# and just not link it if we didn't want the embed...
#

#
# Generate an embeddable stdlib
# Generate an embeddable core module
#

set(stdlib_generated_header_dir ${CMAKE_CURRENT_BINARY_DIR})
set(stdlib_generated_header
${stdlib_generated_header_dir}/slang-stdlib-generated.h
set(core_module_generated_header_dir ${CMAKE_CURRENT_BINARY_DIR})
set(core_module_generated_header
${core_module_generated_header_dir}/slang-core-module-generated.h
)
add_custom_command(
OUTPUT ${stdlib_generated_header}
OUTPUT ${core_module_generated_header}
COMMAND
slang-bootstrap -archive-type riff-lz4 -save-core-module-bin-source
${stdlib_generated_header}
${core_module_generated_header}
DEPENDS slang-bootstrap
VERBATIM
)

set(stdlib_common_args
set(core_module_common_args
.
OBJECT
EXCLUDE_FROM_ALL
Expand All @@ -34,67 +34,67 @@ set(stdlib_common_args
FOLDER generated
LINK_WITH_PRIVATE core
USE_EXTRA_WARNINGS
EXPLICIT_SOURCE ./slang-embedded-stdlib.cpp
EXPLICIT_SOURCE ./slang-embedded-core-module.cpp
)

slang_add_target(
${stdlib_common_args}
TARGET_NAME slang-embedded-stdlib
EXPLICIT_SOURCE ${stdlib_generated_header}
EXTRA_COMPILE_DEFINITIONS_PRIVATE SLANG_EMBED_STDLIB
INCLUDE_DIRECTORIES_PRIVATE ${stdlib_generated_header_dir}
${core_module_common_args}
TARGET_NAME slang-embedded-core-module
EXPLICIT_SOURCE ${core_module_generated_header}
EXTRA_COMPILE_DEFINITIONS_PRIVATE SLANG_EMBED_CORE_MODULE
INCLUDE_DIRECTORIES_PRIVATE ${core_module_generated_header_dir}
)

slang_add_target(
${stdlib_common_args}
TARGET_NAME slang-no-embedded-stdlib
${core_module_common_args}
TARGET_NAME slang-no-embedded-core-module
)

#
# Compiling the meta.slang files
#

# List of *.meta.slang headers
set(stdlib_meta_source_dir "${slang_SOURCE_DIR}/source/slang")
glob_append(stdlib_meta_source "${stdlib_meta_source_dir}/*.meta.slang")
set(core_module_meta_source_dir "${slang_SOURCE_DIR}/source/slang")
glob_append(core_module_meta_source "${core_module_meta_source_dir}/*.meta.slang")

set(stdlib_meta_output_dir "${CMAKE_CURRENT_BINARY_DIR}/stdlib-meta")
set(core_module_meta_output_dir "${CMAKE_CURRENT_BINARY_DIR}/core-module-meta")

# Generate the output file list
set(stdlib_meta_generated_headers)
foreach(meta_source ${stdlib_meta_source})
set(core_module_meta_generated_headers)
foreach(meta_source ${core_module_meta_source})
file(
RELATIVE_PATH
meta_source_relative
"${stdlib_meta_source_dir}"
"${core_module_meta_source_dir}"
${meta_source}
)
list(
APPEND
stdlib_meta_generated_headers
"${stdlib_meta_output_dir}/${meta_source_relative}.h"
core_module_meta_generated_headers
"${core_module_meta_output_dir}/${meta_source_relative}.h"
)
endforeach()

add_custom_command(
OUTPUT ${stdlib_meta_generated_headers}
COMMAND ${CMAKE_COMMAND} -E make_directory ${stdlib_meta_output_dir}
OUTPUT ${core_module_meta_generated_headers}
COMMAND ${CMAKE_COMMAND} -E make_directory ${core_module_meta_output_dir}
COMMAND
slang-generate ${stdlib_meta_source} --target-directory
${stdlib_meta_output_dir}
DEPENDS ${stdlib_meta_source} slang-generate
WORKING_DIRECTORY "${stdlib_meta_source_dir}"
slang-generate ${core_module_meta_source} --target-directory
${core_module_meta_output_dir}
DEPENDS ${core_module_meta_source} slang-generate
WORKING_DIRECTORY "${core_module_meta_source_dir}"
VERBATIM
)

add_custom_target(generate-stdlib-headers DEPENDS ${stdlib_meta_generated_headers})
set_target_properties(generate-stdlib-headers PROPERTIES FOLDER generated)
add_custom_target(generate-core-module-headers DEPENDS ${core_module_meta_generated_headers})
set_target_properties(generate-core-module-headers PROPERTIES FOLDER generated)

#
# Generate embedded stdlib source
# Generate embedded core module source
#

set(stdlib_source_common_args
set(core_module_source_common_args
.
OBJECT
EXCLUDE_FROM_ALL
Expand All @@ -107,23 +107,23 @@ set(stdlib_source_common_args
INCLUDE_DIRECTORIES_PRIVATE ../slang
FOLDER generated
EXPLICIT_SOURCE
./slang-embedded-stdlib-source.cpp
${stdlib_meta_generated_headers}
REQUIRES generate-stdlib-headers
EXTRA_COMPILE_DEFINITIONS_PRIVATE SLANG_EMBED_STDLIB_SOURCE
./slang-embedded-core-module-source.cpp
${core_module_meta_generated_headers}
REQUIRES generate-core-module-headers
EXTRA_COMPILE_DEFINITIONS_PRIVATE SLANG_EMBED_CORE_MODULE_SOURCE
INCLUDE_DIRECTORIES_PRIVATE
${stdlib_meta_output_dir}
${core_module_meta_output_dir}
EXPORT_MACRO_PREFIX SLANG
EXPORT_TYPE_AS ${SLANG_LIB_TYPE}
)

slang_add_target(
${stdlib_source_common_args}
TARGET_NAME slang-embedded-stdlib-source
EXTRA_COMPILE_DEFINITIONS_PRIVATE SLANG_EMBED_STDLIB_SOURCE
${core_module_source_common_args}
TARGET_NAME slang-embedded-core-module-source
EXTRA_COMPILE_DEFINITIONS_PRIVATE SLANG_EMBED_CORE_MODULE_SOURCE
)

slang_add_target(
${stdlib_source_common_args}
TARGET_NAME slang-no-embedded-stdlib-source
${core_module_source_common_args}
TARGET_NAME slang-no-embedded-core-module-source
)
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include "slang-compiler.h"
#include "slang-ir.h"
#include "slang-ir-util.h"
#include "slang-stdlib-textures.h"
#include "slang-core-module-textures.h"

#define STRINGIZE(x) STRINGIZE2(x)
#define STRINGIZE2(x) #x
#define LINE_STRING STRINGIZE(__LINE__)

namespace Slang
{
// We are going to generate the stdlib source code from a more compact
// We are going to generate the core module source code from a more compact
// description. For example, we need to generate all the `operator`
// declarations for the basic unary and binary math operations on
// builtin types. To do this, we will make a big array of all these
Expand Down Expand Up @@ -284,7 +284,7 @@ namespace Slang

ComPtr<ISlangBlob> Session::getCoreLibraryCode()
{
#if SLANG_EMBED_STDLIB_SOURCE
#if SLANG_EMBED_CORE_MODULE_SOURCE
if (!coreLibraryCode)
{
StringBuilder sb;
Expand All @@ -298,7 +298,7 @@ namespace Slang

ComPtr<ISlangBlob> Session::getHLSLLibraryCode()
{
#if SLANG_EMBED_STDLIB_SOURCE
#if SLANG_EMBED_CORE_MODULE_SOURCE
if (!hlslLibraryCode)
{
const String path = getStdlibPath();
Expand All @@ -312,7 +312,7 @@ namespace Slang

ComPtr<ISlangBlob> Session::getAutodiffLibraryCode()
{
#if SLANG_EMBED_STDLIB_SOURCE
#if SLANG_EMBED_CORE_MODULE_SOURCE
if (!autodiffLibraryCode)
{
const String path = getStdlibPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#include "../core/slang-array-view.h"
#include "../core/slang-blob.h"

#ifdef SLANG_EMBED_STDLIB
#ifdef SLANG_EMBED_CORE_MODULE

static const uint8_t g_coreModule[] =
{
# include "slang-stdlib-generated.h"
# include "slang-core-module-generated.h"
};

static Slang::StaticBlob g_coreModuleBlob((const void*)g_coreModule, sizeof(g_coreModule));
Expand Down
24 changes: 12 additions & 12 deletions source/slang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,22 @@ set(slang_public_lib_args
${slang_SOURCE_DIR}/include/slang*.h
${CMAKE_CURRENT_BINARY_DIR}/slang-version-header/*.h
LINK_WITH_PRIVATE
$<IF:$<BOOL:${SLANG_EMBED_STDLIB}>,slang-embedded-stdlib,slang-no-embedded-stdlib>
$<IF:$<BOOL:${SLANG_EMBED_STDLIB_SOURCE}>,slang-embedded-stdlib-source,slang-no-embedded-stdlib-source>
$<IF:$<BOOL:${SLANG_EMBED_CORE_MODULE}>,slang-embedded-core-module,slang-no-embedded-core-module>
$<IF:$<BOOL:${SLANG_EMBED_CORE_MODULE_SOURCE}>,slang-embedded-core-module-source,slang-no-embedded-core-module-source>
INSTALL
)

#
# Minimal static slang used in generating the embedded stdlib
# Minimal static slang used in generating the embedded core module
#

#
# Slang itself
#

if(NOT SLANG_EMBED_STDLIB)
# If we're not embedding stdlib we can just do a normal build of slang,
# including all the options, this can also serve as our no embedded stdlib
if(NOT SLANG_EMBED_CORE_MODULE)
# If we're not embedding core module we can just do a normal build of slang,
# including all the options, this can also serve as our no embedded core module
# library for slang-bootstrap (not that we need that anyway)
slang_add_target(
.
Expand All @@ -231,10 +231,10 @@ if(NOT SLANG_EMBED_STDLIB)
${slang_public_lib_args}
INSTALL_COMPONENT generators
)
add_library(slang-without-embedded-stdlib ALIAS slang)
add_library(slang-without-embedded-core-module ALIAS slang)
else()
# However if we're embedding stdlib, we need to make two different
# libraries, one with the embedded stdlib and one without, so first define
# However if we're embedding core module, we need to make two different
# libraries, one with the embedded core module and one without, so first define
# the shared objects as one target so we don't build them twice.
slang_add_target(
.
Expand All @@ -251,12 +251,12 @@ else()
${slang_interface_args}
NO_SOURCE
TARGET_NAME
slang-without-embedded-stdlib
slang-without-embedded-core-module
EXCLUDE_FROM_ALL
LINK_WITH_PRIVATE
slang-common-objects
slang-no-embedded-stdlib
slang-embedded-stdlib-source
slang-no-embedded-core-module
slang-embedded-core-module-source
OUTPUT_DIR generators
FOLDER generators
INSTALL_COMPONENT generators
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "slang-stdlib-textures.h"
#include "slang-core-module-textures.h"
#include <spirv/unified1/spirv.h>

#define EMIT_LINE_DIRECTIVE() sb << "#line " << (__LINE__+1) << " \"slang-stdlib-textures.cpp\"\n"
#define EMIT_LINE_DIRECTIVE() sb << "#line " << (__LINE__+1) << " \"slang-core-module-textures.cpp\"\n"

namespace Slang
{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// slang-stdlib.cpp

#include "slang-compiler.h"
#include "slang-ir.h"
#include "../core/slang-string-util.h"
Expand Down
2 changes: 1 addition & 1 deletion tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ generator(
USE_FEWER_WARNINGS
LINK_WITH_PRIVATE
prelude
slang-without-embedded-stdlib
slang-without-embedded-core-module
slang-capability-lookup
slang-lookup-tables
Threads::Threads
Expand Down
8 changes: 4 additions & 4 deletions tools/slang-test/parse-diagnostic-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,17 +449,17 @@ static bool _isAtEnd(const UnownedStringSlice& text, const UnownedStringSlice& l
SlangResult resB = ParseDiagnosticUtil::parseDiagnostics(b, diagsB);

/*
TODO(JS): In the past we needed special handling of the stdlib, when
in some builds the path contains the stdlib.
TODO(JS): In the past we needed special handling of the core module, when
in some builds the path contains the core module.
For now we don't seem to need this, this is for future reference, if there
is an issue with needing to specially handle this.
static const UnownedStringSlice stdLibNames[] =
static const UnownedStringSlice coreModuleNames[] =
{
UnownedStringSlice::fromLiteral("core.meta.slang"),
UnownedStringSlice::fromLiteral("hlsl.meta.slang"),
UnownedStringSlice::fromLiteral("slang-stdlib.cpp"),
UnownedStringSlice::fromLiteral("slang-core-module.cpp"),
};
*/

Expand Down

0 comments on commit d8969d8

Please sign in to comment.