@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,258 @@
1
+ use std::{
2
+ path::PathBuf,
3
+ pin::Pin,
4
+ task::{Context, Poll},
5
+ };
6
+
7
+ use futures::future::BoxFuture;
8
+ use tokio::io::{AsyncRead, AsyncSeek, AsyncWrite, ReadBuf};
9
+
10
+ use crate::{FileOpener, FileSystem, OpenOptionsConfig, VirtualFile};
11
+
12
+ /// A [`FileSystem`] wrapper that will automatically log all operations at the
13
+ /// `trace` level.
14
+ ///
15
+ /// To see these logs, you will typically need to set the `$RUST_LOG`
16
+ /// environment variable to `virtual_fs::trace_fs=trace`.
17
+ #[derive(Debug, Clone, PartialEq, Eq)]
18
+ pub struct TraceFileSystem<F>(pub F);
19
+
20
+ impl<F> TraceFileSystem<F> {
21
+ pub fn new(filesystem: F) -> Self {
22
+ TraceFileSystem(filesystem)
23
+ }
24
+
25
+ pub fn inner(&self) -> &F {
26
+ &self.0
27
+ }
28
+
29
+ pub fn inner_mut(&mut self) -> &mut F {
30
+ &mut self.0
31
+ }
32
+
33
+ pub fn into_inner(self) -> F {
34
+ self.0
35
+ }
36
+ }
37
+
38
+ impl<F> FileSystem for TraceFileSystem<F>
39
+ where
40
+ F: FileSystem,
41
+ {
42
+ #[tracing::instrument(level = "trace", skip(self), err)]
43
+ fn readlink(&self, path: &std::path::Path) -> crate::Result<PathBuf> {
44
+ self.0.readlink(path)
45
+ }
46
+
47
+ #[tracing::instrument(level = "trace", skip(self), err)]
48
+ fn read_dir(&self, path: &std::path::Path) -> crate::Result<crate::ReadDir> {
49
+ self.0.read_dir(path)
50
+ }
51
+
52
+ #[tracing::instrument(level = "trace", skip(self), err)]
53
+ fn create_dir(&self, path: &std::path::Path) -> crate::Result<()> {
54
+ self.0.create_dir(path)
55
+ }
56
+
57
+ #[tracing::instrument(level = "trace", skip(self), err)]
58
+ fn remove_dir(&self, path: &std::path::Path) -> crate::Result<()> {
59
+ self.0.remove_dir(path)
60
+ }
61
+
62
+ #[tracing::instrument(level = "trace", skip(self), err)]
63
+ fn rename<'a>(
64
+ &'a self,
65
+ from: &'a std::path::Path,
66
+ to: &'a std::path::Path,
67
+ ) -> BoxFuture<'a, crate::Result<()>> {
68
+ Box::pin(async { self.0.rename(from, to).await })
69
+ }
70
+
71
+ #[tracing::instrument(level = "trace", skip(self), err)]
72
+ fn metadata(&self, path: &std::path::Path) -> crate::Result<crate::Metadata> {
73
+ self.0.metadata(path)
74
+ }
75
+
76
+ #[tracing::instrument(level = "trace", skip(self), err)]
77
+ fn symlink_metadata(&self, path: &std::path::Path) -> crate::Result<crate::Metadata> {
78
+ self.0.symlink_metadata(path)
79
+ }
80
+
81
+ #[tracing::instrument(level = "trace", skip(self), err)]
82
+ fn remove_file(&self, path: &std::path::Path) -> crate::Result<()> {
83
+ self.0.remove_file(path)
84
+ }
85
+
86
+ #[tracing::instrument(level = "trace", skip(self))]
87
+ fn new_open_options(&self) -> crate::OpenOptions<'_> {
88
+ crate::OpenOptions::new(self)
89
+ }
90
+ }
91
+
92
+ impl<F> FileOpener for TraceFileSystem<F>
93
+ where
94
+ F: FileSystem,
95
+ {
96
+ #[tracing::instrument(level = "trace", skip(self))]
97
+ fn open(
98
+ &self,
99
+ path: &std::path::Path,
100
+ conf: &OpenOptionsConfig,
101
+ ) -> crate::Result<Box<dyn crate::VirtualFile + Send + Sync + 'static>> {
102
+ let file = self.0.new_open_options().options(conf.clone()).open(path)?;
103
+ Ok(Box::new(TraceFile {
104
+ file,
105
+ path: path.to_owned(),
106
+ }))
107
+ }
108
+ }
109
+
110
+ #[derive(Debug)]
111
+ struct TraceFile {
112
+ path: PathBuf,
113
+ file: Box<dyn crate::VirtualFile + Send + Sync + 'static>,
114
+ }
115
+
116
+ impl VirtualFile for TraceFile {
117
+ #[tracing::instrument(level = "trace", skip(self), fields(path=%self.path.display()))]
118
+ fn last_accessed(&self) -> u64 {
119
+ self.file.last_accessed()
120
+ }
121
+
122
+ #[tracing::instrument(level = "trace", skip(self), fields(path=%self.path.display()))]
123
+ fn last_modified(&self) -> u64 {
124
+ self.file.last_modified()
125
+ }
126
+
127
+ #[tracing::instrument(level = "trace", skip(self), fields(path=%self.path.display()))]
128
+ fn created_time(&self) -> u64 {
129
+ self.file.created_time()
130
+ }
131
+
132
+ #[tracing::instrument(level = "trace", skip(self), fields(path=%self.path.display()))]
133
+ fn set_times(&mut self, atime: Option<u64>, mtime: Option<u64>) -> crate::Result<()> {
134
+ self.file.set_times(atime, mtime)
135
+ }
136
+
137
+ #[tracing::instrument(level = "trace", skip(self), fields(path=%self.path.display()))]
138
+ fn size(&self) -> u64 {
139
+ self.file.size()
140
+ }
141
+
142
+ #[tracing::instrument(level = "trace", skip(self), fields(path=%self.path.display()), err)]
143
+ fn set_len(&mut self, new_size: u64) -> crate::Result<()> {
144
+ self.file.set_len(new_size)
145
+ }
146
+
147
+ fn unlink(&mut self) -> crate::Result<()> {
148
+ self.file.unlink()
149
+ }
150
+
151
+ #[tracing::instrument(level = "trace", skip_all, fields(path=%self.path.display()))]
152
+ fn poll_read_ready(
153
+ mut self: Pin<&mut Self>,
154
+ cx: &mut Context<'_>,
155
+ ) -> Poll<std::io::Result<usize>> {
156
+ let result = Pin::new(&mut *self.file).poll_read_ready(cx);
157
+
158
+ if let Poll::Ready(Err(e)) = &result {
159
+ tracing::trace!(error = e as &dyn std::error::Error);
160
+ }
161
+
162
+ result
163
+ }
164
+
165
+ #[tracing::instrument(level = "trace", skip_all, fields(path=%self.path.display()))]
166
+ fn poll_write_ready(
167
+ mut self: Pin<&mut Self>,
168
+ cx: &mut Context<'_>,
169
+ ) -> Poll<std::io::Result<usize>> {
170
+ let result = Pin::new(&mut *self.file).poll_write_ready(cx);
171
+
172
+ if let Poll::Ready(Err(e)) = &result {
173
+ tracing::trace!(error = e as &dyn std::error::Error);
174
+ }
175
+
176
+ result
177
+ }
178
+ }
179
+
180
+ impl AsyncRead for TraceFile {
181
+ #[tracing::instrument(level = "trace", skip_all, fields(path=%self.path.display()))]
182
+ fn poll_read(
183
+ mut self: Pin<&mut Self>,
184
+ cx: &mut Context<'_>,
185
+ buf: &mut ReadBuf<'_>,
186
+ ) -> Poll<std::io::Result<()>> {
187
+ let result = Pin::new(&mut *self.file).poll_read(cx, buf);
188
+
189
+ if let Poll::Ready(Err(e)) = &result {
190
+ tracing::trace!(error = e as &dyn std::error::Error);
191
+ }
192
+
193
+ result
194
+ }
195
+ }
196
+
197
+ impl AsyncWrite for TraceFile {
198
+ #[tracing::instrument(level = "trace", skip_all, fields(path=%self.path.display()))]
199
+ fn poll_write(
200
+ mut self: Pin<&mut Self>,
201
+ cx: &mut Context<'_>,
202
+ buf: &[u8],
203
+ ) -> Poll<Result<usize, std::io::Error>> {
204
+ let result = Pin::new(&mut *self.file).poll_write(cx, buf);
205
+
206
+ if let Poll::Ready(Err(e)) = &result {
207
+ tracing::trace!(error = e as &dyn std::error::Error);
208
+ }
209
+
210
+ result
211
+ }
212
+
213
+ #[tracing::instrument(level = "trace", skip_all, fields(path=%self.path.display()))]
214
+ fn poll_flush(
215
+ mut self: Pin<&mut Self>,
216
+ cx: &mut Context<'_>,
217
+ ) -> Poll<Result<(), std::io::Error>> {
218
+ let result = Pin::new(&mut *self.file).poll_flush(cx);
219
+
220
+ if let Poll::Ready(Err(e)) = &result {
221
+ tracing::trace!(error = e as &dyn std::error::Error);
222
+ }
223
+
224
+ result
225
+ }
226
+
227
+ #[tracing::instrument(level = "trace", skip_all, fields(path=%self.path.display()))]
228
+ fn poll_shutdown(
229
+ mut self: Pin<&mut Self>,
230
+ cx: &mut Context<'_>,
231
+ ) -> Poll<Result<(), std::io::Error>> {
232
+ let result = Pin::new(&mut *self.file).poll_shutdown(cx);
233
+
234
+ if let Poll::Ready(Err(e)) = &result {
235
+ tracing::trace!(error = e as &dyn std::error::Error);
236
+ }
237
+
238
+ result
239
+ }
240
+ }
241
+
242
+ impl AsyncSeek for TraceFile {
243
+ #[tracing::instrument(level = "trace", skip_all, fields(path=%self.path.display()), err)]
244
+ fn start_seek(mut self: Pin<&mut Self>, position: std::io::SeekFrom) -> std::io::Result<()> {
245
+ Pin::new(&mut *self.file).start_seek(position)
246
+ }
247
+
248
+ #[tracing::instrument(level = "trace", skip_all, fields(path=%self.path.display()))]
249
+ fn poll_complete(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<u64>> {
250
+ let result = Pin::new(&mut *self.file).poll_complete(cx);
251
+
252
+ if let Poll::Ready(Err(e)) = &result {
253
+ tracing::trace!(error = e as &dyn std::error::Error);
254
+ }
255
+
256
+ result
257
+ }
258
+ }