From 3303d3c98f54164ef9a2130c12f12ea6980cea88 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Mon, 27 Oct 2025 23:08:56 +0100 Subject: Stub out `core:os/os2` for js_wasm --- core/os/os2/dir_js.odin | 24 ++++++++++ core/os/os2/env_js.odin | 42 +++++++++++++++++ core/os/os2/errors_js.odin | 13 +++++ core/os/os2/file_js.odin | 107 ++++++++++++++++++++++++++++++++++++++++++ core/os/os2/heap_js.odin | 7 +++ core/os/os2/path_js.odin | 85 +++++++++++++++++++++++++++++++++ core/os/os2/pipe_js.odin | 14 ++++++ core/os/os2/process_js.odin | 87 ++++++++++++++++++++++++++++++++++ core/os/os2/stat_js.odin | 21 +++++++++ core/os/os2/temp_file_js.odin | 9 ++++ 10 files changed, 409 insertions(+) create mode 100644 core/os/os2/dir_js.odin create mode 100644 core/os/os2/env_js.odin create mode 100644 core/os/os2/errors_js.odin create mode 100644 core/os/os2/file_js.odin create mode 100644 core/os/os2/heap_js.odin create mode 100644 core/os/os2/path_js.odin create mode 100644 core/os/os2/pipe_js.odin create mode 100644 core/os/os2/process_js.odin create mode 100644 core/os/os2/stat_js.odin create mode 100644 core/os/os2/temp_file_js.odin diff --git a/core/os/os2/dir_js.odin b/core/os/os2/dir_js.odin new file mode 100644 index 000000000..d8f7c6202 --- /dev/null +++ b/core/os/os2/dir_js.odin @@ -0,0 +1,24 @@ +#+build js wasm32, js wasm64p32 +#+private +package os2 + +import "base:intrinsics" + +Read_Directory_Iterator_Impl :: struct { + fullpath: [dynamic]byte, + buf: []byte, + off: int, +} + +@(require_results) +_read_directory_iterator :: proc(it: ^Read_Directory_Iterator) -> (fi: File_Info, index: int, ok: bool) { + return {}, -1, false +} + +_read_directory_iterator_init :: proc(it: ^Read_Directory_Iterator, f: ^File) { + +} + +_read_directory_iterator_destroy :: proc(it: ^Read_Directory_Iterator) { + +} diff --git a/core/os/os2/env_js.odin b/core/os/os2/env_js.odin new file mode 100644 index 000000000..c1d94ba4a --- /dev/null +++ b/core/os/os2/env_js.odin @@ -0,0 +1,42 @@ +#+build js wasm32, js wasm64p32 +#+private +package os2 + +import "base:runtime" + +build_env :: proc() -> (err: Error) { + return +} + +// delete_string_if_not_original :: proc(str: string) { + +// } + +@(require_results) +_lookup_env_alloc :: proc(key: string, allocator: runtime.Allocator) -> (value: string, found: bool) { + return +} + +_lookup_env_buf :: proc(buf: []u8, key: string) -> (value: string, error: Error) { + return "", .Unsupported +} +_lookup_env :: proc{_lookup_env_alloc, _lookup_env_buf} + +@(require_results) +_set_env :: proc(key, value: string) -> (err: Error) { + return .Unsupported +} + +@(require_results) +_unset_env :: proc(key: string) -> bool { + return true +} + +_clear_env :: proc() { + +} + +@(require_results) +_environ :: proc(allocator: runtime.Allocator) -> (environ: []string, err: Error) { + return {}, .Unsupported +} diff --git a/core/os/os2/errors_js.odin b/core/os/os2/errors_js.odin new file mode 100644 index 000000000..c92d36736 --- /dev/null +++ b/core/os/os2/errors_js.odin @@ -0,0 +1,13 @@ +#+build js wasm32, js wasm64p32 +#+private +package os2 + +_Platform_Error :: enum i32 {} + +_error_string :: proc(errno: i32) -> string { + return "" +} + +_get_platform_error :: proc(errno: _Platform_Error) -> Error { + return Platform_Error(errno) +} diff --git a/core/os/os2/file_js.odin b/core/os/os2/file_js.odin new file mode 100644 index 000000000..fd4bf347c --- /dev/null +++ b/core/os/os2/file_js.odin @@ -0,0 +1,107 @@ +#+build js wasm32, js wasm64p32 +#+private +package os2 + +import "base:runtime" + +import "core:io" +import "core:time" + +File_Impl :: distinct rawptr + +_open :: proc(name: string, flags: File_Flags, perm: int) -> (f: ^File, err: Error) { + return nil, .Unsupported +} + +_new_file :: proc(handle: uintptr, name: string, allocator: runtime.Allocator) -> (f: ^File, err: Error) { + return nil, .Unsupported +} + +_clone :: proc(f: ^File) -> (clone: ^File, err: Error) { + return nil, .Unsupported +} + +_close :: proc(f: ^File_Impl) -> (err: Error) { + return .Unsupported +} + +_fd :: proc(f: ^File) -> uintptr { + return 0 +} + + +_name :: proc(f: ^File) -> string { + return "" +} + +_sync :: proc(f: ^File) -> Error { + return .Unsupported +} + +_truncate :: proc(f: ^File, size: i64) -> Error { + return .Unsupported +} + +_remove :: proc(name: string) -> Error { + return .Unsupported +} + +_rename :: proc(old_path, new_path: string) -> Error { + return .Unsupported +} + +_link :: proc(old_name, new_name: string) -> Error { + return .Unsupported +} + +_symlink :: proc(old_name, new_name: string) -> Error { + return .Unsupported +} + +_read_link :: proc(name: string, allocator: runtime.Allocator) -> (s: string, err: Error) { + return "", .Unsupported +} + +_chdir :: proc(name: string) -> Error { + return .Unsupported +} + +_fchdir :: proc(f: ^File) -> Error { + return .Unsupported +} + +_fchmod :: proc(f: ^File, mode: int) -> Error { + return .Unsupported +} + +_chmod :: proc(name: string, mode: int) -> Error { + return .Unsupported +} + +_fchown :: proc(f: ^File, uid, gid: int) -> Error { + return .Unsupported +} + +_chown :: proc(name: string, uid, gid: int) -> Error { + return .Unsupported +} + +_lchown :: proc(name: string, uid, gid: int) -> Error { + return .Unsupported +} + +_chtimes :: proc(name: string, atime, mtime: time.Time) -> Error { + return .Unsupported +} + +_fchtimes :: proc(f: ^File, atime, mtime: time.Time) -> Error { + return .Unsupported +} + +_exists :: proc(path: string) -> bool { + return false +} + +_file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, offset: i64, whence: io.Seek_From) -> (n: i64, err: io.Error) { + return 0, .Empty +} \ No newline at end of file diff --git a/core/os/os2/heap_js.odin b/core/os/os2/heap_js.odin new file mode 100644 index 000000000..15990b517 --- /dev/null +++ b/core/os/os2/heap_js.odin @@ -0,0 +1,7 @@ +#+build js wasm32, js wasm64p32 +#+private +package os2 + +import "base:runtime" + +_heap_allocator_proc :: runtime.wasm_allocator_proc diff --git a/core/os/os2/path_js.odin b/core/os/os2/path_js.odin new file mode 100644 index 000000000..0c0d1424b --- /dev/null +++ b/core/os/os2/path_js.odin @@ -0,0 +1,85 @@ +#+build js wasm32, js wasm64p32 +#+private +package os2 + +import "base:runtime" + +_Path_Separator :: '/' +_Path_Separator_String :: "/" +_Path_List_Separator :: ':' + +_is_path_separator :: proc(c: byte) -> (ok: bool) { + return c == _Path_Separator +} + +_mkdir :: proc(name: string, perm: int) -> (err: Error) { + return .Unsupported +} + +_mkdir_all :: proc(path: string, perm: int) -> (err: Error) { + return .Unsupported +} + +_remove_all :: proc(path: string) -> (err: Error) { + return .Unsupported +} + +_get_working_directory :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) { + return "", .Unsupported +} + +_set_working_directory :: proc(dir: string) -> (err: Error) { + return .Unsupported +} + +_get_executable_path :: proc(allocator: runtime.Allocator) -> (path: string, err: Error) { + return "", .Unsupported +} + +_are_paths_identical :: proc(a, b: string) -> bool { + return false +} + +_clean_path_handle_start :: proc(path: string, buffer: []u8) -> (rooted: bool, start: int) { + return +} + +_is_absolute_path :: proc(path: string) -> bool { + return false +} + +_get_absolute_path :: proc(path: string, allocator: runtime.Allocator) -> (absolute_path: string, err: Error) { + return "", .Unsupported +} + +_get_relative_path_handle_start :: proc(base, target: string) -> bool { + return false +} + +_get_common_path_len :: proc(base, target: string) -> int { + i := 0 + end := min(len(base), len(target)) + for j in 0..=end { + if j == end || _is_path_separator(base[j]) { + if base[i:j] == target[i:j] { + i = j + } else { + break + } + } + } + return i +} + +_split_path :: proc(path: string) -> (dir, file: string) { + i := len(path) - 1 + for i >= 0 && !_is_path_separator(path[i]) { + i -= 1 + } + if i == 0 { + return path[:i+1], path[i+1:] + } else if i > 0 { + return path[:i], path[i+1:] + } + return "", path +} \ No newline at end of file diff --git a/core/os/os2/pipe_js.odin b/core/os/os2/pipe_js.odin new file mode 100644 index 000000000..253228f86 --- /dev/null +++ b/core/os/os2/pipe_js.odin @@ -0,0 +1,14 @@ +#+build js wasm32, js wasm64p32 +#+private +package os2 + +_pipe :: proc() -> (r, w: ^File, err: Error) { + err = .Unsupported + return +} + +@(require_results) +_pipe_has_data :: proc(r: ^File) -> (ok: bool, err: Error) { + err = .Unsupported + return +} diff --git a/core/os/os2/process_js.odin b/core/os/os2/process_js.odin new file mode 100644 index 000000000..a2db3d56e --- /dev/null +++ b/core/os/os2/process_js.odin @@ -0,0 +1,87 @@ +#+build js wasm32, js wasm64p32 +#+private +package os2 + +import "base:runtime" +import "core:time" + + +_exit :: proc "contextless" (code: int) -> ! { + runtime.panic_contextless("exit") +} + +_get_uid :: proc() -> int { + return 0 +} + +_get_euid :: proc() -> int { + return 0 +} + +_get_gid :: proc() -> int { + return 0 +} + +_get_egid :: proc() -> int { + return 0 +} + +_get_pid :: proc() -> int { + return 0 +} + +_get_ppid :: proc() -> int { + return 0 +} + +_process_info_by_handle :: proc(process: Process, selection: Process_Info_Fields, allocator: runtime.Allocator) -> (info: Process_Info, err: Error) { + err = .Unsupported + return +} + +_current_process_info :: proc(selection: Process_Info_Fields, allocator: runtime.Allocator) -> (info: Process_Info, err: Error) { + err = .Unsupported + return +} + +_process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) { + err = .Unsupported + return +} + +_process_wait :: proc(process: Process, timeout: time.Duration) -> (process_state: Process_State, err: Error) { + err = .Unsupported + return +} + +_process_close :: proc(process: Process) -> Error { + return .Unsupported +} + +_process_kill :: proc(process: Process) -> (err: Error) { + return .Unsupported +} + +_process_info_by_pid :: proc(pid: int, selection: Process_Info_Fields, allocator: runtime.Allocator) -> (info: Process_Info, err: Error) { + err = .Unsupported + return +} + +_process_list :: proc(allocator: runtime.Allocator) -> (list: []int, err: Error) { + err = .Unsupported + return +} + +_process_open :: proc(pid: int, flags: Process_Open_Flags) -> (process: Process, err: Error) { + process.pid = pid + err = .Unsupported + return +} + +_process_handle_still_valid :: proc(p: Process) -> Error { + return nil +} + +_process_state_update_times :: proc(p: Process, state: ^Process_State) { + return +} diff --git a/core/os/os2/stat_js.odin b/core/os/os2/stat_js.odin new file mode 100644 index 000000000..439226490 --- /dev/null +++ b/core/os/os2/stat_js.odin @@ -0,0 +1,21 @@ +#+build js wasm32, js wasm64p32 +#+private +package os2 + +import "base:runtime" + +_fstat :: proc(f: ^File, allocator: runtime.Allocator) -> (fi: File_Info, err: Error) { + return {}, .Unsupported +} + +_stat :: proc(name: string, allocator: runtime.Allocator) -> (fi: File_Info, err: Error) { + return {}, .Unsupported +} + +_lstat :: proc(name: string, allocator: runtime.Allocator) -> (fi: File_Info, err: Error) { + return {}, .Unsupported +} + +_same_file :: proc(fi1, fi2: File_Info) -> bool { + return fi1.fullpath == fi2.fullpath +} \ No newline at end of file diff --git a/core/os/os2/temp_file_js.odin b/core/os/os2/temp_file_js.odin new file mode 100644 index 000000000..e1f2b3d95 --- /dev/null +++ b/core/os/os2/temp_file_js.odin @@ -0,0 +1,9 @@ +#+build js wasm32, js wasm64p32 +#+private +package os2 + +import "base:runtime" + +_temp_dir :: proc(allocator: runtime.Allocator) -> (string, runtime.Allocator_Error) { + return "", .Mode_Not_Implemented +} \ No newline at end of file -- cgit v1.2.3