diff --git a/src/Makefile b/src/Makefile index 855dcb45e..14fe136dd 100644 --- a/src/Makefile +++ b/src/Makefile @@ -298,6 +298,7 @@ endif CXXFLAGS+=$(MYCXXFLAGS) CFLAGS+=$(MYCFLAGS) LDFLAGS+=$(MYLDFLAGS) +SOLDFLAGS+=$(MYSOLDFLAGS) all: luacartesi libcartesi.a grpc hash c-api jsonrpc-remote-cartesi-machine diff --git a/src/json-util.h b/src/json-util.h index cfcd3f919..ae61a166c 100644 --- a/src/json-util.h +++ b/src/json-util.h @@ -21,6 +21,8 @@ #include #include +// Disable JSON filesystem support because it is not supported in some targets +#define JSON_HAS_FILESYSTEM 0 #include #include "base64.h" diff --git a/src/jsonrpc-remote-machine.cpp b/src/jsonrpc-remote-machine.cpp index d086f618a..c6738784f 100644 --- a/src/jsonrpc-remote-machine.cpp +++ b/src/jsonrpc-remote-machine.cpp @@ -37,7 +37,6 @@ #include #include -#include #include #include "base64.h" diff --git a/src/jsonrpc-virtual-machine.cpp b/src/jsonrpc-virtual-machine.cpp index 939630c11..335f1289f 100644 --- a/src/jsonrpc-virtual-machine.cpp +++ b/src/jsonrpc-virtual-machine.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include "jsonrpc-mg-mgr.h" diff --git a/src/machine.cpp b/src/machine.cpp index bf0fa4ea3..2c86e9250 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include "clint-factory.h" @@ -46,6 +45,13 @@ #include "uarch-step.h" #include "unique-c-ptr.h" +#ifdef _WIN32 +#include // mkdir +#define mkdir(a, b) _mkdir(a) +#else +#include // mkdir +#endif + /// \file /// \brief Cartesi machine implementation diff --git a/src/pma.cpp b/src/pma.cpp index 5fc23b650..19f5bddfd 100644 --- a/src/pma.cpp +++ b/src/pma.cpp @@ -14,11 +14,6 @@ // with this program (see COPYING). If not, see . // -#include // open -#include // mmap, munmap -#include // fstat -#include // close - #include #include #include @@ -27,14 +22,27 @@ #include "pma.h" #include "unique-c-ptr.h" +#if (defined(_WIN32) || defined(__wasi__)) && !defined(NO_MMAP) +#define NO_MMAP +#endif + +#ifndef NO_MMAP +#include // open +#include // mmap, munmap +#include // fstat +#include // close +#endif + namespace cartesi { using namespace std::string_literals; void pma_memory::release(void) { if (m_backing_file >= 0) { +#ifndef NO_MMAP munmap(m_host_memory, m_length); close(m_backing_file); +#endif m_backing_file = -1; } else { std::free(m_host_memory); // NOLINT(cppcoreguidelines-no-malloc) @@ -111,6 +119,7 @@ pma_memory::pma_memory(const std::string &description, uint64_t length, const st } } +#ifndef NO_MMAP pma_memory::pma_memory(const std::string &description, uint64_t length, const std::string &path, const mmapd &m) : m_length{length}, m_host_memory{nullptr}, @@ -158,6 +167,17 @@ pma_memory::pma_memory(const std::string &description, uint64_t length, const st m_host_memory = host_memory; m_backing_file = backing_file; } +#else +pma_memory::pma_memory(const std::string &description, uint64_t length, const std::string &path, const mmapd &m) : + pma_memory(description, length, path, callocd{}) { + if (path.empty()) { + throw std::runtime_error{"image file must be specified for "s + description}; + } + if (m.shared) { + throw std::runtime_error{"shared image is unsupported, when initialization "s + description}; + } +} +#endif pma_memory &pma_memory::operator=(pma_memory &&other) noexcept { release(); diff --git a/src/test-machine-c-api.cpp b/src/test-machine-c-api.cpp index 85e17f92b..4d2ab8c35 100644 --- a/src/test-machine-c-api.cpp +++ b/src/test-machine-c-api.cpp @@ -20,9 +20,8 @@ #include #include -#include - #include "grpc-machine-c-api.h" +#include "json-util.h" #include "machine-c-api.h" #include "riscv-constants.h" #include "test-utils.h" diff --git a/src/tty.cpp b/src/tty.cpp index b219d16de..bc003c323 100644 --- a/src/tty.cpp +++ b/src/tty.cpp @@ -15,16 +15,26 @@ // #include -#include #include -#include #include -#include -#include -#include + +#if (defined(_WIN32)) && !defined(NO_STDIN_READ) +#define NO_STDIN_READ +#endif + +#ifndef NO_STDIN_READ +#include // select +#endif + +#include // write/read/close + +#if (defined(_WIN32) || defined(__wasi__)) && !defined(NO_TERMIOS) +#define NO_TERMIOS +#endif #ifndef NO_TERMIOS -#include +#include // open +#include // tcgetattr/tcsetattr #endif #include "tty.h" @@ -74,6 +84,7 @@ static int get_ttyfd(void) { #endif static bool try_read_chars_from_stdin(uint64_t wait, char *data, size_t max_len, ssize_t *actual_len) { +#ifndef NO_STDIN_READ const int fd_max{0}; fd_set rfds{}; timeval tv{}; @@ -90,6 +101,14 @@ static bool try_read_chars_from_stdin(uint64_t wait, char *data, size_t max_len, return true; } return false; +#else + // No support for reading console inputs for Windows yet + (void) wait; + (void) data; + (void) max_len; + (void) actual_len; + return false; +#endif } /// Returns pointer to the global TTY state