use #exists to provide good errors for common missing libraries

This commit is contained in:
Laytan Laats
2024-06-04 20:13:51 +02:00
parent b47a15733d
commit 3e159736cd
24 changed files with 143 additions and 110 deletions
+19 -6
View File
@@ -2,13 +2,26 @@ package stb_image
import c "core:c/libc"
@(private)
LIB :: (
"../lib/stb_image.lib" when ODIN_OS == .Windows
else "../lib/stb_image.a" when ODIN_OS == .Linux
else "../lib/darwin/stb_image.a" when ODIN_OS == .Darwin
else ""
)
when LIB != "" {
when !#exists(LIB) {
// The STB libraries are shipped with the compiler on Windows so a Windows specific message should not be needed.
#panic("Could not find the compiled STB libraries, they can be compiled by running `make -C \"" + ODIN_ROOT + "vendor/stb/src\"`")
}
foreign import stbi { LIB }
} else {
foreign import stbi "system:stb_image"
}
#assert(size_of(c.int) == size_of(b32))
when ODIN_OS == .Windows { foreign import stbi "../lib/stb_image.lib" }
else when ODIN_OS == .Linux { foreign import stbi "../lib/stb_image.a" }
else when ODIN_OS == .Darwin { foreign import stbi "../lib/darwin/stb_image.a" }
else { foreign import stbi "system:stb_image" }
#assert(size_of(b32) == size_of(c.int))
//
+17 -4
View File
@@ -2,11 +2,24 @@ package stb_image
import c "core:c/libc"
when ODIN_OS == .Windows { foreign import lib "../lib/stb_image_resize.lib" }
else when ODIN_OS == .Linux { foreign import lib "../lib/stb_image_resize.a" }
else when ODIN_OS == .Darwin { foreign import lib "../lib/darwin/stb_image_resize.a" }
else { foreign import lib "system:stb_image_resize" }
@(private)
RESIZE_LIB :: (
"../lib/stb_image_resize.lib" when ODIN_OS == .Windows
else "../lib/stb_image_resize.a" when ODIN_OS == .Linux
else "../lib/darwin/stb_image_resize.a" when ODIN_OS == .Darwin
else ""
)
when RESIZE_LIB != "" {
when !#exists(RESIZE_LIB) {
// The STB libraries are shipped with the compiler on Windows so a Windows specific message should not be needed.
#panic("Could not find the compiled STB libraries, they can be compiled by running `make -C \"" + ODIN_ROOT + "vendor/stb/src\"`")
}
foreign import lib { RESIZE_LIB }
} else {
foreign import lib "system:stb_image_resize"
}
//////////////////////////////////////////////////////////////////////////////
//
+17 -4
View File
@@ -2,11 +2,24 @@ package stb_image
import c "core:c/libc"
when ODIN_OS == .Windows { foreign import stbiw "../lib/stb_image_write.lib" }
else when ODIN_OS == .Linux { foreign import stbiw "../lib/stb_image_write.a" }
else when ODIN_OS == .Darwin { foreign import stbiw "../lib/darwin/stb_image_write.a" }
else { foreign import stbiw "system:stb_image_write" }
@(private)
WRITE_LIB :: (
"../lib/stb_image_write.lib" when ODIN_OS == .Windows
else "../lib/stb_image_write.a" when ODIN_OS == .Linux
else "../lib/darwin/stb_image_write.a" when ODIN_OS == .Darwin
else ""
)
when WRITE_LIB != "" {
when !#exists(WRITE_LIB) {
// The STB libraries are shipped with the compiler on Windows so a Windows specific message should not be needed.
#panic("Could not find the compiled STB libraries, they can be compiled by running `make -C \"" + ODIN_ROOT + "vendor/stb/src\"`")
}
foreign import stbiw { WRITE_LIB }
} else {
foreign import stbiw "system:stb_image_write"
}
write_func :: proc "c" (ctx: rawptr, data: rawptr, size: c.int)