From 3572d52ace485884d7abbcef365d04cd4dd95020 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Mon, 14 Mar 2022 16:52:33 +0100 Subject: [PATCH] Adds EMSCRIPTEN preprocessor definition to libsolidity build & avoid accessing filesystem::current_path() if building for Emscripten. --- libsolidity/CMakeLists.txt | 4 ++++ libsolidity/interface/FileReader.cpp | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libsolidity/CMakeLists.txt b/libsolidity/CMakeLists.txt index 3d2845463..b686f94c1 100644 --- a/libsolidity/CMakeLists.txt +++ b/libsolidity/CMakeLists.txt @@ -176,3 +176,7 @@ set(sources add_library(solidity ${sources}) target_link_libraries(solidity PUBLIC yul evmasm langutil smtutil solutil Boost::boost fmt::fmt-header-only) + +if(EMSCRIPTEN) + target_compile_definitions(solidity PRIVATE EMSCRIPTEN=1) +endif() diff --git a/libsolidity/interface/FileReader.cpp b/libsolidity/interface/FileReader.cpp index 8300feb57..67c144c52 100644 --- a/libsolidity/interface/FileReader.cpp +++ b/libsolidity/interface/FileReader.cpp @@ -244,7 +244,13 @@ boost::filesystem::path FileReader::normalizeCLIPathForVFS( // - Preserves case. Even if the filesystem is case-insensitive but case-preserving and the // case differs, the actual case from disk is NOT detected. - boost::filesystem::path canonicalWorkDir = boost::filesystem::weakly_canonical(boost::filesystem::current_path()); + boost::filesystem::path canonicalWorkDir = +#if defined(EMSCRIPTEN) + boost::filesystem::path("/") +#else + boost::filesystem::weakly_canonical(boost::filesystem::current_path()) +#endif + ; // NOTE: On UNIX systems the path returned from current_path() has symlinks resolved while on // Windows it does not. To get consistent results we resolve them on all platforms.