Skip to content

Commit

Permalink
[Misc] Extract define for loadable library filename extension to header
Browse files Browse the repository at this point in the history
Signed-off-by: Shen-Ta Hsieh <[email protected]>
  • Loading branch information
ibmibmibm authored and hydai committed Jun 14, 2022
1 parent cb66b63 commit f865b15
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 53 deletions.
3 changes: 3 additions & 0 deletions include/common/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,23 @@
#define WASMEDGE_OS_LINUX 1
#define WASMEDGE_OS_MACOS 0
#define WASMEDGE_OS_WINDOWS 0
#define WASMEDGE_LIB_EXTENSION ".so"

#elif defined(macintosh) || defined(Macintosh) || \
(defined(__APPLE__) && defined(__MACH__))

#define WASMEDGE_OS_LINUX 0
#define WASMEDGE_OS_MACOS 1
#define WASMEDGE_OS_WINDOWS 0
#define WASMEDGE_LIB_EXTENSION ".dylib"

#elif defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || \
defined(__TOS_WIN__) || defined(__WINDOWS__)

#define WASMEDGE_OS_LINUX 0
#define WASMEDGE_OS_MACOS 0
#define WASMEDGE_OS_WINDOWS 1
#define WASMEDGE_LIB_EXTENSION ".dll"

#else

Expand Down
5 changes: 1 addition & 4 deletions lib/aot/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,10 @@
#endif

#if WASMEDGE_OS_LINUX
#define EXTENSION ".so"sv
#define SYMBOL(X) X
#elif WASMEDGE_OS_MACOS
#define EXTENSION ".dylib"sv
#define SYMBOL(X) "_" X
#elif WASMEDGE_OS_WINDOWS
#define EXTENSION ".dll"sv
#define SYMBOL(X) X
#endif

Expand Down Expand Up @@ -4758,7 +4755,7 @@ Expect<void> outputWasmLibrary(const std::filesystem::path &OutputPath,
{
// tempfile
std::filesystem::path SOPath(OutputPath);
SOPath.replace_extension("%%%%%%%%%%" EXTENSION);
SOPath.replace_extension("%%%%%%%%%%" WASMEDGE_LIB_EXTENSION);
auto Object = llvm::sys::fs::TempFile::create(SOPath.u8string());
if (!Object) {
// TODO:return error
Expand Down
11 changes: 2 additions & 9 deletions lib/plugin/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@ std::vector<std::filesystem::path> Plugin::getDefaultPluginPaths() noexcept {
}

bool Plugin::load(const std::filesystem::path &Path) noexcept {
#if WASMEDGE_OS_LINUX
const auto Extension = ".so"sv;
#elif WASMEDGE_OS_MACOS
const auto Extension = ".dylib"sv;
#elif WASMEDGE_OS_WINDOWS
const auto Extension = ".dll"sv;
#endif
std::error_code Error;
auto Status = std::filesystem::status(Path, Error);
if (likely(!Error)) {
Expand All @@ -103,13 +96,13 @@ bool Plugin::load(const std::filesystem::path &Path) noexcept {
Error)) {
const auto &EntryPath = Entry.path();
if (Entry.is_regular_file(Error) &&
EntryPath.extension().u8string() == Extension) {
EntryPath.extension().u8string() == WASMEDGE_LIB_EXTENSION) {
Result |= loadFile(EntryPath);
}
}
return Result;
} else if (std::filesystem::is_regular_file(Status) &&
Path.extension().u8string() == Extension) {
Path.extension().u8string() == WASMEDGE_LIB_EXTENSION) {
return loadFile(Path);
}
}
Expand Down
14 changes: 3 additions & 11 deletions test/aot/AOTcoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@
#include <utility>
#include <vector>

#if WASMEDGE_OS_LINUX
#define EXTENSION ".so"sv
#elif WASMEDGE_OS_MACOS
#define EXTENSION ".dylib"sv
#elif WASMEDGE_OS_WINDOWS
#define EXTENSION ".dll"sv
#endif

namespace {

using namespace std::literals;
Expand Down Expand Up @@ -70,7 +62,7 @@ TEST_P(NativeCoreTest, TestSuites) {
CopyConf.getCompilerConfigure().setDumpIR(true);
WasmEdge::AOT::Compiler Compiler(CopyConf);
auto Path = std::filesystem::u8path(Filename);
Path.replace_extension(std::filesystem::u8path(EXTENSION));
Path.replace_extension(std::filesystem::u8path(WASMEDGE_LIB_EXTENSION));
const auto SOPath = Path.u8string();
auto Data = *Loader.loadFile(Filename);
std::unique_ptr<WasmEdge::AST::Module> Module;
Expand Down Expand Up @@ -289,7 +281,7 @@ TEST(AsyncRunWsmFile, NativeInterruptTest) {
WasmEdge::Validator::Validator ValidatorEngine(Conf);
WasmEdge::AOT::Compiler Compiler(Conf);
auto Path = std::filesystem::temp_directory_path() /
std::filesystem::u8path("AOTcoreTest" EXTENSION);
std::filesystem::u8path("AOTcoreTest" WASMEDGE_LIB_EXTENSION);
auto Module = *Loader.parseModule(Wasm);
ASSERT_TRUE(ValidatorEngine.validate(*Module));
ASSERT_TRUE(Compiler.compile(Wasm, *Module, Path));
Expand Down Expand Up @@ -331,7 +323,7 @@ TEST(AsyncExecute, NativeInterruptTest) {
WasmEdge::Validator::Validator ValidatorEngine(Conf);
WasmEdge::AOT::Compiler Compiler(Conf);
auto Path = std::filesystem::temp_directory_path() /
std::filesystem::u8path("AOTcoreTest" EXTENSION);
std::filesystem::u8path("AOTcoreTest" WASMEDGE_LIB_EXTENSION);
auto Module = *Loader.parseModule(Wasm);
ASSERT_TRUE(ValidatorEngine.validate(*Module));
ASSERT_TRUE(Compiler.compile(Wasm, *Module, Path));
Expand Down
10 changes: 1 addition & 9 deletions test/api/APIAOTCoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@
#include <utility>
#include <vector>

#if WASMEDGE_OS_LINUX
#define EXTENSION ".so"sv
#elif WASMEDGE_OS_MACOS
#define EXTENSION ".dylib"sv
#elif WASMEDGE_OS_WINDOWS
#define EXTENSION ".dll"sv
#endif

namespace {
using namespace std::literals;
using namespace WasmEdge;
Expand All @@ -62,7 +54,7 @@ TEST_P(CoreTest, TestSuites) {
auto Compile = [&, Conf = std::cref(Conf)](
const std::string &Filename) -> Expect<std::string> {
auto Path = std::filesystem::u8path(Filename);
Path.replace_extension(std::filesystem::u8path(EXTENSION));
Path.replace_extension(std::filesystem::u8path(WASMEDGE_LIB_EXTENSION));
const auto SOPath = Path.u8string();
WasmEdge_Result Res =
WasmEdge_CompilerCompile(CompilerCxt, Filename.c_str(), SOPath.c_str());
Expand Down
15 changes: 4 additions & 11 deletions test/thread/ThreadTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,21 +225,14 @@ TEST(AsyncExecute, GasThreadTest) {

#ifdef WASMEDGE_BUILD_AOT_RUNTIME

#if WASMEDGE_OS_LINUX
#define EXTENSION ".so"sv
#elif WASMEDGE_OS_MACOS
#define EXTENSION ".dylib"sv
#elif WASMEDGE_OS_WINDOWS
#define EXTENSION ".dll"sv
#endif

TEST(AOTAsyncExecute, ThreadTest) {
WasmEdge::Configure Conf;
Conf.getCompilerConfigure().setInterruptible(true);
Conf.getCompilerConfigure().setOutputFormat(
WasmEdge::CompilerConfigure::OutputFormat::Native);
const auto Path = std::filesystem::temp_directory_path() /
std::filesystem::u8path("ThreadTest" EXTENSION);
const auto Path =
std::filesystem::temp_directory_path() /
std::filesystem::u8path("ThreadTest" WASMEDGE_LIB_EXTENSION);
{
WasmEdge::Loader::Loader Loader(Conf);
WasmEdge::Validator::Validator ValidatorEngine(Conf);
Expand Down Expand Up @@ -285,7 +278,7 @@ TEST(AOTAsyncExecute, GasThreadTest) {
Conf.getCompilerConfigure().setOutputFormat(
WasmEdge::CompilerConfigure::OutputFormat::Native);
auto Path = std::filesystem::temp_directory_path() /
std::filesystem::u8path("AOTGasTest" EXTENSION);
std::filesystem::u8path("AOTGasTest" WASMEDGE_LIB_EXTENSION);

{
WasmEdge::Loader::Loader Loader(Conf);
Expand Down
10 changes: 1 addition & 9 deletions tools/wasmedge/wasmedgec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@
#include <utility>
#include <vector>

#if WASMEDGE_OS_LINUX
#define EXTENSION ".so"sv
#elif WASMEDGE_OS_MACOS
#define EXTENSION ".dylib"sv
#elif WASMEDGE_OS_WINDOWS
#define EXTENSION ".dll"sv
#endif

int main(int Argc, const char *Argv[]) {
namespace PO = WasmEdge::PO;
using namespace std::literals;
Expand Down Expand Up @@ -207,7 +199,7 @@ int main(int Argc, const char *Argv[]) {
if (ConfGenericBinary.value()) {
Conf.getCompilerConfigure().setGenericBinary(true);
}
if (OutputPath.extension().u8string() == EXTENSION) {
if (OutputPath.extension().u8string() == WASMEDGE_LIB_EXTENSION) {
Conf.getCompilerConfigure().setOutputFormat(
WasmEdge::CompilerConfigure::OutputFormat::Native);
}
Expand Down

0 comments on commit f865b15

Please sign in to comment.