Skip to content
Merged
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
2 changes: 1 addition & 1 deletion emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ def default_setting(name, new_default):
state.forced_stdlibs.append('libwasmfs')
settings.FILESYSTEM = 0
settings.SYSCALLS_REQUIRE_FILESYSTEM = 0
settings.JS_LIBRARIES.append((0, 'library_wasmfs.js'))
# settings.JS_LIBRARIES.append((0, 'library_wasmfs.js')) TODO: populate with library_wasmfs.js later

# Explicitly drop linking in a malloc implementation if program is not using any dynamic allocation calls.
if not settings.USES_DYNAMIC_ALLOC:
Expand Down
16 changes: 1 addition & 15 deletions src/library_wasmfs.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
var WasmfsLibrary = {
$wasmfsBuffers: [null, [], []],
emscripten_wasmfs_printbuffer__deps: ['$wasmfsBuffers'],
emscripten_wasmfs_printbuffer: function(stream, ptr, len) {
for (var j = 0; j < len; j++) {
if (HEAPU8[ptr+j] === 0 || HEAPU8[ptr+j] === 10) {
(stream === 1 ? out : err)(UTF8ArrayToString(wasmfsBuffers[stream], 0));
wasmfsBuffers[stream].length = 0;
} else {
wasmfsBuffers[stream].push(HEAPU8[ptr+j]);
}
}

}
}
var WasmfsLibrary = {}

mergeInto(LibraryManager.library, WasmfsLibrary);
5 changes: 2 additions & 3 deletions src/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ var LibraryManager = {
}
libraries.push('library_noderawfs.js');
}
} else {
libraries.push('library_wasmfs.js');
}
}
// TODO: populate with libraries.push('library_wasmfs.js') later

// Additional JS libraries (without AUTO_JS_LIBRARIES, link to these explicitly via -lxxx.js)
if (AUTO_JS_LIBRARIES) {
Expand Down
22 changes: 18 additions & 4 deletions system/lib/wasmfs/wasmfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,39 @@
#include <emscripten/emscripten.h>
#include <emscripten/html5.h>
#include <stdlib.h>
#include <vector>
#include <wasi/api.h>

extern "C" {

int emscripten_wasmfs_printbuffer(__wasi_fd_t fd, const uint8_t* ptr, __wasi_size_t len);
static std::vector<char> fd_write_stdstream_buffer;

__wasi_errno_t __wasi_fd_write(
__wasi_fd_t fd, const __wasi_ciovec_t* iovs, size_t iovs_len, __wasi_size_t* nwritten) {
// FD 1 = STDOUT and FD 2 = STDERR.
// Temporary hardcoding of filedescriptor values.
// TODO: May not want to proxy stderr (fd == 2) to the main thread.
// This will not not show in HTML, a console.warn in a worker is suffficient.
// This will not show in HTML - a console.warn in a worker is suffficient.
// This would be a change from the current FS.
if (fd == 1 || fd == 2) {
__wasi_size_t num = 0;
for (size_t i = 0; i < iovs_len; i++) {
const uint8_t* ptr = iovs[i].buf;
const uint8_t* buf = iovs[i].buf;
__wasi_size_t len = iovs[i].buf_len;
emscripten_wasmfs_printbuffer(fd, ptr, len);
for (__wasi_size_t j = 0; j < len; j++) {
uint8_t current = buf[j];
if (current == 0 || current == 10) {
fd_write_stdstream_buffer.push_back('\0'); // for null-terminated C strings
if (fd == 1) {
emscripten_console_log(&fd_write_stdstream_buffer[0]);
} else if (fd == 2) {
emscripten_console_error(&fd_write_stdstream_buffer[0]);
}
fd_write_stdstream_buffer.clear();
} else {
fd_write_stdstream_buffer.push_back(current);
}
}
num += len;
}
*nwritten = num;
Expand Down
4 changes: 3 additions & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,9 @@ def verify_es5(self, filename):
def build(self, filename, libraries=[], includes=[], force_c=False, js_outfile=True, emcc_args=[], output_basename=None):
suffix = '.js' if js_outfile else '.wasm'
compiler = [compiler_for(filename, force_c)]
if compiler[0] == EMCC:
if compiler[0] == EMCC and not self.get_setting('WASMFS'):
Comment thread
ethanalee marked this conversation as resolved.
# TODO change test behaviour in the future when WASMFS becomes default file system
# WASMFS is excluded here since it currently requires stdlib++ functions

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of worries me, to be honest. It seems like we might end up forgetting it, and then users would hit problems that don't occur in the test suite. That's a risk when working around issues in the test suite like this.

One possible idea is to move this to emcc.py, using the flag @sbc100 mentioned to link as cxx. We'll need that anyhow I think. However, I'm also ok with landing this if we put that on a TODO somewhere we are sure we won't forget.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean using -s DEFAULT_TO_CXX=0 here instead of -nostdlib++? Sure we could try that. I'll open a PR to do that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Maybe what you meant, but to be sure I meant not here and instead in emcc.py - then it will work outside of the test suite too.)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting we move forward with changing the default to DEFAULT_TO_CXX=0 for all users? This is the plan as layed out in #11121 but it could be a breaking change for many users and I'd like to start by issuing a warning.

The point of this line here is to opt into this new stricter behaviour within the test suite before we apply it to all users.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, sorry, I mean to add something like this in emcc.py:

if WASMFS:
  DEFAULT_TO_CXX = 1

That would affect no one but a few tests atm.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that sounds like the correct solution.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can land this as is for now. I will keep the todo and add this setting in the following PR

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Followup PR sounds good.

# TODO(https://github.com/emscripten-core/emscripten/issues/11121)
# We link with C++ stdlibs, even when linking with emcc for historical reasons. We can remove
# this if this issues is fixed.
Expand Down