From 15f07d14b5f048dc355536cbdf5cf9c10291b13b Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 10 Feb 2022 13:57:59 -0500 Subject: Fix MacOSX build issues (#2124) * #include an absolute path didn't work - because paths were taken to always be relative. * Small fixes. Added compiler crash with generic defined in a function. Added enum-flags test that works (by limiting backing type to int), and using __EnumType constraint. * Add comment about crash. * Disable crashing test. * Fixes to make compile on OSX. * Add github build for OSX. * Make premake generator a utility. * Fix osx compilation issue. * More fixes for OSX build. * OSX fix due to ambiguity around size_t and integer types. * Disable xlib on build on osx. * Use 'prebuildcommands' to make prebuild make utility projects do something. * Small fixes for premake so utility works on linux/osx. * Another hack to try and make generators run when 'utility' * Fix typo in macos.yml. * Revert premake to old style, and disable stdlib embedding on OSX. --- .github/workflows/macos.yml | 33 ++++++++++++++++++++++ .../gfx-unit-test-tool.vcxproj.filters | 6 ++-- examples/model-viewer/main.cpp | 8 +++--- github_macos_build.sh | 21 ++++++++++++++ premake5.lua | 3 +- slang.h | 9 +++++- source/core/slang-http.cpp | 2 +- source/core/unix/slang-unix-process.cpp | 4 +++ tools/gfx/cpu/render-cpu.cpp | 2 +- 9 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/macos.yml create mode 100644 github_macos_build.sh diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml new file mode 100644 index 000000000..700d9f6a4 --- /dev/null +++ b/.github/workflows/macos.yml @@ -0,0 +1,33 @@ +name: MacOS Build CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + name: MacOS Build CI + + runs-on: macos-latest + + strategy: + matrix: + configuration: ['release'] # 'debug' + compiler: ['clang'] + platform: ['x64'] + + steps: + - uses: actions/checkout@v2.3.4 + with: + submodules: 'true' + fetch-depth: '0' + + - name: build + run: + CC=${{matrix.compiler}} + CONFIGURATION=${{matrix.configuration}} + ARCH=${{matrix.platform}} + source ./github_macos_build.sh + \ No newline at end of file diff --git a/build/visual-studio/gfx-unit-test-tool/gfx-unit-test-tool.vcxproj.filters b/build/visual-studio/gfx-unit-test-tool/gfx-unit-test-tool.vcxproj.filters index 230aa3893..e96c7bfcc 100644 --- a/build/visual-studio/gfx-unit-test-tool/gfx-unit-test-tool.vcxproj.filters +++ b/build/visual-studio/gfx-unit-test-tool/gfx-unit-test-tool.vcxproj.filters @@ -44,6 +44,9 @@ Source Files + + Source Files + Source Files @@ -74,9 +77,6 @@ Source Files - - Source Files - diff --git a/examples/model-viewer/main.cpp b/examples/model-viewer/main.cpp index 3b278fede..121e3fc4b 100644 --- a/examples/model-viewer/main.cpp +++ b/examples/model-viewer/main.cpp @@ -314,7 +314,7 @@ struct DirectionalLight : Light static const char* getTypeName() { return "DirectionalLight"; } - virtual void writeTo(ShaderCursor const& cursor) + virtual void writeTo(ShaderCursor const& cursor) override { cursor["direction"].setData(&direction, sizeof(direction)); cursor["intensity"].setData(&intensity, sizeof(intensity)); @@ -333,7 +333,7 @@ struct PointLight : Light static const char* getTypeName() { return "PointLight"; } - virtual void writeTo(ShaderCursor const& cursor) + virtual void writeTo(ShaderCursor const& cursor) override { cursor["position"].setData(&position, sizeof(position)); cursor["intensity"].setData(&intensity, sizeof(intensity)); @@ -594,7 +594,7 @@ struct LightEnv : public RefObject // The more interesting case is when we have a `LightArray`, // in which case we need to fill in the first field (the light count)... // - uint32_t lightCount = uint32_t(lightTypeArray->lights.size()); + int32_t lightCount = int32_t(lightTypeArray->lights.size()); lightTypeCursor["count"].setData(&lightCount, sizeof(lightCount)); // // ... followed by an array of values of type `L` in the second field. @@ -603,7 +603,7 @@ struct LightEnv : public RefObject // not access the entries past that point. // auto arrayCursor = lightTypeCursor["lights"]; - for (size_t ii = 0; ii < lightCount; ++ii) + for (int32_t ii = 0; ii < lightCount; ++ii) { lightTypeArray->lights[ii]->writeTo(arrayCursor[ii]); } diff --git a/github_macos_build.sh b/github_macos_build.sh new file mode 100644 index 000000000..739088814 --- /dev/null +++ b/github_macos_build.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# Get premake +wget https://github.com/shader-slang/slang-binaries/blob/master/premake/premake-5.0.0-alpha16/bin/osx/premake5?raw=true -O premake5 +chmod u+x premake5 + +# generate slang-tag-version.h +git describe --tags | sed -e "s/\(.*\)/\#define SLANG_TAG_VERSION \"\1\"/" > slang-tag-version.h +cat slang-tag-version.h + +# Create the makefile +# +# NOTE! For now we disable stdlib embedding, because on OSX it produces an error when generating +# thinking it's creating a lib, but has no source +# +# --enable-embed-stdlib=true +./premake5 gmake --cc=${CC} --enable-xlib=false --arch=${ARCH} --deps=true --no-progress=true + +# Build the configuration +make config=${CONFIGURATION}_x64 -j`sysctl -n hw.ncpu` + + diff --git a/premake5.lua b/premake5.lua index dc6f1a552..064253d1b 100644 --- a/premake5.lua +++ b/premake5.lua @@ -203,9 +203,10 @@ newoption { -- TODO(JS): What's the point in the enable-xlib command line option if it's just overridden here? - if targetInfo.isWindows then + if targetInfo.isWindows or os.target() == "macosx" then enableXlib = false end + -- Even if we have the nvapi path, we only want to currently enable on windows targets enableNvapi = not not (os.isdir(nvapiPath) and targetInfo.isWindows and _OPTIONS["enable-nvapi"] == "true") diff --git a/slang.h b/slang.h index cdc0daeab..83b10fc74 100644 --- a/slang.h +++ b/slang.h @@ -490,13 +490,20 @@ extern "C" // Use SLANG_PTR_ macros to determine SlangInt/SlangUInt types. // This is used over say using size_t/ptrdiff_t/intptr_t/uintptr_t, because on some targets, these types are distinct from - // their uint_t/int_t equivalents and so produce ambiguity with function overloading. + // their uint_t/int_t equivalents and so produce ambiguity with function overloading. + // + // SlangSizeT is helpful as on some compilers size_t is distinct from a regular integer type and so overloading doesn't work. + // Casting to SlangSizeT works around this. #if SLANG_PTR_IS_64 typedef int64_t SlangInt; typedef uint64_t SlangUInt; + + typedef uint64_t SlangSizeT; #else typedef int32_t SlangInt; typedef uint32_t SlangUInt; + + typedef uint32_t SlangSizeT; #endif typedef bool SlangBool; diff --git a/source/core/slang-http.cpp b/source/core/slang-http.cpp index bb5994635..3da22ba9c 100644 --- a/source/core/slang-http.cpp +++ b/source/core/slang-http.cpp @@ -158,7 +158,7 @@ void HTTPHeader::reset() void HTTPHeader::append(StringBuilder& out) const { // Output the content length - out << g_contentLength << ": " << m_contentLength << "\r\n"; + out << g_contentLength << ": " << SlangSizeT(m_contentLength) << "\r\n"; // If either is set construct a content type if (m_mimeType.getLength() || m_encoding.getLength()) diff --git a/source/core/unix/slang-unix-process.cpp b/source/core/unix/slang-unix-process.cpp index 1f58f5725..991d905d9 100644 --- a/source/core/unix/slang-unix-process.cpp +++ b/source/core/unix/slang-unix-process.cpp @@ -19,6 +19,10 @@ #include #include +#if SLANG_OSX +# include +#endif + #include namespace Slang { diff --git a/tools/gfx/cpu/render-cpu.cpp b/tools/gfx/cpu/render-cpu.cpp index a20ed3ebe..d17cf6ea8 100644 --- a/tools/gfx/cpu/render-cpu.cpp +++ b/tools/gfx/cpu/render-cpu.cpp @@ -873,7 +873,7 @@ public: virtual SLANG_NO_THROW Result SLANG_MCALL setData(ShaderOffset const& offset, void const* data, size_t size) override { - size = Math::Min(size, (size_t)m_data.getCount() - offset.uniformOffset); + size = Math::Min(size, size_t(m_data.getCount() - offset.uniformOffset)); memcpy((char*)m_data.getBuffer() + offset.uniformOffset, data, size); return SLANG_OK; } -- cgit v1.2.3