Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shader-slang: new recipe #25309

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions recipes/shader-slang/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sources:
"2024.11.1":
url: "https://github.com/shader-slang/slang/archive/refs/tags/v2024.11.1.tar.gz"
sha256: "e25bdf63e4cace79ba388e4411eed73495f2046ef53125e42ec5fa36599995a8"
patches:
"2024.11.1":
- patch_file: "patches/0001-update-unvendored-includes.patch"
- patch_file: "patches/0002-cmake-fixes.patch"
- patch_file: "patches/0003-fix-glslang-regression.patch"
165 changes: 165 additions & 0 deletions recipes/shader-slang/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import os

from conan import ConanFile
from conan.tools.apple import is_apple_os
from conan.tools.build import check_min_cppstd, can_run
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir, mkdir

required_conan_version = ">=2.0"


class ShaderSlangConan(ConanFile):
name = "shader-slang"
description = (
"Slang is a shading language that makes it easier to build and maintain large shader"
" codebases in a modular and extensible fashion, while also maintaining the highest possible"
" performance on modern GPUs and graphics APIs."
)
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/shader-slang/slang"
topics = ("shaders", "vulkan", "glsl", "cuda", "hlsl", "d3d12")
package_type = "shared-library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"enable_gfx": [True, False],
"with_x11": [True, False],
"with_cuda": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"enable_gfx": False,
"with_x11": True,
"with_cuda": False,
}

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
if not self.options.enable_gfx or self.settings.os not in ["Linux", "FreeBSD"]:
del self.options.with_x11

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("glslang/1.3.290.0")
self.requires("spirv-headers/1.3.290.0")
self.requires("spirv-tools/1.3.290.0")
self.requires("lz4/1.10.0")
self.requires("miniz/3.0.2")
self.requires("unordered_dense/4.4.0")
if self.options.enable_gfx:
self.requires("vulkan-headers/1.3.290.0")
self.requires("imgui/1.91.0")
if is_apple_os(self):
self.requires("metal-cpp/14.2")
if self.options.get_safe("with_x11"):
self.requires("xorg/system")

def validate(self):
check_min_cppstd(self, 17)

def build_requirements(self):
self.tool_requires("cmake/[>=3.25 <4]")
if not can_run(self):
self.tool_requires(f"shader-slang/{self.version}")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
apply_conandata_patches(self)

def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["SLANG_LIB_TYPE"] = "SHARED" if self.options.shared else "STATIC"
tc.cache_variables["SLANG_ENABLE_PREBUILT_BINARIES"] = False
tc.cache_variables["SLANG_ENABLE_TESTS"] = False
tc.cache_variables["SLANG_ENABLE_EXAMPLES"] = False
tc.cache_variables["SLANG_ENABLE_GFX"] = self.options.enable_gfx
tc.cache_variables["SLANG_ENABLE_XLIB"] = self.options.get_safe("with_x11", False)
tc.cache_variables["SLANG_ENABLE_CUDA"] = self.options.get_safe("with_cuda", False)
tc.cache_variables["SLANG_SLANG_LLVM_FLAVOR"] = "USE_SYSTEM_LLVM" if self.options.get_safe("with_llvm") else "DISABLE"
tc.generate()
deps = CMakeDeps(self)
deps.generate()
VirtualBuildEnv(self).generate()

def _patch_sources(self):
# Everything except dxc/dxcapi.h is unvendored
mkdir(self, os.path.join(self.source_folder, "external_headers"))
os.rename(os.path.join(self.source_folder, "external", "dxc"),
os.path.join(self.source_folder, "external_headers", "dxc"))
rmdir(self, os.path.join(self.source_folder, "external"))

def build(self):
self._patch_sources()
cmake = CMake(self)
cmake.configure()
cmake.build()
if self.settings_target is not None:
# Build and install native build tools for cross-compilation
cmake.build(target="generators")
cmake.build(target="slang-bootstrap")

def package(self):
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
if self.settings_target is not None:
cmake.install(component="generators")
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.components["slang_"].libs = ["slang"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["slang_"].system_libs.extend(["m", "pthread", "dl", "rt"])
self.cpp_info.components["slang_"].requires = [
"miniz::miniz",
"lz4::lz4",
"glslang::glslang-core",
"glslang::spirv",
"spirv-tools::spirv-tools-opt",
"spirv-headers::spirv-headers",
"unordered_dense::unordered_dense"
]

self.cpp_info.components["slang-glslang"].libs = ["slang-glslang"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["slang-glslang"].system_libs.extend(["m", "pthread", "rt"])
self.cpp_info.components["slang-glslang"].requires = [
"glslang::glslang-core",
"glslang::spirv",
"spirv-tools::spirv-tools-opt",
"spirv-headers::spirv-headers",
"unordered_dense::unordered_dense"
]

self.cpp_info.components["slang-rt"].libs = ["slang-rt"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["slang-rt"].system_libs.extend(["m", "pthread", "dl"])
self.cpp_info.components["slang-rt"].requires = ["miniz::miniz", "lz4::lz4"]

if self.options.enable_gfx:
self.cpp_info.components["gfx"].libs = ["gfx"]
self.cpp_info.components["gfx"].requires = ["slang_", "vulkan-headers::vulkan-headers"]
if is_apple_os(self):
self.cpp_info.components["gfx"].requires.append("metal-cpp::metal-cpp")
if self.options.get_safe("with_x11"):
self.cpp_info.components["gfx"].requires.append("xorg::x11")
if self.options.with_cuda:
self.cpp_info.components["gfx"].system_libs.append("cuda")

if self.options.enable_gfx:
self.cpp_info.components["_tools"].requires = ["imgui::imgui"]
202 changes: 202 additions & 0 deletions recipes/shader-slang/all/patches/0001-update-unvendored-includes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
From 0cf4d7dd8ed237ec954f5579c4e61e5f4867bac6 Mon Sep 17 00:00:00 2001
From: Martin Valgur <[email protected]>
Date: Wed, 18 Sep 2024 14:23:20 +0300
Subject: [PATCH 1/2] Update unvendored dependency includes

---
source/compiler-core/slang-dxc-compiler.cpp | 4 ++--
source/compiler-core/slang-spirv-core-grammar.h | 2 +-
source/core/slang-dictionary.h | 2 +-
source/core/slang-hash.h | 2 +-
source/core/slang-lz4-compression-system.cpp | 2 +-
source/slang-glslang/slang-glslang.cpp | 13 +++++++------
source/slang/slang-ir-glsl-legalize.cpp | 2 +-
tools/gfx/open-gl/render-gl.cpp | 6 +++---
tools/platform/gui.h | 2 +-
tools/platform/model.cpp | 12 ++++++------
tools/platform/vector-math.h | 8 ++++----
17 files changed, 40 insertions(+), 39 deletions(-)

diff --git a/source/compiler-core/slang-dxc-compiler.cpp b/source/compiler-core/slang-dxc-compiler.cpp
index 3a949b3b..527e5d91 100644
--- a/source/compiler-core/slang-dxc-compiler.cpp
+++ b/source/compiler-core/slang-dxc-compiler.cpp
@@ -40,9 +40,9 @@
# ifdef _WIN32
# include <windows.h>
# include <unknwn.h>
-# include "../../external/dxc/dxcapi.h"
+# include "dxc/dxcapi.h"
# else
-# include "../../external/dxc/dxcapi.h"
+# include "dxc/dxcapi.h"

# ifdef __uuidof
// DXC's WinAdapter.h defines __uuidof(T) over types, but the existing
diff --git a/source/compiler-core/slang-spirv-core-grammar.h b/source/compiler-core/slang-spirv-core-grammar.h
index 958aaaef..7391b086 100644
--- a/source/compiler-core/slang-spirv-core-grammar.h
+++ b/source/compiler-core/slang-spirv-core-grammar.h
@@ -4,7 +4,7 @@
#include "../core/slang-string.h"
#include "../core/slang-string-slice-pool.h"
#include "../core/slang-dictionary.h"
-#include "../../external/spirv-headers/include/spirv/unified1/spirv.h"
+#include <spirv/unified1/spirv.h>
#include <optional>

namespace Slang
diff --git a/source/core/slang-dictionary.h b/source/core/slang-dictionary.h
index ba467274..d31e89fc 100644
--- a/source/core/slang-dictionary.h
+++ b/source/core/slang-dictionary.h
@@ -8,7 +8,7 @@
#include "slang-exception.h"
#include "slang-math.h"
#include "slang-hash.h"
-#include "../../external/unordered_dense/include/ankerl/unordered_dense.h"
+#include <ankerl/unordered_dense.h>
#include <initializer_list>

namespace Slang
diff --git a/source/core/slang-hash.h b/source/core/slang-hash.h
index 784f7fd2..b6884d6a 100644
--- a/source/core/slang-hash.h
+++ b/source/core/slang-hash.h
@@ -3,7 +3,7 @@

#include "../../include/slang.h"
#include "slang-math.h"
-#include "../../external/unordered_dense/include/ankerl/unordered_dense.h"
+#include <ankerl/unordered_dense.h>
#include <cstring>
#include <type_traits>

diff --git a/source/core/slang-lz4-compression-system.cpp b/source/core/slang-lz4-compression-system.cpp
index c20b457d..1e2ab955 100644
--- a/source/core/slang-lz4-compression-system.cpp
+++ b/source/core/slang-lz4-compression-system.cpp
@@ -5,7 +5,7 @@

#include "slang-blob.h"

-#include "../../external/lz4/lib/lz4.h"
+#include <lz4.h>

namespace Slang
{
diff --git a/source/slang-glslang/slang-glslang.cpp b/source/slang-glslang/slang-glslang.cpp
index 2dd1b46a..f440c179 100644
--- a/source/slang-glslang/slang-glslang.cpp
+++ b/source/slang-glslang/slang-glslang.cpp
@@ -4,8 +4,8 @@

#include "glslang/Public/ResourceLimits.h"
#include "glslang/Public/ShaderLang.h"
-#include "SPIRV/GlslangToSpv.h"
-#include "SPIRV/disassemble.h"
+#include "glslang/SPIRV/GlslangToSpv.h"
+#include "glslang/SPIRV/disassemble.h"

#include "slang.h"

diff --git a/source/slang/slang-ir-glsl-legalize.cpp b/source/slang/slang-ir-glsl-legalize.cpp
index d8c1aa91..54646e26 100644
--- a/source/slang/slang-ir-glsl-legalize.cpp
+++ b/source/slang/slang-ir-glsl-legalize.cpp
@@ -11,7 +11,7 @@
#include "slang-ir-clone.h"
#include "slang-ir-single-return.h"
#include "slang-glsl-extension-tracker.h"
-#include "../../external/spirv-headers/include/spirv/unified1/spirv.h"
+#include <spirv/unified1/spirv.h>

namespace Slang
{
diff --git a/tools/gfx/open-gl/render-gl.cpp b/tools/gfx/open-gl/render-gl.cpp
index abb17837..e7970368 100644
--- a/tools/gfx/open-gl/render-gl.cpp
+++ b/tools/gfx/open-gl/render-gl.cpp
@@ -9,7 +9,7 @@
#include "core/slang-basic.h"
#include "core/slang-blob.h"
#include "core/slang-secure-crt.h"
-#include "external/stb/stb_image_write.h"
+#include "stb_image_write.h"

#if SLANG_WIN64 || SLANG_WIN64
#define ENABLE_GL_IMPL 1
@@ -35,8 +35,8 @@
#pragma comment(lib, "opengl32")

#include <GL/GL.h>
-#include "external/glext.h"
-#include "external/wglext.h"
+#include "glext.h"
+#include "wglext.h"

// We define an "X-macro" for mapping over loadable OpenGL
// extension entry point that we will use, so that we can
diff --git a/tools/platform/gui.h b/tools/platform/gui.h
index e3975f3f..465ba87b 100644
--- a/tools/platform/gui.h
+++ b/tools/platform/gui.h
@@ -5,7 +5,7 @@
#include "vector-math.h"
#include "window.h"
#include "slang-com-ptr.h"
-#include "external/imgui/imgui.h"
+#include "imgui.h"
#include "source/core/slang-basic.h"

namespace platform {
diff --git a/tools/platform/model.cpp b/tools/platform/model.cpp
index a48d499b..51803bda 100644
--- a/tools/platform/model.cpp
+++ b/tools/platform/model.cpp
@@ -4,17 +4,17 @@
#include "window.h"

#define TINYOBJLOADER_IMPLEMENTATION
-#include "../../external/tinyobjloader/tiny_obj_loader.h"
+#include "tiny_obj_loader.h"

#define STB_IMAGE_IMPLEMENTATION
-#include "../../external/stb/stb_image.h"
+#include "stb_image.h"

#define STB_IMAGE_RESIZE_IMPLEMENTATION
-#include "../../external/stb/stb_image_resize.h"
+#include "stb_image_resize.h"

-#include "../../external/glm/glm/glm.hpp"
-#include "../../external/glm/glm/gtc/matrix_transform.hpp"
-#include "../../external/glm/glm/gtc/constants.hpp"
+#include "glm/glm.hpp"
+#include "glm/gtc/matrix_transform.hpp"
+#include "glm/gtc/constants.hpp"

#include <memory>
#include <unordered_map>
diff --git a/tools/platform/vector-math.h b/tools/platform/vector-math.h
index e35cb46a..8b59fb91 100644
--- a/tools/platform/vector-math.h
+++ b/tools/platform/vector-math.h
@@ -3,10 +3,10 @@

// We will use the GLM library for our vector math types, just for simplicity.

-#include "../../external/glm/glm/glm.hpp"
-#include "../../external/glm/glm/gtc/matrix_transform.hpp"
-#include "../../external/glm/glm/gtc/constants.hpp"
-#include "../../external/glm/glm/gtc/quaternion.hpp"
+#include "glm/glm.hpp"
+#include "glm/gtc/matrix_transform.hpp"
+#include "glm/gtc/constants.hpp"
+#include "glm/gtc/quaternion.hpp"

namespace gfx {

--
2.25.1

Loading