Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Add support for read/seek on files in the native file system #16307

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
wip: add native fs support
  • Loading branch information
msabwat committed Feb 16, 2022
commit 33e3f1b09ccf548229078100b81291244c9546f6
16 changes: 16 additions & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2071,6 +2071,9 @@ def default_setting(name, new_default):

# set location of worker.js
settings.PTHREAD_WORKER_FILE = unsuffixed_basename(target) + '.worker.js'

# set location of nativefs_worker.js
settings.NATIVE_FS_WORKER_FILE = unsuffixed_basename(target) + '.nativefs_worker.js'
else:
settings.JS_LIBRARIES.append((0, 'library_pthread_stub.js'))

Expand Down Expand Up @@ -2840,6 +2843,19 @@ def phase_final_emitting(options, state, target, wasm_target, memfile):
minified_worker = building.acorn_optimizer(worker_output, ['minifyWhitespace'], return_output=True)
write_file(worker_output, minified_worker)

if settings.EMSCRIPTEN_NATIVE_FS:
if not settings.USE_PTHREADS:
exit_with_error('EMSCRIPTEN_NATIVE_FS feature needs -s USE_PTHREADS')
target_dir = os.path.dirname(os.path.abspath(target))
worker_output = os.path.join(target_dir, settings.NATIVE_FS_WORKER_FILE)
contents = shared.read_and_preprocess(utils.path_from_root('src/nativefs_worker.js'), expand_macros=True)
write_file(worker_output, contents)

# Minify the worker.js file in optimized builds
if (settings.OPT_LEVEL >= 1 or settings.SHRINK_LEVEL >= 1) and not settings.DEBUG_LEVEL:
minified_worker = building.acorn_optimizer(worker_output, ['minifyWhitespace'], return_output=True)
write_file(worker_output, minified_worker)

# track files that will need native eols
generated_text_files_with_native_eols = []

Expand Down
9 changes: 8 additions & 1 deletion src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -3021,7 +3021,14 @@ LibraryManager.library = {
#if RELOCATABLE
code -= {{{ GLOBAL_BASE }}};
#endif
var args = readAsmConstArgs(sigPtr, argbuf);
#if EMSCRIPTEN_NATIVE_FS
if ( code === - 1 ) {
var args = 0;
}
else {
var args = readAsmConstArgs(sigPtr, argbuf);
}
#endif
#if USE_PTHREADS
if (ENVIRONMENT_IS_PTHREAD) {
// EM_ASM functions are variadic, receiving the actual arguments as a buffer
Expand Down
Loading