@wasm-oj/server 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +6 -0
  3. package/THIRD_PARTY_NOTICES.md +302 -0
  4. package/crates/runtime-core/Cargo.lock +5099 -0
  5. package/crates/runtime-core/Cargo.toml +66 -0
  6. package/crates/runtime-core/README.md +47 -0
  7. package/crates/runtime-core/src/bin/wasm-oj-compiler.rs +418 -0
  8. package/crates/runtime-core/src/bin/wasm-oj-runner.rs +294 -0
  9. package/crates/runtime-core/src/capabilities.rs +118 -0
  10. package/crates/runtime-core/src/compiler.rs +658 -0
  11. package/crates/runtime-core/src/contract.rs +5 -0
  12. package/crates/runtime-core/src/deterministic.rs +1051 -0
  13. package/crates/runtime-core/src/error.rs +58 -0
  14. package/crates/runtime-core/src/filesystem.rs +547 -0
  15. package/crates/runtime-core/src/filesystem_quota.rs +167 -0
  16. package/crates/runtime-core/src/go_compiler_session.rs +297 -0
  17. package/crates/runtime-core/src/interactive.rs +1019 -0
  18. package/crates/runtime-core/src/judge_package.rs +1539 -0
  19. package/crates/runtime-core/src/lib.rs +98 -0
  20. package/crates/runtime-core/src/memory.rs +84 -0
  21. package/crates/runtime-core/src/meter.rs +549 -0
  22. package/crates/runtime-core/src/module_imports.rs +149 -0
  23. package/crates/runtime-core/src/module_policy.rs +714 -0
  24. package/crates/runtime-core/src/output.rs +204 -0
  25. package/crates/runtime-core/src/run/mod.rs +208 -0
  26. package/crates/runtime-core/src/run/native.rs +260 -0
  27. package/crates/runtime-core/src/run/web.rs +229 -0
  28. package/crates/runtime-core/src/run/web_runtime.rs +109 -0
  29. package/crates/runtime-core/src/types.rs +268 -0
  30. package/crates/runtime-core/src/web.rs +83 -0
  31. package/dist/chunks/go-toolchain-Dbt-lp2L.js +426 -0
  32. package/dist/chunks/java-toolchain-DajoRCHu.js +44 -0
  33. package/dist/chunks/python-toolchain-Dx834o2A.js +4 -0
  34. package/dist/chunks/rust-toolchain-CJ3sMxPE.js +252 -0
  35. package/dist/chunks/toolchains-C6KuA1yM.js +224 -0
  36. package/dist/go-stage.mjs +193 -0
  37. package/dist/index.d.ts +221 -0
  38. package/dist/index.js +4393 -0
  39. package/dist/java-stage.mjs +111 -0
  40. package/dist/python-stage.mjs +90 -0
  41. package/dist/rustc-stage.mjs +301 -0
  42. package/dist/server-build-stage.mjs +2564 -0
  43. package/dist/server-runner-stage.mjs +155 -0
  44. package/licenses/fflate-MIT.txt +21 -0
  45. package/licenses/runtime-core-dependencies.html +6253 -0
  46. package/licenses/runtime-core-dependencies.json +3041 -0
  47. package/licenses/wasmer-sdk-MIT.txt +21 -0
  48. package/licenses/wasmer-sdk-dependencies.html +6901 -0
  49. package/licenses/wasmer-sdk-dependencies.json +3013 -0
  50. package/package.json +70 -0
  51. package/rust-toolchain.toml +5 -0
  52. package/testdata/wojjdg02-v2-text.hex +1 -0
  53. package/vendor/shared-buffer/Cargo.toml +22 -0
  54. package/vendor/shared-buffer/LICENSE_APACHE.md +176 -0
  55. package/vendor/shared-buffer/LICENSE_MIT.md +25 -0
  56. package/vendor/shared-buffer/README.md +34 -0
  57. package/vendor/shared-buffer/src/lib.rs +58 -0
  58. package/vendor/shared-buffer/src/mmap.rs +250 -0
  59. package/vendor/shared-buffer/src/owned.rs +389 -0
  60. package/vendor/virtual-fs/Cargo.toml +181 -0
  61. package/vendor/virtual-fs/LICENSE +25 -0
  62. package/vendor/virtual-fs/src/arc_box_file.rs +142 -0
  63. package/vendor/virtual-fs/src/arc_file.rs +182 -0
  64. package/vendor/virtual-fs/src/arc_fs.rs +68 -0
  65. package/vendor/virtual-fs/src/buffer_file.rs +103 -0
  66. package/vendor/virtual-fs/src/builder.rs +232 -0
  67. package/vendor/virtual-fs/src/combine_file.rs +101 -0
  68. package/vendor/virtual-fs/src/cow_file.rs +345 -0
  69. package/vendor/virtual-fs/src/dual_write_file.rs +113 -0
  70. package/vendor/virtual-fs/src/empty_fs.rs +81 -0
  71. package/vendor/virtual-fs/src/filesystems.rs +108 -0
  72. package/vendor/virtual-fs/src/host_fs.rs +1390 -0
  73. package/vendor/virtual-fs/src/lib.rs +782 -0
  74. package/vendor/virtual-fs/src/limiter.rs +252 -0
  75. package/vendor/virtual-fs/src/mem_fs/file.rs +1799 -0
  76. package/vendor/virtual-fs/src/mem_fs/file_opener.rs +941 -0
  77. package/vendor/virtual-fs/src/mem_fs/filesystem.rs +2134 -0
  78. package/vendor/virtual-fs/src/mem_fs/mod.rs +245 -0
  79. package/vendor/virtual-fs/src/mem_fs/offloaded_file.rs +474 -0
  80. package/vendor/virtual-fs/src/mem_fs/stdio.rs +318 -0
  81. package/vendor/virtual-fs/src/mount_fs.rs +2225 -0
  82. package/vendor/virtual-fs/src/null_file.rs +87 -0
  83. package/vendor/virtual-fs/src/ops.rs +364 -0
  84. package/vendor/virtual-fs/src/overlay_fs.rs +2216 -0
  85. package/vendor/virtual-fs/src/passthru_fs.rs +119 -0
  86. package/vendor/virtual-fs/src/pipe.rs +603 -0
  87. package/vendor/virtual-fs/src/random_file.rs +88 -0
  88. package/vendor/virtual-fs/src/special_file.rs +108 -0
  89. package/vendor/virtual-fs/src/static_file.rs +133 -0
  90. package/vendor/virtual-fs/src/static_fs.rs +460 -0
  91. package/vendor/virtual-fs/src/tmp_fs.rs +95 -0
  92. package/vendor/virtual-fs/src/trace_fs.rs +258 -0
  93. package/vendor/virtual-fs/src/webc_volume_fs.rs +829 -0
  94. package/vendor/virtual-fs/src/zero_file.rs +90 -0
@@ -0,0 +1,113 @@
1
+ use super::*;
2
+
3
+ use crate::VirtualFile;
4
+
5
+ /// Wraps a [`VirtualFile`], and also invokes a provided function for each write.
6
+ ///
7
+ /// Useful for debugging.
8
+ #[derive(derive_more::Debug)]
9
+ pub struct DualWriteFile {
10
+ inner: Box<dyn VirtualFile + Send + Sync + 'static>,
11
+ #[allow(clippy::type_complexity)]
12
+ #[debug(ignore)]
13
+ extra_write: Box<dyn FnMut(&[u8]) + Send + Sync + 'static>,
14
+ }
15
+
16
+ impl DualWriteFile {
17
+ pub fn new(
18
+ inner: Box<dyn VirtualFile + Send + Sync + 'static>,
19
+ funct: impl FnMut(&[u8]) + Send + Sync + 'static,
20
+ ) -> Self {
21
+ Self {
22
+ inner,
23
+ extra_write: Box::new(funct),
24
+ }
25
+ }
26
+ }
27
+
28
+ impl VirtualFile for DualWriteFile {
29
+ fn last_accessed(&self) -> u64 {
30
+ self.inner.last_accessed()
31
+ }
32
+
33
+ fn last_modified(&self) -> u64 {
34
+ self.inner.last_modified()
35
+ }
36
+
37
+ fn created_time(&self) -> u64 {
38
+ self.inner.created_time()
39
+ }
40
+
41
+ fn set_times(&mut self, atime: Option<u64>, mtime: Option<u64>) -> crate::Result<()> {
42
+ self.inner.set_times(atime, mtime)
43
+ }
44
+
45
+ fn size(&self) -> u64 {
46
+ self.inner.size()
47
+ }
48
+
49
+ fn set_len(&mut self, new_size: u64) -> crate::Result<()> {
50
+ self.inner.set_len(new_size)
51
+ }
52
+
53
+ fn unlink(&mut self) -> Result<()> {
54
+ self.inner.unlink()
55
+ }
56
+
57
+ fn poll_read_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
58
+ Pin::new(self.inner.as_mut()).poll_read_ready(cx)
59
+ }
60
+
61
+ fn poll_write_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
62
+ Pin::new(self.inner.as_mut()).poll_write_ready(cx)
63
+ }
64
+ }
65
+
66
+ impl AsyncWrite for DualWriteFile {
67
+ fn poll_write(
68
+ mut self: Pin<&mut Self>,
69
+ cx: &mut std::task::Context<'_>,
70
+ buf: &[u8],
71
+ ) -> Poll<std::io::Result<usize>> {
72
+ match Pin::new(&mut self.inner).poll_write(cx, buf) {
73
+ Poll::Ready(Ok(amt)) => {
74
+ if amt > 0 {
75
+ (self.extra_write)(&buf[..amt]);
76
+ }
77
+ Poll::Ready(Ok(amt))
78
+ }
79
+ res => res,
80
+ }
81
+ }
82
+
83
+ fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
84
+ Pin::new(&mut self.inner).poll_flush(cx)
85
+ }
86
+
87
+ fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
88
+ Pin::new(&mut self.inner).poll_shutdown(cx)
89
+ }
90
+ }
91
+
92
+ impl AsyncRead for DualWriteFile {
93
+ fn poll_read(
94
+ mut self: Pin<&mut Self>,
95
+ cx: &mut std::task::Context<'_>,
96
+ buf: &mut tokio::io::ReadBuf<'_>,
97
+ ) -> Poll<io::Result<()>> {
98
+ Pin::new(&mut self.inner).poll_read(cx, buf)
99
+ }
100
+ }
101
+
102
+ impl AsyncSeek for DualWriteFile {
103
+ fn start_seek(mut self: Pin<&mut Self>, position: io::SeekFrom) -> io::Result<()> {
104
+ Pin::new(&mut self.inner).start_seek(position)
105
+ }
106
+
107
+ fn poll_complete(
108
+ mut self: Pin<&mut Self>,
109
+ cx: &mut std::task::Context<'_>,
110
+ ) -> Poll<io::Result<u64>> {
111
+ Pin::new(&mut self.inner).poll_complete(cx)
112
+ }
113
+ }
@@ -0,0 +1,81 @@
1
+ //! When no file system is used by a WebC then this is used as a placeholder -
2
+ //! as the name suggests it always returns file not found.
3
+
4
+ use std::path::Path;
5
+ #[allow(unused_imports, dead_code)]
6
+ use tracing::{debug, error, info, trace, warn};
7
+
8
+ use crate::*;
9
+
10
+ #[derive(Debug, Default)]
11
+ pub struct EmptyFileSystem {}
12
+
13
+ #[allow(unused_variables)]
14
+ impl FileSystem for EmptyFileSystem {
15
+ fn readlink(&self, path: &Path) -> Result<PathBuf> {
16
+ Err(FsError::EntryNotFound)
17
+ }
18
+
19
+ fn read_dir(&self, path: &Path) -> Result<ReadDir> {
20
+ // Special-case the root path by returning an empty iterator.
21
+ // An empty file system should still be readable, just not contain
22
+ // any entries.
23
+ if path == Path::new("/") {
24
+ Ok(ReadDir::new(Vec::new()))
25
+ } else {
26
+ Err(FsError::EntryNotFound)
27
+ }
28
+ }
29
+
30
+ fn create_dir(&self, path: &Path) -> Result<()> {
31
+ Err(FsError::EntryNotFound)
32
+ }
33
+
34
+ fn remove_dir(&self, path: &Path) -> Result<()> {
35
+ Err(FsError::EntryNotFound)
36
+ }
37
+
38
+ fn rename<'a>(&'a self, from: &'a Path, to: &'a Path) -> BoxFuture<'a, Result<()>> {
39
+ Box::pin(async { Err(FsError::EntryNotFound) })
40
+ }
41
+
42
+ fn metadata(&self, path: &Path) -> Result<Metadata> {
43
+ // Special-case the root path by returning an stub value.
44
+ // An empty file system should still be readable, just not contain
45
+ // any entries.
46
+ if path == Path::new("/") {
47
+ Ok(Metadata {
48
+ ft: FileType::new_dir(),
49
+ accessed: 0,
50
+ created: 0,
51
+ modified: 0,
52
+ len: 0,
53
+ })
54
+ } else {
55
+ Err(FsError::EntryNotFound)
56
+ }
57
+ }
58
+
59
+ fn symlink_metadata(&self, path: &Path) -> Result<Metadata> {
60
+ Err(FsError::EntryNotFound)
61
+ }
62
+
63
+ fn remove_file(&self, path: &Path) -> Result<()> {
64
+ Err(FsError::EntryNotFound)
65
+ }
66
+
67
+ fn new_open_options(&self) -> OpenOptions<'_> {
68
+ OpenOptions::new(self)
69
+ }
70
+ }
71
+
72
+ impl FileOpener for EmptyFileSystem {
73
+ #[allow(unused_variables)]
74
+ fn open(
75
+ &self,
76
+ path: &Path,
77
+ conf: &OpenOptionsConfig,
78
+ ) -> Result<Box<dyn VirtualFile + Send + Sync + 'static>> {
79
+ Err(FsError::EntryNotFound)
80
+ }
81
+ }
@@ -0,0 +1,108 @@
1
+ use crate::FileSystem;
2
+
3
+ /// A chain of one or more [`FileSystem`]s.
4
+ pub trait FileSystems<'a>: 'a {
5
+ // FIXME(Michael-F-Bryan): Rewrite this to use GATs when we bump the MSRV to
6
+ // 1.65 or higher. That'll get rid of all the lifetimes and HRTBs.
7
+ type Iter: IntoIterator<Item = &'a (dyn FileSystem + Send)> + Send + 'a;
8
+
9
+ /// Get something that can be used to iterate over the underlying
10
+ /// filesystems.
11
+ fn filesystems(&'a self) -> Self::Iter;
12
+ }
13
+
14
+ impl<'a, 'b, S> FileSystems<'a> for &'b S
15
+ where
16
+ S: FileSystems<'a> + 'b,
17
+ 'b: 'a,
18
+ {
19
+ type Iter = S::Iter;
20
+
21
+ fn filesystems(&'a self) -> Self::Iter {
22
+ (**self).filesystems()
23
+ }
24
+ }
25
+
26
+ impl<'a, T> FileSystems<'a> for Vec<T>
27
+ where
28
+ T: FileSystem + Send,
29
+ {
30
+ type Iter = <[T] as FileSystems<'a>>::Iter;
31
+
32
+ fn filesystems(&'a self) -> Self::Iter {
33
+ self[..].filesystems()
34
+ }
35
+ }
36
+
37
+ impl<'a, T, const N: usize> FileSystems<'a> for [T; N]
38
+ where
39
+ T: FileSystem + Send,
40
+ {
41
+ type Iter = [&'a (dyn FileSystem + Send); N];
42
+
43
+ fn filesystems(&'a self) -> Self::Iter {
44
+ // TODO: rewrite this when array::each_ref() is stable
45
+ let mut i = 0;
46
+ [(); N].map(|_| {
47
+ let f = &self[i] as &(dyn FileSystem + Send);
48
+ i += 1;
49
+ f
50
+ })
51
+ }
52
+ }
53
+
54
+ impl<'a, T> FileSystems<'a> for [T]
55
+ where
56
+ T: FileSystem + Send,
57
+ {
58
+ type Iter = std::iter::Map<std::slice::Iter<'a, T>, fn(&T) -> &(dyn FileSystem + Send)>;
59
+
60
+ fn filesystems(&'a self) -> Self::Iter {
61
+ self.iter().map(|fs| fs as &(dyn FileSystem + Send))
62
+ }
63
+ }
64
+
65
+ impl<'a> FileSystems<'a> for () {
66
+ type Iter = std::iter::Empty<&'a (dyn FileSystem + Send)>;
67
+
68
+ fn filesystems(&'a self) -> Self::Iter {
69
+ std::iter::empty()
70
+ }
71
+ }
72
+
73
+ macro_rules! count {
74
+ ($first:tt $($rest:tt)*) => {
75
+ 1 + count!($($rest)*)
76
+ };
77
+ () => { 0 };
78
+ }
79
+
80
+ macro_rules! tuple_filesystems {
81
+ ($first:ident $(, $rest:ident)* $(,)?) => {
82
+ impl<'a, $first, $( $rest ),*> FileSystems<'a> for ($first, $($rest),*)
83
+ where
84
+ $first: FileSystem,
85
+ $($rest: FileSystem),*
86
+ {
87
+ type Iter = [&'a (dyn FileSystem + Send); count!($first $($rest)*)];
88
+
89
+ fn filesystems(&'a self) -> Self::Iter {
90
+ #[allow(non_snake_case)]
91
+ let ($first, $($rest),*) = self;
92
+
93
+ [
94
+ $first as &(dyn FileSystem + Send),
95
+ $($rest),*
96
+ ]
97
+ }
98
+
99
+ }
100
+
101
+ tuple_filesystems!($($rest),*);
102
+ };
103
+ () => {};
104
+ }
105
+
106
+ tuple_filesystems!(
107
+ F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14, F15, F16,
108
+ );