diff --git a/modules/juce_core/juce_core.cpp b/modules/juce_core/juce_core.cpp index 0c9b604f24..fd1a760425 100644 --- a/modules/juce_core/juce_core.cpp +++ b/modules/juce_core/juce_core.cpp @@ -72,6 +72,16 @@ #include #endif + #if JUCE_WASM + #include + #include + #include + #include + #include + #include + #include + #endif + #if JUCE_LINUX #include #include @@ -92,7 +102,7 @@ #include #include - #if ! JUCE_ANDROID + #if ! (JUCE_ANDROID || JUCE_WASM) #include #endif #endif @@ -230,14 +240,20 @@ #include "native/juce_android_Threads.cpp" #include "native/juce_android_RuntimePermissions.cpp" +#elif JUCE_WASM + #include "native/juce_wasm_SystemStats.cpp" + #endif -#include "threads/juce_ChildProcess.cpp" #include "threads/juce_HighResolutionTimer.cpp" #include "threads/juce_WaitableEvent.cpp" #include "network/juce_URL.cpp" -#include "network/juce_WebInputStream.cpp" -#include "streams/juce_URLInputSource.cpp" + +#if ! JUCE_WASM + #include "threads/juce_ChildProcess.cpp" + #include "network/juce_WebInputStream.cpp" + #include "streams/juce_URLInputSource.cpp" +#endif //============================================================================== #if JUCE_UNIT_TESTS diff --git a/modules/juce_core/native/juce_posix_IPAddress.h b/modules/juce_core/native/juce_posix_IPAddress.h index 41c83cd374..797174619d 100644 --- a/modules/juce_core/native/juce_posix_IPAddress.h +++ b/modules/juce_core/native/juce_posix_IPAddress.h @@ -25,6 +25,18 @@ namespace juce namespace { + struct InterfaceInfo + { + IPAddress interfaceAddress, broadcastAddress; + }; + + inline bool operator== (const InterfaceInfo& lhs, const InterfaceInfo& rhs) + { + return lhs.interfaceAddress == rhs.interfaceAddress + && lhs.broadcastAddress == rhs.broadcastAddress; + } + + #if ! JUCE_WASM static IPAddress makeAddress (const sockaddr_in6* addr_in) { if (addr_in == nullptr) @@ -54,17 +66,6 @@ namespace return IPAddress (ntohl (addr_in->sin_addr.s_addr)); } - struct InterfaceInfo - { - IPAddress interfaceAddress, broadcastAddress; - }; - - bool operator== (const InterfaceInfo& lhs, const InterfaceInfo& rhs) - { - return lhs.interfaceAddress == rhs.interfaceAddress - && lhs.broadcastAddress == rhs.broadcastAddress; - } - bool populateInterfaceInfo (struct ifaddrs* ifa, InterfaceInfo& interfaceInfo) { if (ifa->ifa_addr != nullptr) @@ -91,10 +92,15 @@ namespace return false; } + #endif Array getAllInterfaceInfo() { Array interfaces; + + #if JUCE_WASM + // TODO + #else struct ifaddrs* ifaddr = nullptr; if (getifaddrs (&ifaddr) != -1) @@ -109,6 +115,7 @@ namespace freeifaddrs (ifaddr); } + #endif return interfaces; } diff --git a/modules/juce_core/native/juce_posix_NamedPipe.cpp b/modules/juce_core/native/juce_posix_NamedPipe.cpp index e48ad25691..8b14f16d3a 100644 --- a/modules/juce_core/native/juce_posix_NamedPipe.cpp +++ b/modules/juce_core/native/juce_posix_NamedPipe.cpp @@ -23,6 +23,8 @@ namespace juce { +#if ! JUCE_WASM + class NamedPipe::Pimpl { public: @@ -241,4 +243,6 @@ int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOut return pimpl != nullptr ? pimpl->write (static_cast (sourceBuffer), numBytesToWrite, timeOutMilliseconds) : -1; } +#endif + } // namespace juce diff --git a/modules/juce_core/native/juce_posix_SharedCode.h b/modules/juce_core/native/juce_posix_SharedCode.h index 5b76af7f6d..082a5697a6 100644 --- a/modules/juce_core/native/juce_posix_SharedCode.h +++ b/modules/juce_core/native/juce_posix_SharedCode.h @@ -130,16 +130,20 @@ bool File::setAsCurrentWorkingDirectory() const return chdir (getFullPathName().toUTF8()) == 0; } -#if JUCE_ANDROID - using juce_sigactionflags_type = unsigned long; -#else - using juce_sigactionflags_type = int; -#endif - //============================================================================== // The unix siginterrupt function is deprecated - this does the same job. int juce_siginterrupt (int sig, int flag) { + #if JUCE_WASM + ignoreUnused (sig, flag); + return 0; + #else + #if JUCE_ANDROID + using juce_sigactionflags_type = unsigned long; + #else + using juce_sigactionflags_type = int; + #endif + struct ::sigaction act; (void) ::sigaction (sig, nullptr, &act); @@ -149,6 +153,7 @@ int juce_siginterrupt (int sig, int flag) act.sa_flags |= static_cast (SA_RESTART); return ::sigaction (sig, &act, nullptr); + #endif } //============================================================================== @@ -168,6 +173,7 @@ namespace && JUCE_STAT (fileName.toUTF8(), &info) == 0; } + #if ! JUCE_WASM // if this file doesn't exist, find a parent of it that does.. bool juce_doStatFS (File f, struct statfs& result) { @@ -205,6 +211,7 @@ namespace if (isReadOnly != nullptr) *isReadOnly = access (path.toUTF8(), W_OK) != 0; } + #endif Result getResultForErrno() { @@ -329,6 +336,7 @@ void File::getFileTimesInternal (int64& modificationTime, int64& accessTime, int bool File::setFileTimesInternal (int64 modificationTime, int64 accessTime, int64 /*creationTime*/) const { + #if ! JUCE_WASM juce_statStruct info; if ((modificationTime != 0 || accessTime != 0) && juce_stat (fullPath, info)) @@ -360,6 +368,7 @@ bool File::setFileTimesInternal (int64 modificationTime, int64 accessTime, int64 return utime (fullPath.toUTF8(), ×) == 0; #endif } + #endif return false; } @@ -533,6 +542,7 @@ String SystemStats::getEnvironmentVariable (const String& name, const String& de } //============================================================================== +#if ! JUCE_WASM void MemoryMappedFile::openInternal (const File& file, AccessMode mode, bool exclusive) { jassert (mode == readOnly || mode == readWrite); @@ -659,6 +669,8 @@ int File::getVolumeSerialNumber() const return 0; } +#endif + //============================================================================== #if ! JUCE_IOS void juce_runSystemCommand (const String&); @@ -1010,6 +1022,7 @@ void JUCE_CALLTYPE Thread::setCurrentThreadAffinityMask (uint32 affinityMask) } //============================================================================== +#if ! JUCE_WASM bool DynamicLibrary::open (const String& name) { close(); @@ -1031,7 +1044,6 @@ void* DynamicLibrary::getFunction (const String& functionName) noexcept return handle != nullptr ? dlsym (handle, functionName.toUTF8()) : nullptr; } - //============================================================================== #if JUCE_LINUX || JUCE_ANDROID static String readPosixConfigFileValue (const char* file, const char* key) @@ -1221,6 +1233,8 @@ bool ChildProcess::start (const StringArray& args, int streamFlags) return activeProcess != nullptr; } +#endif + //============================================================================== struct HighResolutionTimer::Pimpl { diff --git a/modules/juce_core/native/juce_wasm_SystemStats.cpp b/modules/juce_core/native/juce_wasm_SystemStats.cpp new file mode 100644 index 0000000000..118f9d812a --- /dev/null +++ b/modules/juce_core/native/juce_wasm_SystemStats.cpp @@ -0,0 +1,87 @@ +/* + ============================================================================== + + This file is part of the JUCE library. + Copyright (c) 2020 - Raw Material Software Limited + + JUCE is an open source library subject to commercial or open-source + licensing. + + The code included in this file is provided under the terms of the ISC license + http://www.isc.org/downloads/software-support-policy/isc-license. Permission + To use, copy, modify, and/or distribute this software for any purpose with or + without fee is hereby granted provided that the above copyright notice and + this permission notice appear in all copies. + + JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER + EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE + DISCLAIMED. + + ============================================================================== +*/ + +namespace juce +{ + +void Logger::outputDebugString (const String& text) +{ + std::cerr << text << std::endl; +} + +//============================================================================== +SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() { return WASM; } +String SystemStats::getOperatingSystemName() { return "WASM"; } +bool SystemStats::isOperatingSystem64Bit() { return true; } +String SystemStats::getDeviceDescription() { return "Web-browser"; } +String SystemStats::getDeviceManufacturer() { return {}; } +String SystemStats::getCpuVendor() { return {}; } +String SystemStats::getCpuModel() { return {}; } +int SystemStats::getCpuSpeedInMegahertz() { return 0; } +int SystemStats::getMemorySizeInMegabytes() { return 0; } +int SystemStats::getPageSize() { return 0; } +String SystemStats::getLogonName() { return {}; } +String SystemStats::getFullUserName() { return {}; } +String SystemStats::getComputerName() { return {}; } +String SystemStats::getUserLanguage() { return {}; } +String SystemStats::getUserRegion() { return {}; } +String SystemStats::getDisplayLanguage() { return {}; } + +//============================================================================== +void CPUInformation::initialise() noexcept +{ + numLogicalCPUs = 1; + numPhysicalCPUs = 1; +} + +//============================================================================== +uint32 juce_millisecondsSinceStartup() noexcept +{ + return static_cast (emscripten_get_now()); +} + +int64 Time::getHighResolutionTicks() noexcept +{ + return static_cast (emscripten_get_now() * 1000.0); +} + +int64 Time::getHighResolutionTicksPerSecond() noexcept +{ + return 1000000; // (microseconds) +} + +double Time::getMillisecondCounterHiRes() noexcept +{ + return emscripten_get_now(); +} + +bool Time::setSystemTimeToThisTime() const +{ + return false; +} + +JUCE_API bool JUCE_CALLTYPE juce_isRunningUnderDebugger() noexcept +{ + return false; +} + +} // namespace juce diff --git a/modules/juce_core/network/juce_NamedPipe.cpp b/modules/juce_core/network/juce_NamedPipe.cpp index c39ac66d6e..a4a26ecfc7 100644 --- a/modules/juce_core/network/juce_NamedPipe.cpp +++ b/modules/juce_core/network/juce_NamedPipe.cpp @@ -23,6 +23,8 @@ namespace juce { +#if ! JUCE_WASM + NamedPipe::NamedPipe() {} NamedPipe::~NamedPipe() @@ -265,6 +267,7 @@ private: static NamedPipeTests namedPipeTests; +#endif #endif } // namespace juce diff --git a/modules/juce_core/network/juce_Socket.cpp b/modules/juce_core/network/juce_Socket.cpp index 64168aa721..a43cb141db 100644 --- a/modules/juce_core/network/juce_Socket.cpp +++ b/modules/juce_core/network/juce_Socket.cpp @@ -23,6 +23,8 @@ namespace juce { +#if ! JUCE_WASM + JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4127 4389 4018) #ifndef AI_NUMERICSERV // (missing in older Mac SDKs) @@ -857,6 +859,7 @@ struct SocketTests : public UnitTest static SocketTests socketTests; +#endif #endif } // namespace juce diff --git a/modules/juce_core/system/juce_SystemStats.cpp b/modules/juce_core/system/juce_SystemStats.cpp index 847127162f..813a23b298 100644 --- a/modules/juce_core/system/juce_SystemStats.cpp +++ b/modules/juce_core/system/juce_SystemStats.cpp @@ -138,7 +138,7 @@ String SystemStats::getStackBacktrace() { String result; - #if JUCE_ANDROID || JUCE_MINGW + #if JUCE_ANDROID || JUCE_MINGW || JUCE_WASM jassertfalse; // sorry, not implemented yet! #elif JUCE_WINDOWS @@ -187,6 +187,8 @@ String SystemStats::getStackBacktrace() } //============================================================================== +#if ! JUCE_WASM + static SystemStats::CrashHandlerFunction globalCrashHandler = nullptr; #if JUCE_WINDOWS @@ -223,6 +225,8 @@ void SystemStats::setApplicationCrashHandler (CrashHandlerFunction handler) #endif } +#endif + bool SystemStats::isRunningInAppExtensionSandbox() noexcept { #if JUCE_MAC || JUCE_IOS diff --git a/modules/juce_core/system/juce_SystemStats.h b/modules/juce_core/system/juce_SystemStats.h index 5e4d2b1074..d42a185c3e 100644 --- a/modules/juce_core/system/juce_SystemStats.h +++ b/modules/juce_core/system/juce_SystemStats.h @@ -51,6 +51,7 @@ public: Linux = 0x0400, Android = 0x0800, iOS = 0x1000, + WASM = 0x2000, MacOSX_10_7 = MacOSX | 7, MacOSX_10_8 = MacOSX | 8, diff --git a/modules/juce_core/system/juce_TargetPlatform.h b/modules/juce_core/system/juce_TargetPlatform.h index d0530b48cf..5b4d293bb6 100644 --- a/modules/juce_core/system/juce_TargetPlatform.h +++ b/modules/juce_core/system/juce_TargetPlatform.h @@ -65,7 +65,7 @@ #elif defined (__FreeBSD__) || (__OpenBSD__) #define JUCE_BSD 1 #elif defined (LINUX) || defined (__linux__) - #define JUCE_LINUX 1 + #define JUCE_LINUX 1 #elif defined (__APPLE_CPP__) || defined (__APPLE_CC__) #define CF_EXCLUDE_CSTD_HEADERS 1 #include // (needed to find out what platform we're using) @@ -78,6 +78,8 @@ #else #define JUCE_MAC 1 #endif +#elif defined (__wasm__) + #define JUCE_WASM 1 #else #error "Unknown platform!" #endif diff --git a/modules/juce_graphics/image_formats/juce_PNGLoader.cpp b/modules/juce_graphics/image_formats/juce_PNGLoader.cpp index 79418fb84d..210632bf86 100644 --- a/modules/juce_graphics/image_formats/juce_PNGLoader.cpp +++ b/modules/juce_graphics/image_formats/juce_PNGLoader.cpp @@ -73,6 +73,10 @@ namespace pnglibNamespace #define PNG_ARM_NEON_SUPPORTED #endif + #ifndef Byte + using Byte = uint8_t; + #endif + #define PNG_16BIT_SUPPORTED #define PNG_ALIGNED_MEMORY_SUPPORTED #define PNG_BENIGN_ERRORS_SUPPORTED