forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request emscripten-core#21 from rstz/remove-sfa-support
Removed Storage Foundation Support, Simplify file packager code
- Loading branch information
Showing
13 changed files
with
645 additions
and
1,229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,20 +5,20 @@ The Emscripten Pthread File System (PThreadFS) unlocks using (partly) asynchrono | |
PThreadFS works by replacing Emscripten's file system API with a new API that proxies all file system operations to a dedicated pthread. This dedicated thread maintains a virtual file system that can use different APIs as backend (very similar to the way Emscripten's VFS is designed). In particular, PThreadFS comes with built-in support for asynchronous backends such as [OPFS Access Handles](https://docs.google.com/document/d/121OZpRk7bKSF7qU3kQLqAEUVSNxqREnE98malHYwWec/edit#heading=h.gj2fudnvy982). | ||
Although the underlying storage API is asynchronous, PThreadFS makes it appear synchronous to the C++ application. | ||
|
||
If OPFS Access Handles are not available, PThreadFS will attempt to use the [Storage Foundation API](https://github.com/WICG/storage-foundation-api-explainer). As a last fallback, Emscripten's MEMFS in-memory file system is used. | ||
If OPFS Access Handles are not available, PThreadFS will use an in-memory file system. | ||
|
||
The code is still prototype quality and **should not be used in a production environment** for the time being. | ||
|
||
## Enable OPFS Access Handles in Chrome | ||
|
||
OPFS Access Handles require recent versions of Google Chrome Canary. "Experimental Web Platform Features" must be enabled in [chrome://flags](chrome://flags). | ||
OPFS Access Handles require Google Chrome 96. "Experimental Web Platform Features" must be enabled in [chrome://flags](chrome://flags). | ||
|
||
Alternatively, you may enable the API with Chrome's " --enable-runtime-features=FileSystemAccessAccessHandle". On MacOS, this can be done through | ||
``` | ||
open -a /Applications/Google\ Chrome\ Canary.app --args --enable-runtime-features=FileSystemAccessAccessHandle | ||
``` | ||
|
||
Both Storage Foundation API and OPFS are available as [origin trials](https://developer.chrome.com/origintrials/) in Chrome 95. | ||
OPFS Access Handles are available as [origin trial](https://developer.chrome.com/origintrials/) in Chrome 95. | ||
## Getting the code | ||
|
||
PthreadFS is available on Github in the [emscripten-pthreadfs](https://github.com/rstz/emscripten-pthreadfs) repository. All code resides in the `pthreadfs` folder. It should be usable with any up-to-date Emscripten version. | ||
|
@@ -74,7 +74,6 @@ See `pthreadfs/examples/emscripten-tests/fsafs.cpp` for exemplary usage. | |
- PThreadFS depends on C++ libraries. `EM_PTHREADFS_ASM()` cannot be used within C files. | ||
- Performance is good if and only if optimizations (compiler option `-O2`) are enabled and DevTools are closed. | ||
- Accessing the file system before `main()` requires linker option `PTHREAD_POOL_SIZE=<expression>` to be active. Doing so may lead to some blocking of the main thread, which is risky. Check out `examples/early_syscall.cpp` for an example. | ||
- The Storage Foundation backend requires case-insensitive file names. | ||
- Compiling with the Closure Compiler is not supported. | ||
- Compiling with optimization `-O3` is not yet supported and may lead to a faulty build. | ||
|
||
|
@@ -98,23 +97,23 @@ python3 -m http.server 8888 | |
Then open the following link in a Chrome instance with the | ||
_OPFS Access Handles_ [enabled](#enable-and-detect-opfs-in-chrome): | ||
|
||
[localhost:8888/sqlite-speedtest](http://localhost:8888/sqlite-speedtest). The results of the speedtest can be found in the DevTools console. | ||
[localhost:8888/sqlite-speedtest](http://localhost:8888/sqlite-speedtest). | ||
|
||
### Other tests | ||
|
||
The folder `pthreadfs/examples/emscripten-tests` contains a number of other file system tests, mostly taken from Emscripten's standard test suite. | ||
The folder `pthreadfs/examples/` contains a number of other tests. | ||
|
||
To compile, navigate to the `pthreadfs/examples/` directory and run | ||
|
||
```shell | ||
make emscripten-tests | ||
cd dist/emscripten-tests | ||
make all | ||
cd dist/ | ||
python3 -m http.server 8888 | ||
``` | ||
Then open the following link in a Chrome instance with the | ||
_OPFS Access Handles_ [enabled](#enable-and-detect-opfs-in-chrome): | ||
|
||
[localhost:8888/emscripten-tests](http://localhost:8888/emscripten-tests) and choose a test. The results of the test can be found in the DevTools console. | ||
[localhost:8888](http://localhost:8888) and choose a test. The results of the test can be found in the DevTools console. | ||
|
||
## Authors | ||
- Richard Stotz (<[email protected]>) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2013 The Emscripten Authors. All rights reserved. | ||
* Emscripten is available under two separate licenses, the MIT license and the | ||
* University of Illinois/NCSA Open Source License. Both these licenses can be | ||
* found in the LICENSE file. | ||
*/ | ||
|
||
#include <assert.h> | ||
#include <ctype.h> | ||
#include <dirent.h> | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <signal.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
#include "emscripten.h" | ||
|
||
void create_file(const char* path, const char* contents, int mode) { | ||
int fd = open(path, O_CREAT | O_TRUNC | O_RDWR, mode); | ||
assert(fd >= 0); | ||
|
||
int err = write(fd, contents, sizeof(char) * strlen(contents)); | ||
assert(err == (sizeof(char) * strlen(contents))); | ||
|
||
close(fd); | ||
} | ||
|
||
void test_file_contents(const char* path, const char* contents) { | ||
MAIN_THREAD_ASYNC_EM_ASM({ | ||
(async() => { | ||
let path = UTF8ToString($0); | ||
await PThreadFS.init("persistent"); | ||
let content = await PThreadFS.readFile(path); | ||
content = new TextDecoder().decode(content); | ||
if (content != UTF8ToString($1)) { | ||
throw new Error('Incorrect contents read: ' + content); | ||
} | ||
await PThreadFS.unlink(path); | ||
console.log("Success"); | ||
})(); | ||
}, path, contents); | ||
} | ||
|
||
int main() { | ||
const char* path = "persistent/read_from_main_file.txt"; | ||
const char* contents = "file_contents :)"; | ||
create_file(path, contents, 0777); | ||
|
||
test_file_contents(path, contents); | ||
|
||
puts("Check the console for success"); | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2013 The Emscripten Authors. All rights reserved. | ||
* Emscripten is available under two separate licenses, the MIT license and the | ||
* University of Illinois/NCSA Open Source License. Both these licenses can be | ||
* found in the LICENSE file. | ||
*/ | ||
|
||
#include <assert.h> | ||
#include <ctype.h> | ||
#include <dirent.h> | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <signal.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/stat.h> | ||
#include <unistd.h> | ||
|
||
void cleanup() { | ||
rmdir("persistent/mainthreadfolder/subfolder"); | ||
rmdir("persistent/mainthreadfolder"); | ||
} | ||
|
||
void test_file_contents(const char* path) { | ||
printf("Test contents for file %s\n", path); | ||
|
||
int fd = open(path, O_RDONLY, 0777); | ||
assert(fd >= 0); | ||
|
||
char readbuf[1000]; | ||
int bytes_read = read(fd, readbuf, sizeof(char) * (strlen(path) + 20)); | ||
assert(bytes_read > 0); | ||
printf("Content: %s\n", readbuf); | ||
close(fd); | ||
|
||
unlink(path); | ||
} | ||
|
||
int main() { | ||
const char* paths[] = {"persistent/file.txt", "persistent/mainthreadfolder/subfolder/ok now"}; | ||
|
||
for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) { | ||
test_file_contents(paths[i]); | ||
} | ||
cleanup(); | ||
|
||
puts("success"); | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
if ("preRun" in Module) { | ||
Module["preRun"].push(async () => { | ||
await PThreadFS.init('persistent'); | ||
await PThreadFS.writeFile("persistent/file.txt", "the contents of persistent/file.txt !!", {}); | ||
await PThreadFS.createPath("/", "persistent/mainthreadfolder/subfolder/", true, true); | ||
await PThreadFS.writeFile("persistent/mainthreadfolder/subfolder/ok now", | ||
"the contents of persistent/mainthreadfolder/subfolder/ok now !!", {}); | ||
}); | ||
} |
Oops, something went wrong.