Skip to content

Commit

Permalink
Running tests in slang-test process (#740)
Browse files Browse the repository at this point in the history
* First pass at having an interface to write text to that can be replaced.
Simplifed and made more rigerous the interface used to write formatted strings.

* Added AppContext to simplify setting up and parsing around of streams.

* Added more simplified way to get the std error/out from AppContext.

* Work in progress using dll for tools to speed up testing.

* First pass at ISlangWriter interface.

* Added support for writing VaArgs.
Added NullWriter.

* Use ISlangWriter for output.

* Use ISlangWriter for output - replacing OutputCallback.
Make IRDump go to ISlangWriter

* SlangWriterTargetType -> SlangWriterChannel
Improvements around AppContext

* Shared library working with slang-reflection-test.

* Dll testing working for render-test.

* Include va_list definintion from header.

* Fix errors from clang.

* Fix typo for linux.

* Added -usexes option

* Fix typo.

* Fix arguments problem on linux.

* Fix typo for linux.

* Add windows tool shared library projects.

* Fix warning from x86 win build.
Fix signed warning from slang-test/main.cpp

* First attempt at getting premake to work on travis, and run tests.

* Try moving build out into script.

* Invoke bash scripts so they don't have to be executable.

* Drive configuration/tests from env parameters set by travis

* Try using source to run travis tests.

* Remove the build.linux directory - but doing so will overwrite Makefile.

* Made -fno-delete-null-pointer-checks gcc only.

* Try to fix warning from -fno-delete-null-pointer-checks

* Turn of warnings for unknown switches.

* Try to make premake choose the correct tooling.

* Disabled missing braces warning.

* Disable -Wundefined-var-template on clang.

* -Wunused-function disabled for clang.

* Fix typo due to SlangBool.

* Remove this nullptr tests.

* "-Wno-unused-private-field" for clang.

* Added "-Wno-undefined-bool-conversion"

* Add DominatorList::end fix.

* Split scripts into travis_build.sh travis_test.sh

* Fix gcc/clang template pre-declaration issue around QualType.

* Fix premake to build such that pthread correctly links with slang-glslang
  • Loading branch information
jsmall-zzz committed Dec 12, 2018
1 parent 62d3e38 commit 49ed6b6
Show file tree
Hide file tree
Showing 53 changed files with 1,961 additions and 335 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -39,8 +39,8 @@ matrix:
# `./configure && make && make test` which is appropriate
# for autoconf, but I don't want to get into that mess..
#
script: make && make test

script: bash ./travis_build.sh && bash ./travis_test.sh
before_deploy: |
export SLANG_OS_NAME=${TRAVIS_OS_NAME}
export SLANG_ARCH_NAME=`uname -p`
Expand Down
2 changes: 1 addition & 1 deletion examples/hello-world/hello-world.vcxproj
Expand Up @@ -19,7 +19,7 @@
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{5CF41E7B-4883-A844-F1A1-BC3FDD0FB9EA}</ProjectGuid>
<ProjectGuid>{010BE414-ED5B-CF56-16C0-BD18027062C0}</ProjectGuid>
<IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename>
<Keyword>Win32Proj</Keyword>
<RootNamespace>hello-world</RootNamespace>
Expand Down
2 changes: 1 addition & 1 deletion examples/model-viewer/model-viewer.vcxproj
Expand Up @@ -19,7 +19,7 @@
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{639B13F2-CF07-CFEC-98FB-664A0427F154}</ProjectGuid>
<ProjectGuid>{2F8724C6-1BC3-2730-84D5-3F277030D04A}</ProjectGuid>
<IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename>
<Keyword>Win32Proj</Keyword>
<RootNamespace>model-viewer</RootNamespace>
Expand Down
82 changes: 63 additions & 19 deletions premake5.lua
Expand Up @@ -115,13 +115,13 @@ workspace "slang"
architecture "ARM"

filter { "toolset:clang or gcc*" }
buildoptions { "-Wno-unused-parameter", "-Wno-type-limits", "-Wno-sign-compare", "-Wno-unused-variable", "-Wno-reorder", "-Wno-switch", "-Wno-return-type", "-Wno-unused-local-typedefs", "-Wno-parentheses", "-std=c++11", "-fvisibility=hidden", "-fno-delete-null-pointer-checks" }
buildoptions { "-Wno-unused-parameter", "-Wno-type-limits", "-Wno-sign-compare", "-Wno-unused-variable", "-Wno-reorder", "-Wno-switch", "-Wno-return-type", "-Wno-unused-local-typedefs", "-Wno-parentheses", "-std=c++11", "-fvisibility=hidden" , "-fno-delete-null-pointer-checks", "-Wno-ignored-optimization-argument", "-Wno-unknown-warning-option"}

filter { "toolset:gcc*"}
buildoptions { "-Wno-nonnull-compare", "-Wno-unused-but-set-variable", "-Wno-implicit-fallthrough" }
buildoptions { "-Wno-nonnull-compare", "-Wno-unused-but-set-variable", "-Wno-implicit-fallthrough" }

filter { "toolset:clang" }
buildoptions { "-Wno-deprecated-register", "-Wno-tautological-compare"}
buildoptions { "-Wno-deprecated-register", "-Wno-tautological-compare", "-Wno-missing-braces", "-Wno-undefined-var-template", "-Wno-unused-function", "-Wno-undefined-bool-conversion"}

-- When compiling the debug configuration, we want to turn
-- optimization off, make sure debug symbols are output,
Expand Down Expand Up @@ -193,20 +193,15 @@ end
-- Next we will define a helper routine that all of our
-- projects will bottleneck through. Here `name` is
-- the name for the project (and the base name for
-- whatever output file it produces), while `baseDir`
-- is the parent directory of the project's directory.
-- whatever output file it produces), while `sourceDir`
-- is the directory that holds the source.
--
-- E.g., for the `slangc` project, the source code
-- is nested in `source/`, so we'd (indirectly) call:
--
-- baseSlangProject("slangc", "source")
-- baseSlangProject("slangc", "source/slangc")
--
function baseSlangProject(name, baseDir)

-- The project directory will be nested inside
-- the base directory using the project's name.
--
local projectDir = baseDir .. "/" .. name
function baseSlangProject(name, sourceDir)

-- Start a new project in premake. This switches
-- the "current" project over to the newly created
Expand All @@ -220,7 +215,7 @@ function baseSlangProject(name, baseDir)
-- projects. If we don't have a stable UUID, then the
-- output files might have spurious diffs whenever we
-- re-run premake generation.
uuid(os.uuid(projectDir))
uuid(os.uuid(name .. '|' .. sourceDir))

-- Set the location where the project file will be placed.
-- We set the project files to reside in their source
Expand All @@ -233,7 +228,7 @@ function baseSlangProject(name, baseDir)
-- it is less relevant to other projects.
--

location(projectDir)
location(sourceDir)

if os.target() == "windows" then
else
Expand All @@ -257,7 +252,7 @@ function baseSlangProject(name, baseDir)
-- so projects that spread their source over multiple
-- directories will need to take more steps.
--
addSourceDir(projectDir)
addSourceDir(sourceDir)

-- By default, Premake generates VS project files that
-- reflect the directory structure of the source code.
Expand Down Expand Up @@ -314,7 +309,7 @@ function tool(name)
-- Now we invoke our shared project configuration logic,
-- specifying that the project lives under the `tools/` path.
--
baseSlangProject(name, "tools")
baseSlangProject(name, "tools/" .. name)

-- Finally, we set the project "kind" to produce a console
-- application. This is a reasonable default for tools,
Expand All @@ -339,7 +334,29 @@ function standardProject(name)

-- A standard project has its code under `source/`
--
baseSlangProject(name, "source")
baseSlangProject(name, "source/" .. name)
end

function toolSharedLibrary(name)
group "tool-shared-library"
-- specifying that the project lives under the `tools/` path.
--
baseSlangProject(name .. "-shared-library", "tools/" .. name)

defines { "SLANG_SHARED_LIBRARY_TOOL" }

kind "SharedLib"
end

function standardSharedLibraryProject(name)
group "tool-shared-library"
-- A standard project has its code under `source/`
--
baseSlangProject(name .. "-shared-library", "source/".. name)

defines { "SLANG_SHARED_LIBRARY_TOOL" }

kind "SharedLib"
end

-- Finally we have the example programs that show how to use Slang.
Expand All @@ -349,7 +366,7 @@ function example(name)
group "examples"

-- They have their source code under `examples/<project-name>/`
baseSlangProject(name, "examples")
baseSlangProject(name, "examples/" .. name)

-- By default, all of our examples are GUI applications. One some
-- platforms there is no meaningful distinction between GUI and
Expand Down Expand Up @@ -446,8 +463,15 @@ tool "slang-test"
tool "slang-reflection-test"
uuid "22C45F4F-FB6B-4535-BED1-D3F5D0C71047"
includedirs { "." }
links { "slang" }
links { "slang", "core" }

toolSharedLibrary "slang-reflection-test"
uuid "C5ACCA6E-C04D-4B36-8516-3752B3C13C2F"

includedirs { "." }
kind "SharedLib"
links { "core", "slang" }

--
-- The most complex testing tool we have is `render-test`, but from
-- a build perspective the most interesting thing about it is that for
Expand Down Expand Up @@ -475,6 +499,20 @@ if os.target() == "windows" then
-- dxcompiler.dll, and dxil.dll from the Windows SDK redistributable
-- directory into the output directory.
postbuildcommands { '"$(SolutionDir)tools\\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/%{cfg.platform:lower()}/" "%{cfg.targetdir}/"'}

toolSharedLibrary "render-test"
uuid "61F7EB00-7281-4BF3-9470-7C2EA92620C3"

includedirs { ".", "external", "source", "tools/gfx" }
links { "core", "slang", "gfx" }

systemversion "10.0.14393.0"

-- For Windows targets, we want to copy d3dcompiler_47.dll,
-- dxcompiler.dll, and dxil.dll from the Windows SDK redistributable
-- directory into the output directory.
postbuildcommands { '"$(SolutionDir)tools\\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/%{cfg.platform:lower()}/" "%{cfg.targetdir}/"'}

end

--
Expand Down Expand Up @@ -516,6 +554,11 @@ standardProject "slangc"
kind "ConsoleApp"
links { "core", "slang" }

standardSharedLibraryProject "slangc"
uuid "644921BF-D228-4EEF-8CDA-11716DB06989"
kind "SharedLib"
links { "core", "slang" }

--
-- TODO: Slang's current `Makefile` build does some careful incantations
-- to make sure that the binaries it generates use a "relative `RPATH`"
Expand Down Expand Up @@ -665,6 +708,7 @@ standardProject "slang-glslang"
removefiles { "external/glslang/glslang/OSDependent/Windows/main.cpp" }

filter { "system:linux" }
links { "dl", "pthread" }
addSourceDir("external/glslang/glslang/OSDependent/Unix")
buildoptions{"-fPIC", "-pthread"}

Expand Down
95 changes: 84 additions & 11 deletions slang.h
Expand Up @@ -192,19 +192,25 @@ convention for interface methods.
#define SLANG_DYNAMIC
#endif

#if defined(_MSC_VER)
# define SLANG_DLL_EXPORT __declspec(dllexport)
#else
# define SLANG_DLL_EXPORT __attribute__((__visibility__("default")))
#endif

#if defined(SLANG_DYNAMIC)
#if defined(_MSC_VER)
#ifdef SLANG_DYNAMIC_EXPORT
#define SLANG_API __declspec(dllexport)
#else
#define SLANG_API __declspec(dllimport)
#endif
#else
# if defined(_MSC_VER)
# ifdef SLANG_DYNAMIC_EXPORT
# define SLANG_API SLANG_DLL_EXPORT
# else
# define SLANG_API __declspec(dllimport)
# endif
# else
// TODO: need to consider compiler capabilities
// #ifdef SLANG_DYNAMIC_EXPORT
#define SLANG_API __attribute__((__visibility__("default")))
// #endif
#endif
//# ifdef SLANG_DYNAMIC_EXPORT
# define SLANG_API SLANG_DLL_EXPORT
//# endif
# endif
#endif

#ifndef SLANG_API
Expand Down Expand Up @@ -283,6 +289,13 @@ convention for interface methods.
# define SLANG_UINT64(x) (x##ull)
#endif


#ifdef __cplusplus
# define SLANG_EXTERN_C extern "C"
#else
# define SLANG_EXTERN_C
#endif

#ifdef __cplusplus
// C++ specific macros
// Gcc
Expand Down Expand Up @@ -339,6 +352,8 @@ convention for interface methods.
#include <stddef.h>
#endif // ! SLANG_NO_STDDEF

#include <stdarg.h>

#ifdef __cplusplus
extern "C"
{
Expand All @@ -354,6 +369,8 @@ extern "C"
typedef uint32_t SlangUInt32;
typedef intptr_t SlangInt;
typedef uintptr_t SlangUInt;

typedef bool SlangBool;

/*!
@brief Severity of a diagnostic generated by the compiler.
Expand Down Expand Up @@ -634,6 +651,8 @@ extern "C"
#define SLANG_E_CANNOT_OPEN SLANG_MAKE_CORE_ERROR(4)
//! Indicates a file/resource could not be found
#define SLANG_E_NOT_FOUND SLANG_MAKE_CORE_ERROR(5)
//! An unhandled internal failure (typically from unhandled exception)
#define SLANG_E_INTERNAL_FAIL SLANG_MAKE_CORE_ERROR(6)

/** A "Universally Unique Identifier" (UUID)
Expand Down Expand Up @@ -810,6 +829,51 @@ extern "C"

#define SLANG_UUID_ISlangFileSystemExt { 0x5fb632d2, 0x979d, 0x4481, { 0x9f, 0xee, 0x66, 0x3c, 0x3f, 0x14, 0x49, 0xe1 } }

/* Identifies different types of writer target*/
typedef unsigned int SlangWriterChannel;
enum
{
SLANG_WRITER_CHANNEL_DIAGNOSTIC,
SLANG_WRITER_CHANNEL_STD_OUTPUT,
SLANG_WRITER_CHANNEL_STD_ERROR,
SLANG_WRITER_CHANNEL_COUNT_OF,
};

typedef unsigned int SlangWriterMode;
enum
{
SLANG_WRITER_MODE_TEXT,
SLANG_WRITER_MODE_BINARY,
};

/** A stream typically of text, used for outputting diagnostic as well as other information.
*/
struct ISlangWriter : public ISlangUnknown
{
public:
/** Write the formatted string with the used args. If returns SLANG_E_NOT_IMPLEMENTED, will use a default internal implementation, and call write with result
@param format Format string
@param args The arguments
@return SLANG_E_NOT_IMPLEMENTED if not implemented, SLANG_OK on success */
virtual SLANG_NO_THROW SlangResult SLANG_MCALL writeVaList(const char* format, va_list args) = 0;
/** Write text to the writer
@param chars The characters to write out
@param numChars The amount of characters
@returns SLANG_OK on success */
virtual SLANG_NO_THROW SlangResult SLANG_MCALL write(const char* chars, size_t numChars) = 0;
/** Flushes any content to the ouput */
virtual SLANG_NO_THROW void SLANG_MCALL flush() = 0;
/** Determines if the writer stream is to the console, and can be used to alter the output
@returns Returns true if is a console writer */
virtual SLANG_NO_THROW SlangBool SLANG_MCALL isConsole() = 0;
/** Set the mode for the writer to use
@param mode The mode to use
@returns SLANG_OK on success */
virtual SLANG_NO_THROW SlangResult SLANG_MCALL setMode(SlangWriterMode mode) = 0;
};

#define SLANG_UUID_ISlangWriter { 0xec457f0e, 0x9add, 0x4e6b,{ 0x85, 0x1c, 0xd7, 0xfa, 0x71, 0x6d, 0x15, 0xfd } };

/*!
@brief An instance of the Slang library.
*/
Expand Down Expand Up @@ -984,6 +1048,15 @@ extern "C"
SlangDiagnosticCallback callback,
void const* userData);

SLANG_API void spSetWriter(
SlangCompileRequest* request,
SlangWriterChannel channel,
ISlangWriter* writer);

SLANG_API ISlangWriter* spGetWriter(
SlangCompileRequest* request,
SlangWriterChannel channel);

/*!
@brief Add a path to use when searching for referenced files.
This will be used for both `#include` directives and also for explicit `__import` declarations.
Expand Down

0 comments on commit 49ed6b6

Please sign in to comment.