1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Tweaks for emscripten support

This commit is contained in:
jules 2020-12-17 15:35:32 +00:00 committed by ed
parent 8b075242d4
commit a9b5fe3a39
11 changed files with 169 additions and 24 deletions

View file

@ -72,6 +72,16 @@
#include <netinet/in.h>
#endif
#if JUCE_WASM
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/stat.h>
#endif
#if JUCE_LINUX
#include <stdio.h>
#include <langinfo.h>
@ -92,7 +102,7 @@
#include <net/if.h>
#include <sys/ioctl.h>
#if ! JUCE_ANDROID
#if ! (JUCE_ANDROID || JUCE_WASM)
#include <execinfo.h>
#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

View file

@ -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<InterfaceInfo> getAllInterfaceInfo()
{
Array<InterfaceInfo> interfaces;
#if JUCE_WASM
// TODO
#else
struct ifaddrs* ifaddr = nullptr;
if (getifaddrs (&ifaddr) != -1)
@ -109,6 +115,7 @@ namespace
freeifaddrs (ifaddr);
}
#endif
return interfaces;
}

View file

@ -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<const char*> (sourceBuffer), numBytesToWrite, timeOutMilliseconds) : -1;
}
#endif
} // namespace juce

View file

@ -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<juce_sigactionflags_type> (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(), &times) == 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
{

View file

@ -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<uint32> (emscripten_get_now());
}
int64 Time::getHighResolutionTicks() noexcept
{
return static_cast<int64> (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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -51,6 +51,7 @@ public:
Linux = 0x0400,
Android = 0x0800,
iOS = 0x1000,
WASM = 0x2000,
MacOSX_10_7 = MacOSX | 7,
MacOSX_10_8 = MacOSX | 8,

View file

@ -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 <TargetConditionals.h> // (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

View file

@ -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