diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-06-14 18:05:12 -0400 |
|---|---|---|
| committer | Tim Foley <tfoleyNV@users.noreply.github.com> | 2019-06-14 15:05:12 -0700 |
| commit | 1fe24d3a74a9cd51c4a025cd0e78642f3e29df79 (patch) | |
| tree | a52d2b1e05f0d22accbb70eb4bea69d7c67455a4 /source | |
| parent | 8c56d83506ef92b15b15bdb5969008dd69c8d2a6 (diff) | |
Runtime Shared Library compilation and testing (#985)
* Removed the need for VisualStudio specific CPPCompiler
Improved the version parsing for gcc/clang
Removed need for slang-unix-cpp-compiler-util.cpp/.h
Remove binary before compiling in the compile c tests
* Moved VisualStudio calcArgs into CPPCompilerUtil - as code is not windows specific.
* Set up compile time version for gcc and clang
* Fix compilation on OSX - use remove instead of unlink for file deletion.
* On OSX - clang uses different string format.
* Removed /bin/sh invoking as not required for OSX.
* First pass working testing with shared libraries.
Diffstat (limited to 'source')
| -rw-r--r-- | source/core/slang-cpp-compiler.cpp | 48 | ||||
| -rw-r--r-- | source/core/slang-cpp-compiler.h | 18 | ||||
| -rw-r--r-- | source/core/slang-platform.cpp | 22 | ||||
| -rw-r--r-- | source/core/slang-platform.h | 3 |
4 files changed, 70 insertions, 21 deletions
diff --git a/source/core/slang-cpp-compiler.cpp b/source/core/slang-cpp-compiler.cpp index 4bcdd068c..18cb9cdae 100644 --- a/source/core/slang-cpp-compiler.cpp +++ b/source/core/slang-cpp-compiler.cpp @@ -33,7 +33,15 @@ SlangResult GenericCPPCompiler::compile(const CompileOptions& options, ExecuteRe } #endif - return ProcessUtil::execute(cmdLine, outResult); + SlangResult res = ProcessUtil::execute(cmdLine, outResult); + +#if 0 + { + printf("stdout=\"%s\"\nstderr=\"%s\"\nret=%d\n", outResult.standardOutput.getBuffer(), outResult.standardError.getBuffer(), int(outResult.resultCode)); + } +#endif + + return res; } /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CPPCompilerUtil !!!!!!!!!!!!!!!!!!!!!!*/ @@ -153,6 +161,16 @@ SlangResult CPPCompilerUtil::calcGCCFamilyVersion(const String& exeName, CPPComp // Display full path of source files in diagnostics cmdLine.addArg("/FC"); + if (options.flags & CompileOptions::Flag::EnableExceptionHandling) + { + if (options.sourceType == SourceType::CPP) + { + // https://docs.microsoft.com/en-us/cpp/build/reference/eh-exception-handling-model?view=vs-2019 + // Assumes c functions cannot throw + cmdLine.addArg("/EHsc"); + } + } + switch (options.optimizationLevel) { case OptimizationLevel::Debug: @@ -277,28 +295,12 @@ SlangResult CPPCompilerUtil::calcGCCFamilyVersion(const String& exeName, CPPComp { case TargetType::SharedLibrary: { + // Shared library + cmdLine.addArg("-shared"); // Position independent cmdLine.addArg("-fPIC"); - String sharedLibraryPath; - - // Work out the shared library name - { - String moduleDir = Path::getParentDirectory(options.modulePath); - String moduleFilename = Path::getFileName(options.modulePath); - - StringBuilder sharedLibraryFilename; - SharedLibrary::appendPlatformFileName(moduleFilename.getUnownedSlice(), sharedLibraryFilename); - - if (moduleDir.getLength() > 0) - { - sharedLibraryPath = Path::combine(moduleDir, sharedLibraryFilename); - } - else - { - sharedLibraryPath = sharedLibraryFilename; - } - } + String sharedLibraryPath = SharedLibrary::calcPlatformPath(options.modulePath.getUnownedSlice()); cmdLine.addArg("-o"); cmdLine.addArg(sharedLibraryPath); @@ -366,6 +368,12 @@ SlangResult CPPCompilerUtil::calcGCCFamilyVersion(const String& exeName, CPPComp cmdLine.addArg("-F"); cmdLine.addArg(libPath); } + + if (options.sourceType == SourceType::CPP) + { + // Make STD libs available + cmdLine.addArg("-lstdc++"); + } } static CPPCompiler::Desc _calcCompiledWithDesc() diff --git a/source/core/slang-cpp-compiler.h b/source/core/slang-cpp-compiler.h index 82930afd6..83c18bca2 100644 --- a/source/core/slang-cpp-compiler.h +++ b/source/core/slang-cpp-compiler.h @@ -23,6 +23,11 @@ public: GHS, CountOf, }; + enum class SourceType + { + C, ///< C source + CPP, ///< C++ source + }; struct Desc { @@ -70,9 +75,21 @@ public: struct CompileOptions { + typedef uint32_t Flags; + struct Flag + { + enum Enum : Flags + { + EnableExceptionHandling = 0x01, + }; + }; + OptimizationLevel optimizationLevel = OptimizationLevel::Debug; DebugInfoType debugInfoType = DebugInfoType::Normal; TargetType targetType = TargetType::Executable; + SourceType sourceType = SourceType::CPP; + + Flags flags = Flag::EnableExceptionHandling; String modulePath; ///< The path/name of the output module. Should not have the extension, as that will be added for each of the target types @@ -162,6 +179,7 @@ struct CPPCompilerUtil typedef CPPCompiler::OptimizationLevel OptimizationLevel; typedef CPPCompiler::TargetType TargetType; typedef CPPCompiler::DebugInfoType DebugInfoType; + typedef CPPCompiler::SourceType SourceType; enum class MatchType { diff --git a/source/core/slang-platform.cpp b/source/core/slang-platform.cpp index 1cb2bc56e..82f914f7d 100644 --- a/source/core/slang-platform.cpp +++ b/source/core/slang-platform.cpp @@ -2,6 +2,7 @@ #include "slang-platform.h" #include "slang-common.h" +#include "slang-io.h" #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN @@ -25,6 +26,25 @@ namespace Slang return loadWithPlatformFilename(builder.begin(), handleOut); } +/* static */String SharedLibrary::calcPlatformPath(const UnownedStringSlice& path) +{ + // Work out the shared library name + String parent = Path::getParentDirectory(path); + String filename = Path::getFileName(path); + + StringBuilder builder; + SharedLibrary::appendPlatformFileName(filename.getUnownedSlice(), builder); + + if (parent.getLength() > 0) + { + return Path::combine(parent, builder); + } + else + { + return builder; + } +} + #ifdef _WIN32 // Make sure SlangResult match for common standard window HRESULT @@ -105,8 +125,8 @@ SLANG_COMPILE_TIME_ASSERT(E_OUTOFMEMORY == SLANG_E_OUT_OF_MEMORY); /* static */void SharedLibrary::appendPlatformFileName(const UnownedStringSlice& name, StringBuilder& dst) { - // Windows doesn't need the extension or any prefix to work dst.Append(name); + dst.Append(".dll"); } #else // _WIN32 diff --git a/source/core/slang-platform.h b/source/core/slang-platform.h index e33c5599d..31552e42b 100644 --- a/source/core/slang-platform.h +++ b/source/core/slang-platform.h @@ -42,6 +42,9 @@ namespace Slang /// The input name should be unadorned with any 'lib' prefix or extension static void appendPlatformFileName(const UnownedStringSlice& name, StringBuilder& dst); + /// Calculate the shared library + static String calcPlatformPath(const UnownedStringSlice& path); + private: /// Not constructible! SharedLibrary(); |
