Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions dtool/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,18 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options("-fno-semantic-interposition")
endif()
endif()




if(WASI)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WASI_EMULATED_MMAN -D_WASI_EMULATED_PROCESS_CLOCKS")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lwasi-emulated-mman -lwasi-emulated-process-clocks -lwasi-emulated-getpid")
set(cxx_exceptions_off)
set(cxx_rtti_off)
endif()





5 changes: 5 additions & 0 deletions dtool/src/dtoolutil/filename.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#include <sys/stat.h>
#include <algorithm>

// lockf and tempnam
#if defined(__wasi__)
#include "wasi.c"
#endif // __wasi__

#ifdef PHAVE_UTIME_H
#include <utime.h>
#endif
Expand Down
98 changes: 98 additions & 0 deletions dtool/src/dtoolutil/wasi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#pragma once

extern "C" {

#define PHAVE_LOCKF

static int
lockf(int fd, int cmd, off_t len) {
return 0;
}

#define P_tmpdir "/tmp"
#define LOCK_EX 2
#define LOCK_NB 4

static FILE *
popen(const char *command, const char *type){
return NULL;
}
static char *
__randname(char *tmpl)
{
int i;
struct timespec ts;
unsigned long r;

clock_gettime(CLOCK_REALTIME, &ts);
r = ts.tv_nsec*65537 ^ (uintptr_t)&ts / 16 + (uintptr_t)tmpl;
for (i=0; i<6; i++, r>>=5)
tmpl[i] = 'A'+(r&15)+(r&16)*2;

return tmpl;
}

static char *
mktemp(char *tmpl)
{
size_t l = strlen(tmpl);
int retries = 100;
struct stat st;

if (l < 6 || memcmp(tmpl+l-6, "XXXXXX", 6)) {
errno = EINVAL;
*tmpl = 0;
return tmpl;
}

do {
__randname(tmpl+l-6);
if (stat(tmpl, &st)) {
if (errno != ENOENT) *tmpl = 0;
return tmpl;
}
} while (--retries);

*tmpl = 0;
errno = EEXIST;
return tmpl;
}

static int
mkstemp(char *tmpl) {
FILE *ftemp = fopen(mktemp(tmpl),"w");
return fileno(ftemp);
}

static char *
tempnam (const char *dir, const char *pfx)
{
char buf[FILENAME_MAX];
int all;
char *ptr;
int dirlen = strlen(dir);
if (dirlen>=FILENAME_MAX)
return NULL;

memcpy(buf,dir,FILENAME_MAX);
buf[dirlen] = '/';


if (pfx) {
all = dirlen + 1 + strlen(pfx);
if (all>=FILENAME_MAX)
return NULL;
memcpy(buf+dirlen+1, pfx, FILENAME_MAX - all);
} else {
all = dirlen + 1;
}

memcpy(buf+all, "XXXXXX", 6 );
all += 6 ;
buf[all]= 0;
ptr = (char *)malloc(all);
memcpy(ptr, buf, all);
return mktemp(ptr);
}

} // extern "C"
2 changes: 1 addition & 1 deletion panda/src/audiotraits/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if(NOT HAVE_AUDIO)
return()
elseif(NOT HAVE_FMODEX AND NOT HAVE_OPENAL)
message(SEND_ERROR
message(WARNING
"You must have an audio backend for audio support! Turn off HAVE_AUDIO to ignore this.")
endif()

Expand Down
5 changes: 5 additions & 0 deletions panda/src/gobj/vertexDataSaveFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
#include <sys/file.h>
#endif

// Needed for lockf
#if defined(__wasi__)
#include "wasi.c"
#endif // __wasi__

using std::dec;
using std::hex;

Expand Down
11 changes: 11 additions & 0 deletions panda/src/testbed/pview.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@

using std::cerr;
using std::endl;
#if defined(__wasi__)
extern "C" {
int __cxa_allocate_exception(int discard) {
abort();
}

int __cxa_throw(int discarda, int discardb) {
abort();
}
}
#endif

PandaFramework framework;

Expand Down
Loading