Open tanis2000 opened 5 years ago
The answer here may be use remove the use of libc and use types from std::os::raw instead.
Although it may be necessary to hide the APIs that accept FILE arguments.
@jdm I tried what you suggested and the current state of my tests is here: https://github.com/tanis2000/rust-stb-image/tree/no-libc
It happens that it's still working fine on macOS (haven't tried other desktop OS yet) but if I include this crate in another project and build it with cargo web build
I get an error during linking:
error: linking with `rust-lld` failed: exit code: 1
|
= note: "rust-lld" "-flavor" "wasm" "--no-threads" "-z" "stack-size=1048576" "--stack-first" "--allow-undefined" "--no-entry" "--export-table" "--fatal-warnings" "--export-dynamic" "--no-demangle" "-L" "/Users/tanis/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-unknown/lib" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.1552888bf400l3vb.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.1a86z27dt4lzn0ab.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.1k9s2bfzxlhi2zoq.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.1y85qwr4wbdlws0d.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.2271eouzpwwr1mbo.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.22holi3za28xrzjh.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.29dkwx7x2s0upl75.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.2hebggoq03qbonvd.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.2ii1zcy8gt785z7e.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.2s73e3fl00each62.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.33oulgo7004bx9i0.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.36csiy6r15j9jmn2.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.3cgilsyycevn4we2.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.3vggcc5q7vgexacs.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.3xgfliafx15obf51.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.4aio88nckybg003d.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.4bxrzsygua02rbdn.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.4fwk4tgswjlgc55h.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.4r9n8erk35hybu05.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.54wx996rx71sx5o9.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.5516hcrbtlyq64fd.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.5ddc0r4zwpbis3iu.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.5exz1idydh1i78e5.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.8olvnts1nd7bzt8.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.v6fu6bl5ulfymeh.rcgu.o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.yaaqn9bokzzpdkb.rcgu.o" "-o" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.wasm" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/test_stb_image.2w619fg82u1aekgt.rcgu.o" "--gc-sections" "-O0" "-L" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps" "-L" "/Users/tanis/Documents/test-stb-image/target/debug/deps" "-L" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/build/stb_image-b36a7eba92a2b177/out" "-L" "/Users/tanis/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-unknown/lib" "/Users/tanis/Documents/test-stb-image/target/wasm32-unknown-unknown/debug/deps/libstb_image-63d5aa55b7ef9e8f.rlib" "/Users/tanis/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-unknown/lib/libstd-3df4b302d72ef6ec.rlib" "/Users/tanis/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-unknown/lib/libpanic_abort-9bf16624dd05c0fb.rlib" "/Users/tanis/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-unknown/lib/libdlmalloc-a9b824235cb3bcc0.rlib" "/Users/tanis/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-unknown/lib/libbacktrace_sys-f8521075e248b627.rlib" "/Users/tanis/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-unknown/lib/libunwind-7c91ffdc8da860d3.rlib" "/Users/tanis/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-unknown/lib/librustc_demangle-0ad27b9879d551d3.rlib" "/Users/tanis/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-unknown/lib/liblibc-588f18eae3ea58be.rlib" "/Users/tanis/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-unknown/lib/liballoc-4ebf5caee903d98f.rlib" "/Users/tanis/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-unknown/lib/librustc_std_workspace_core-8895b32baedb08c6.rlib" "/Users/tanis/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-unknown/lib/libcore-6a9d233d01acc350.rlib" "/Users/tanis/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-unknown/lib/libcompiler_builtins-851bb3b5f6c4db49.rlib"
= note: rust-lld: error: unknown file type: stb_image.o
@tanis2000 This crate uses a very old version of cc-rs to compile the C library, back when it used to be called gcc-rs. Try upgrading it to a modern version and updating build.rs and see if that makes a different.
@jdm I upgraded the build.rs script to the latest cc-rs but it actually made things worse.
It works fine when building for the desktop but it's giving the following error when compiling with cargo web build
from within the library folder itself:
error: failed to run custom build command for `stb_image v0.2.2 (/Users/tanis/Documents/rust-stb-image)`
process didn't exit successfully: `/Users/tanis/Documents/rust-stb-image/target/debug/build/stb_image-a85c27b930fed555/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("wasm32-unknown-unknown")
OPT_LEVEL = Some("0")
HOST = Some("x86_64-apple-darwin")
CC_wasm32-unknown-unknown = None
CC_wasm32_unknown_unknown = None
TARGET_CC = None
CC = None
CFLAGS_wasm32-unknown-unknown = None
CFLAGS_wasm32_unknown_unknown = None
TARGET_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("true")
running: "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-Wall" "-Wextra" "-o" "/Users/tanis/Documents/rust-stb-image/target/wasm32-unknown-unknown/debug/build/stb_image-f82d8dbbea50779c/out/src/stb_image.o" "-c" "src/stb_image.c"
cargo:warning=src/stb_image.c:390:10: fatal error: 'stdio.h' file not found
cargo:warning=#include <stdio.h>
cargo:warning= ^~~~~~~~~
cargo:warning=1 error generated.
exit code: 1
--- stderr
thread 'main' panicked at '
Internal error occurred: Command "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-Wall" "-Wextra" "-o" "/Users/tanis/Documents/rust-stb-image/target/wasm32-unknown-unknown/debug/build/stb_image-f82d8dbbea50779c/out/src/stb_image.o" "-c" "src/stb_image.c" with args "clang" did not execute successfully (status code exit code: 1).
', /Users/tanis/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.35/src/lib.rs:2398:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
Sorry, that exceeds my ability to make guesses about solutions at this point.
My guess is that I need to tell clang where the wasm32 sysroot is, but I have no clue myself.
I've opened a PR with my changes where I switched from libc
to std::os::raw
types. You can review it here: https://github.com/servo/rust-stb-image/pull/95
It still doesn't compile for wasm32 and I haven't yet found a way around it, but at least we have a starting point.
was there a solution for this? having same issue too
This is somewhat connected to https://github.com/servo/rust-stb-image/issues/91
When trying to compile for the wasm32 target (without emscripten) but with
cargo web build
, I get some errors due to the libc dependency.i.e.: