From 5f974059f46317328db64b9f0dcf9ead55f167fa Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Thu, 22 Jan 2026 21:34:46 +0100 Subject: [PATCH] move vendor:libc to vendor:libc-shim --- vendor/box2d/box2d_wasm.odin | 2 +- vendor/box2d/wasm.Makefile | 2 +- vendor/cgltf/cgltf_wasm.odin | 2 +- vendor/cgltf/src/Makefile | 2 +- vendor/{libc => libc-shim}/README.md | 6 ++--- vendor/{libc => libc-shim}/assert.odin | 0 vendor/{libc => libc-shim}/ctype.odin | 0 vendor/{libc => libc-shim}/include/alloca.h | 0 vendor/{libc => libc-shim}/include/assert.h | 0 vendor/{libc => libc-shim}/include/ctype.h | 0 vendor/{libc => libc-shim}/include/inttypes.h | 0 vendor/{libc => libc-shim}/include/math.h | 0 vendor/{libc => libc-shim}/include/sched.h | 0 vendor/{libc => libc-shim}/include/stdio.h | 0 vendor/{libc => libc-shim}/include/stdlib.h | 0 vendor/{libc => libc-shim}/include/string.h | 0 vendor/{libc => libc-shim}/include/time.h | 0 vendor/libc-shim/libc.odin | 26 +++++++++++++++++++ vendor/{libc => libc-shim}/math.odin | 0 vendor/{libc => libc-shim}/sched.odin | 0 vendor/{libc => libc-shim}/stdio.odin | 4 +-- vendor/{libc => libc-shim}/stdlib.odin | 0 vendor/{libc => libc-shim}/string.odin | 0 vendor/{libc => libc-shim}/time.odin | 0 vendor/libc/libc.odin | 25 +----------------- vendor/stb/image/stb_image_wasm.odin | 2 +- vendor/stb/rect_pack/stb_rect_pack_wasm.odin | 2 +- vendor/stb/src/Makefile | 12 ++++----- vendor/stb/truetype/stb_truetype_wasm.odin | 2 +- 29 files changed, 45 insertions(+), 42 deletions(-) rename vendor/{libc => libc-shim}/README.md (79%) rename vendor/{libc => libc-shim}/assert.odin (100%) rename vendor/{libc => libc-shim}/ctype.odin (100%) rename vendor/{libc => libc-shim}/include/alloca.h (100%) rename vendor/{libc => libc-shim}/include/assert.h (100%) rename vendor/{libc => libc-shim}/include/ctype.h (100%) rename vendor/{libc => libc-shim}/include/inttypes.h (100%) rename vendor/{libc => libc-shim}/include/math.h (100%) rename vendor/{libc => libc-shim}/include/sched.h (100%) rename vendor/{libc => libc-shim}/include/stdio.h (100%) rename vendor/{libc => libc-shim}/include/stdlib.h (100%) rename vendor/{libc => libc-shim}/include/string.h (100%) rename vendor/{libc => libc-shim}/include/time.h (100%) create mode 100644 vendor/libc-shim/libc.odin rename vendor/{libc => libc-shim}/math.odin (100%) rename vendor/{libc => libc-shim}/sched.odin (100%) rename vendor/{libc => libc-shim}/stdio.odin (98%) rename vendor/{libc => libc-shim}/stdlib.odin (100%) rename vendor/{libc => libc-shim}/string.odin (100%) rename vendor/{libc => libc-shim}/time.odin (100%) diff --git a/vendor/box2d/box2d_wasm.odin b/vendor/box2d/box2d_wasm.odin index 0fcaf753f..1bbe9b8bc 100644 --- a/vendor/box2d/box2d_wasm.odin +++ b/vendor/box2d/box2d_wasm.odin @@ -1,4 +1,4 @@ #+build wasm32, wasm64p32 package vendor_box2d -@(require) import _ "vendor:libc" +@(require) import _ "vendor:libc-shim" diff --git a/vendor/box2d/wasm.Makefile b/vendor/box2d/wasm.Makefile index 80dd2ba14..5cce30ad1 100644 --- a/vendor/box2d/wasm.Makefile +++ b/vendor/box2d/wasm.Makefile @@ -11,7 +11,7 @@ VERSION = 3.1.1 SRCS = $(wildcard box2d-$(VERSION)/src/*.c) OBJS_SIMD = $(SRCS:.c=_simd.o) OBJS = $(SRCS:.c=.o) -SYSROOT = $(shell odin root)/vendor/libc +SYSROOT = $(shell odin root)/vendor/libc-shim CFLAGS = -Ibox2d-$(VERSION)/include --target=wasm32 -D__EMSCRIPTEN__ -DNDEBUG -O3 --sysroot=$(SYSROOT) all: lib/box2d_wasm.o lib/box2d_wasm_simd.o diff --git a/vendor/cgltf/cgltf_wasm.odin b/vendor/cgltf/cgltf_wasm.odin index fb612b2ac..1404fc592 100644 --- a/vendor/cgltf/cgltf_wasm.odin +++ b/vendor/cgltf/cgltf_wasm.odin @@ -1,4 +1,4 @@ #+build wasm32, wasm64p32 package cgltf -@(require) import _ "vendor:libc" +@(require) import _ "vendor:libc-shim" diff --git a/vendor/cgltf/src/Makefile b/vendor/cgltf/src/Makefile index 0dd450ce0..f4dc8c12c 100644 --- a/vendor/cgltf/src/Makefile +++ b/vendor/cgltf/src/Makefile @@ -8,7 +8,7 @@ endif wasm: mkdir -p ../lib - $(CC) -c -Os --target=wasm32 --sysroot=$(shell odin root)/vendor/libc cgltf.c -o ../lib/cgltf_wasm.o + $(CC) -c -Os --target=wasm32 --sysroot=$(shell odin root)/vendor/libc-shim cgltf.c -o ../lib/cgltf_wasm.o unix: mkdir -p ../lib diff --git a/vendor/libc/README.md b/vendor/libc-shim/README.md similarity index 79% rename from vendor/libc/README.md rename to vendor/libc-shim/README.md index 1dd50c5a9..9b44984f6 100644 --- a/vendor/libc/README.md +++ b/vendor/libc-shim/README.md @@ -1,11 +1,11 @@ -# vendor:libc +# vendor:libc-shim A (very small) subset of a libc implementation over Odin libraries. This is mainly intended for use in Odin WASM builds to allow using libraries like box2d, cgltf etc. without emscripten hacks. -You can use this with clang by doing `clang -c --target=wasm32 --sysroot=$(odin root)/vendor/libc` (+ all other flags and inputs). +You can use this with clang by doing `clang -c --target=wasm32 --sysroot=$(odin root)/vendor/libc-shim` (+ all other flags and inputs). This will (if all the libc usage of the library is implemented) spit out a `.o` file you can use with the foreign import system. -If you then also make sure this package is included in the Odin side of the project (`@(require) import "vendor:libc"`) you will be able +If you then also make sure this package is included in the Odin side of the project (`@(require) import "vendor:libc-shim"`) you will be able compile to WASM like Odin expects. This is currently used by `vendor:box2d`, `vendor:stb/image`, `vendor:stb/truetype`, `vendor:stb/rect_pack`, and `vendor:cgltf`. diff --git a/vendor/libc/assert.odin b/vendor/libc-shim/assert.odin similarity index 100% rename from vendor/libc/assert.odin rename to vendor/libc-shim/assert.odin diff --git a/vendor/libc/ctype.odin b/vendor/libc-shim/ctype.odin similarity index 100% rename from vendor/libc/ctype.odin rename to vendor/libc-shim/ctype.odin diff --git a/vendor/libc/include/alloca.h b/vendor/libc-shim/include/alloca.h similarity index 100% rename from vendor/libc/include/alloca.h rename to vendor/libc-shim/include/alloca.h diff --git a/vendor/libc/include/assert.h b/vendor/libc-shim/include/assert.h similarity index 100% rename from vendor/libc/include/assert.h rename to vendor/libc-shim/include/assert.h diff --git a/vendor/libc/include/ctype.h b/vendor/libc-shim/include/ctype.h similarity index 100% rename from vendor/libc/include/ctype.h rename to vendor/libc-shim/include/ctype.h diff --git a/vendor/libc/include/inttypes.h b/vendor/libc-shim/include/inttypes.h similarity index 100% rename from vendor/libc/include/inttypes.h rename to vendor/libc-shim/include/inttypes.h diff --git a/vendor/libc/include/math.h b/vendor/libc-shim/include/math.h similarity index 100% rename from vendor/libc/include/math.h rename to vendor/libc-shim/include/math.h diff --git a/vendor/libc/include/sched.h b/vendor/libc-shim/include/sched.h similarity index 100% rename from vendor/libc/include/sched.h rename to vendor/libc-shim/include/sched.h diff --git a/vendor/libc/include/stdio.h b/vendor/libc-shim/include/stdio.h similarity index 100% rename from vendor/libc/include/stdio.h rename to vendor/libc-shim/include/stdio.h diff --git a/vendor/libc/include/stdlib.h b/vendor/libc-shim/include/stdlib.h similarity index 100% rename from vendor/libc/include/stdlib.h rename to vendor/libc-shim/include/stdlib.h diff --git a/vendor/libc/include/string.h b/vendor/libc-shim/include/string.h similarity index 100% rename from vendor/libc/include/string.h rename to vendor/libc-shim/include/string.h diff --git a/vendor/libc/include/time.h b/vendor/libc-shim/include/time.h similarity index 100% rename from vendor/libc/include/time.h rename to vendor/libc-shim/include/time.h diff --git a/vendor/libc-shim/libc.odin b/vendor/libc-shim/libc.odin new file mode 100644 index 000000000..a5508e14f --- /dev/null +++ b/vendor/libc-shim/libc.odin @@ -0,0 +1,26 @@ +package odin_libc + +import "base:runtime" + +import "core:mem" + +@(private) +g_ctx: runtime.Context +@(private) +g_allocator: mem.Compat_Allocator + +@(init) +init_context :: proc "contextless" () { + g_ctx = runtime.default_context() + context = g_ctx + + // Wrapping the allocator with the mem.Compat_Allocator so we can + // mimic the realloc semantics. + mem.compat_allocator_init(&g_allocator, g_ctx.allocator) + g_ctx.allocator = mem.compat_allocator(&g_allocator) +} + +// NOTE: the allocator must respect an `old_size` of `-1` on resizes! +set_context :: proc(ctx := context) { + g_ctx = ctx +} diff --git a/vendor/libc/math.odin b/vendor/libc-shim/math.odin similarity index 100% rename from vendor/libc/math.odin rename to vendor/libc-shim/math.odin diff --git a/vendor/libc/sched.odin b/vendor/libc-shim/sched.odin similarity index 100% rename from vendor/libc/sched.odin rename to vendor/libc-shim/sched.odin diff --git a/vendor/libc/stdio.odin b/vendor/libc-shim/stdio.odin similarity index 98% rename from vendor/libc/stdio.odin rename to vendor/libc-shim/stdio.odin index d41f790ee..e269b8986 100644 --- a/vendor/libc/stdio.odin +++ b/vendor/libc-shim/stdio.odin @@ -17,7 +17,7 @@ EOF :: -1 @(require, linkage="strong", link_name="fopen") fopen :: proc "c" (path: cstring, mode: cstring) -> FILE { context = g_ctx - unimplemented("vendor/libc: fopen") + unimplemented("vendor/libc-shim: fopen") } @(require, linkage="strong", link_name="fseek") @@ -366,7 +366,7 @@ _sscanf :: proc "c" (str, fmt: [^]byte, orig_ptrs: [^]rawptr) -> i32 { i = 0 k = t == 'c' ? width + 1 : 31 if size == .l { - unimplemented("vendor/libc: sscanf wide character support") + unimplemented("vendor/libc-shim: sscanf wide character support") } else if alloc { s = make([^]byte, k) if s == nil { diff --git a/vendor/libc/stdlib.odin b/vendor/libc-shim/stdlib.odin similarity index 100% rename from vendor/libc/stdlib.odin rename to vendor/libc-shim/stdlib.odin diff --git a/vendor/libc/string.odin b/vendor/libc-shim/string.odin similarity index 100% rename from vendor/libc/string.odin rename to vendor/libc-shim/string.odin diff --git a/vendor/libc/time.odin b/vendor/libc-shim/time.odin similarity index 100% rename from vendor/libc/time.odin rename to vendor/libc-shim/time.odin diff --git a/vendor/libc/libc.odin b/vendor/libc/libc.odin index a5508e14f..7af35b090 100644 --- a/vendor/libc/libc.odin +++ b/vendor/libc/libc.odin @@ -1,26 +1,3 @@ package odin_libc -import "base:runtime" - -import "core:mem" - -@(private) -g_ctx: runtime.Context -@(private) -g_allocator: mem.Compat_Allocator - -@(init) -init_context :: proc "contextless" () { - g_ctx = runtime.default_context() - context = g_ctx - - // Wrapping the allocator with the mem.Compat_Allocator so we can - // mimic the realloc semantics. - mem.compat_allocator_init(&g_allocator, g_ctx.allocator) - g_ctx.allocator = mem.compat_allocator(&g_allocator) -} - -// NOTE: the allocator must respect an `old_size` of `-1` on resizes! -set_context :: proc(ctx := context) { - g_ctx = ctx -} +#panic("`vendor:libc` has been moved, use `vendor:libc-shim` instead.") diff --git a/vendor/stb/image/stb_image_wasm.odin b/vendor/stb/image/stb_image_wasm.odin index f43012383..cfad4725a 100644 --- a/vendor/stb/image/stb_image_wasm.odin +++ b/vendor/stb/image/stb_image_wasm.odin @@ -1,4 +1,4 @@ #+build wasm32, wasm64p32 package stb_image -@(require) import _ "vendor:libc" +@(require) import _ "vendor:libc-shim" diff --git a/vendor/stb/rect_pack/stb_rect_pack_wasm.odin b/vendor/stb/rect_pack/stb_rect_pack_wasm.odin index c4e2e5160..c9b6f3de8 100644 --- a/vendor/stb/rect_pack/stb_rect_pack_wasm.odin +++ b/vendor/stb/rect_pack/stb_rect_pack_wasm.odin @@ -1,4 +1,4 @@ #+build wasm32, wasm64p32 package stb_rect_pack -@(require) import _ "vendor:libc" +@(require) import _ "vendor:libc-shim" diff --git a/vendor/stb/src/Makefile b/vendor/stb/src/Makefile index 194ea5e75..94ba4d5bf 100644 --- a/vendor/stb/src/Makefile +++ b/vendor/stb/src/Makefile @@ -8,12 +8,12 @@ endif wasm: mkdir -p ../lib - $(CC) -c -Os --target=wasm32 --sysroot=$(shell odin root)/vendor/libc stb_image.c -o ../lib/stb_image_wasm.o -DSTBI_NO_STDIO - $(CC) -c -Os --target=wasm32 --sysroot=$(shell odin root)/vendor/libc stb_image_write.c -o ../lib/stb_image_write_wasm.o -DSTBI_WRITE_NO_STDIO - $(CC) -c -Os --target=wasm32 --sysroot=$(shell odin root)/vendor/libc stb_image_resize.c -o ../lib/stb_image_resize_wasm.o - $(CC) -c -Os --target=wasm32 --sysroot=$(shell odin root)/vendor/libc stb_truetype.c -o ../lib/stb_truetype_wasm.o - # $(CC) -c -Os --target=wasm32 --sysroot=$(shell odin root)/vendor/libc stb_vorbis.c -o ../lib/stb_vorbis_wasm.o -DSTB_VORBIS_NO_STDIO - $(CC) -c -Os --target=wasm32 --sysroot=$(shell odin root)/vendor/libc stb_rect_pack.c -o ../lib/stb_rect_pack_wasm.o + $(CC) -c -Os --target=wasm32 --sysroot=$(shell odin root)/vendor/libc-shim stb_image.c -o ../lib/stb_image_wasm.o -DSTBI_NO_STDIO + $(CC) -c -Os --target=wasm32 --sysroot=$(shell odin root)/vendor/libc-shim stb_image_write.c -o ../lib/stb_image_write_wasm.o -DSTBI_WRITE_NO_STDIO + $(CC) -c -Os --target=wasm32 --sysroot=$(shell odin root)/vendor/libc-shim stb_image_resize.c -o ../lib/stb_image_resize_wasm.o + $(CC) -c -Os --target=wasm32 --sysroot=$(shell odin root)/vendor/libc-shim stb_truetype.c -o ../lib/stb_truetype_wasm.o + # $(CC) -c -Os --target=wasm32 --sysroot=$(shell odin root)/vendor/libc-shim stb_vorbis.c -o ../lib/stb_vorbis_wasm.o -DSTB_VORBIS_NO_STDIO + $(CC) -c -Os --target=wasm32 --sysroot=$(shell odin root)/vendor/libc-shim stb_rect_pack.c -o ../lib/stb_rect_pack_wasm.o $(CC) -c -Os --target=wasm32 stb_sprintf.c -o ../lib/stb_sprintf_wasm.o unix: diff --git a/vendor/stb/truetype/stb_truetype_wasm.odin b/vendor/stb/truetype/stb_truetype_wasm.odin index f36239086..727ba3ef0 100644 --- a/vendor/stb/truetype/stb_truetype_wasm.odin +++ b/vendor/stb/truetype/stb_truetype_wasm.odin @@ -1,4 +1,4 @@ #+build wasm32, wasm64p32 package stb_truetype -@(require) import _ "vendor:libc" +@(require) import _ "vendor:libc-shim"