Open frewsxcv opened 2 years ago
I haven't seen any crates with native dependencies buildable in a wasm/browser environment.
I'd be interested if there are any working examples of what that could look like.
Clang does support building wasm32 as a target (I think?) and if not Clang then at least setting the C compiler to Emscripten should work, but I haven't got that to work either.
export CC=emcc
cargo build --target wasm32-unknown-unknown
Compiling proj-sys v0.22.0 (/Users/coreyf/dev/georust/proj/proj-sys)
error: failed to run custom build command for `proj-sys v0.22.0 (/Users/coreyf/dev/georust/proj/proj-sys)`
Caused by:
process didn't exit successfully: `/Users/coreyf/dev/georust/proj/target/debug/build/proj-sys-141d6ea7039d6b8c/build-script-build` (exit status: 101)
--- stdout
cargo:rerun-if-env-changed=PROJ_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_wasm32-unknown-unknown
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_wasm32_unknown_unknown
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
cargo:rerun-if-env-changed=PKG_CONFIG_wasm32-unknown-unknown
cargo:rerun-if-env-changed=PKG_CONFIG_wasm32_unknown_unknown
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_wasm32-unknown-unknown
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_wasm32_unknown_unknown
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
CMAKE_TOOLCHAIN_FILE_wasm32-unknown-unknown = None
CMAKE_TOOLCHAIN_FILE_wasm32_unknown_unknown = None
TARGET_CMAKE_TOOLCHAIN_FILE = None
CMAKE_TOOLCHAIN_FILE = None
CMAKE_GENERATOR_wasm32-unknown-unknown = None
CMAKE_GENERATOR_wasm32_unknown_unknown = None
TARGET_CMAKE_GENERATOR = None
CMAKE_GENERATOR = None
CMAKE_PREFIX_PATH_wasm32-unknown-unknown = None
CMAKE_PREFIX_PATH_wasm32_unknown_unknown = None
TARGET_CMAKE_PREFIX_PATH = None
CMAKE_PREFIX_PATH = None
CMAKE_wasm32-unknown-unknown = None
CMAKE_wasm32_unknown_unknown = None
TARGET_CMAKE = None
CMAKE = None
running: "cmake" "/Users/coreyf/dev/georust/proj/proj-sys/PROJSRC/proj/proj-8.1.0" "-DBUILD_SHARED_LIBS=OFF" "-DBUILD_TESTING=OFF" "-DBUILD_CCT=OFF" "-DBUILD_CS2CS=OFF" "-DBUILD_GEOD=OFF" "-DBUILD_GIE=OFF" "-DBUILD_PROJ=OFF" "-DBUILD_PROJINFO=OFF" "-DBUILD_PROJSYNC=OFF" "-DENABLE_CURL=OFF" "-DENABLE_TIFF=OFF" "-DCMAKE_INSTALL_PREFIX=/Users/coreyf/dev/georust/proj/target/wasm32-unknown-unknown/debug/build/proj-sys-53bbbe1c8a420d33/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC" "-DCMAKE_C_COMPILER=/opt/homebrew/bin/emcc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC --target=wasm32-unknown-unknown" "-DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC" "-DCMAKE_ASM_COMPILER=/opt/homebrew/bin/emcc" "-DCMAKE_BUILD_TYPE=Debug"
-- The C compiler identification is Clang 14.0.0
-- The CXX compiler identification is Clang 13.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /opt/homebrew/bin/emcc
-- Check for working C compiler: /opt/homebrew/bin/emcc - broken
-- Configuring incomplete, errors occurred!
See also "/Users/coreyf/dev/georust/proj/target/wasm32-unknown-unknown/debug/build/proj-sys-53bbbe1c8a420d33/out/build/CMakeFiles/CMakeOutput.log".
See also "/Users/coreyf/dev/georust/proj/target/wasm32-unknown-unknown/debug/build/proj-sys-53bbbe1c8a420d33/out/build/CMakeFiles/CMakeError.log".
--- stderr
pkg-config unable to find existing libproj installation: pkg-config has not been configured to support cross-compilation.
Install a sysroot for the target platform and configure it via
PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a
cross-compiling wrapper for pkg-config and set it via
PKG_CONFIG environment variable.
building libproj from source
disabling tiff support
CMake Error at /opt/homebrew/Cellar/cmake/3.22.2/share/cmake/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler
"/opt/homebrew/bin/emcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/coreyf/dev/georust/proj/target/wasm32-unknown-unknown/debug/build/proj-sys-53bbbe1c8a420d33/out/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make -f Makefile cmTC_42d34/fast && /Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/cmTC_42d34.dir/build.make CMakeFiles/cmTC_42d34.dir/build
Building C object CMakeFiles/cmTC_42d34.dir/testCCompiler.c.o
/opt/homebrew/bin/emcc -ffunction-sections -fdata-sections -fPIC -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk -MD -MT CMakeFiles/cmTC_42d34.dir/testCCompiler.c.o -MF CMakeFiles/cmTC_42d34.dir/testCCompiler.c.o.d -o CMakeFiles/cmTC_42d34.dir/testCCompiler.c.o -c /Users/coreyf/dev/georust/proj/target/wasm32-unknown-unknown/debug/build/proj-sys-53bbbe1c8a420d33/out/build/CMakeFiles/CMakeTmp/testCCompiler.c
emcc: error: arm64: No such file or directory ("arm64" was expected to be an input file, based on the commandline arguments provided)
make[1]: *** [CMakeFiles/cmTC_42d34.dir/testCCompiler.c.o] Error 1
make: *** [cmTC_42d34/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:14 (project)
thread 'main' panicked at '
command did not execute successfully, got: exit status: 1
build script failed, must exit now', /Users/coreyf/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.48/src/lib.rs:975:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
~/d/g/proj (master|…) [101] $ export CC=emcc
~/d/g/proj (master|…) $ export C^C
~/d/g/proj (master|…) $ cargo build --target wasm32-unknown-unknown
Compiling proj-sys v0.22.0 (/Users/coreyf/dev/georust/proj/proj-sys)
error: failed to run custom build command for `proj-sys v0.22.0 (/Users/coreyf/dev/georust/proj/proj-sys)`
Caused by:
process didn't exit successfully: `/Users/coreyf/dev/georust/proj/target/debug/build/proj-sys-141d6ea7039d6b8c/build-script-build` (exit status: 101)
--- stdout
cargo:rerun-if-env-changed=PROJ_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_wasm32-unknown-unknown
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_wasm32_unknown_unknown
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
cargo:rerun-if-env-changed=PKG_CONFIG_wasm32-unknown-unknown
cargo:rerun-if-env-changed=PKG_CONFIG_wasm32_unknown_unknown
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_wasm32-unknown-unknown
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_wasm32_unknown_unknown
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
CMAKE_TOOLCHAIN_FILE_wasm32-unknown-unknown = None
CMAKE_TOOLCHAIN_FILE_wasm32_unknown_unknown = None
TARGET_CMAKE_TOOLCHAIN_FILE = None
CMAKE_TOOLCHAIN_FILE = None
CMAKE_GENERATOR_wasm32-unknown-unknown = None
CMAKE_GENERATOR_wasm32_unknown_unknown = None
TARGET_CMAKE_GENERATOR = None
CMAKE_GENERATOR = None
CMAKE_PREFIX_PATH_wasm32-unknown-unknown = None
CMAKE_PREFIX_PATH_wasm32_unknown_unknown = None
TARGET_CMAKE_PREFIX_PATH = None
CMAKE_PREFIX_PATH = None
CMAKE_wasm32-unknown-unknown = None
CMAKE_wasm32_unknown_unknown = None
TARGET_CMAKE = None
CMAKE = None
running: "cmake" "/Users/coreyf/dev/georust/proj/proj-sys/PROJSRC/proj/proj-8.1.0" "-DBUILD_SHARED_LIBS=OFF" "-DBUILD_TESTING=OFF" "-DBUILD_CCT=OFF" "-DBUILD_CS2CS=OFF" "-DBUILD_GEOD=OFF" "-DBUILD_GIE=OFF" "-DBUILD_PROJ=OFF" "-DBUILD_PROJINFO=OFF" "-DBUILD_PROJSYNC=OFF" "-DENABLE_CURL=OFF" "-DENABLE_TIFF=OFF" "-DCMAKE_INSTALL_PREFIX=/Users/coreyf/dev/georust/proj/target/wasm32-unknown-unknown/debug/build/proj-sys-53bbbe1c8a420d33/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC" "-DCMAKE_C_COMPILER=/opt/homebrew/bin/emcc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC --target=wasm32-unknown-unknown" "-DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC" "-DCMAKE_ASM_COMPILER=/opt/homebrew/bin/emcc" "-DCMAKE_BUILD_TYPE=Debug"
-- The C compiler identification is Clang 14.0.0
-- The CXX compiler identification is Clang 13.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /opt/homebrew/bin/emcc
-- Check for working C compiler: /opt/homebrew/bin/emcc - broken
-- Configuring incomplete, errors occurred!
See also "/Users/coreyf/dev/georust/proj/target/wasm32-unknown-unknown/debug/build/proj-sys-53bbbe1c8a420d33/out/build/CMakeFiles/CMakeOutput.log".
See also "/Users/coreyf/dev/georust/proj/target/wasm32-unknown-unknown/debug/build/proj-sys-53bbbe1c8a420d33/out/build/CMakeFiles/CMakeError.log".
--- stderr
pkg-config unable to find existing libproj installation: pkg-config has not been configured to support cross-compilation.
Install a sysroot for the target platform and configure it via
PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a
cross-compiling wrapper for pkg-config and set it via
PKG_CONFIG environment variable.
building libproj from source
disabling tiff support
CMake Error at /opt/homebrew/Cellar/cmake/3.22.2/share/cmake/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler
"/opt/homebrew/bin/emcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/coreyf/dev/georust/proj/target/wasm32-unknown-unknown/debug/build/proj-sys-53bbbe1c8a420d33/out/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make -f Makefile cmTC_85c58/fast && /Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/cmTC_85c58.dir/build.make CMakeFiles/cmTC_85c58.dir/build
Building C object CMakeFiles/cmTC_85c58.dir/testCCompiler.c.o
/opt/homebrew/bin/emcc -ffunction-sections -fdata-sections -fPIC -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk -MD -MT CMakeFiles/cmTC_85c58.dir/testCCompiler.c.o -MF CMakeFiles/cmTC_85c58.dir/testCCompiler.c.o.d -o CMakeFiles/cmTC_85c58.dir/testCCompiler.c.o -c /Users/coreyf/dev/georust/proj/target/wasm32-unknown-unknown/debug/build/proj-sys-53bbbe1c8a420d33/out/build/CMakeFiles/CMakeTmp/testCCompiler.c
emcc: error: arm64: No such file or directory ("arm64" was expected to be an input file, based on the commandline arguments provided)
make[1]: *** [CMakeFiles/cmTC_85c58.dir/testCCompiler.c.o] Error 1
make: *** [cmTC_85c58/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:14 (project)
thread 'main' panicked at '
command did not execute successfully, got: exit status: 1
build script failed, must exit now', /Users/coreyf/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.48/src/lib.rs:975:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Maybe relevant: ZSTD added support for wasm32-unknown-unknown
in https://github.com/gyscos/zstd-rs/pull/139 by adding shims for stdlib.h
and string.h
. But that seems unrelated to
pkg-config unable to find existing libproj installation: pkg-config has not been configured to support cross-compilation
Another relevant link https://github.com/rustwasm/team/issues/291
I spent a couple minutes trying to build for wasm32-unknown-emscripten
without much luck. These build changes helped progress a little further
--- a/proj-sys/build.rs
+++ b/proj-sys/build.rs
@@ -88,6 +88,10 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
let mut archive = Archive::new(tar);
archive.unpack("PROJSRC/proj")?;
let mut config = cmake::Config::new("PROJSRC/proj/proj-8.1.0");
+ config.define("CMAKE_TRY_COMPILE_TARGET_TYPE", "STATIC_LIBRARY");
+ config.define("CMAKE_C_COMPILER_WORKS", "1");
+ config.define("CMAKE_CXX_COMPILER_WORKS", "1");
+ config.define("USE_THREAD", "0");
config.define("BUILD_SHARED_LIBS", "OFF");
config.define("BUILD_TESTING", "OFF");
config.define("BUILD_CCT", "OFF");
IMO wasm32-unknown-unknown
is pretty hopeless for the current time given Proj's reliance on several system libs, not least Sqlite3 (potentially unless you go back to a proj version before they added sqlite3 as a dependency).
That leaves wasm32-unknown-emscripten
, which at least in principle has the potential to work. I think the first course of action here would be to build Proj to emscripten outside of rust, just to verify dependencies can compile.
When I run
git clone https://github.com/OSGeo/PROJ
cd PROJ
mkdir build
cd build
emcmake cmake -DBUILD_APPS=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DENABLE_TIFF=OFF ..
I get
CMake Error at CMakeLists.txt:176 (message):
sqlite3 dependency not found!
sqlite3 can be built to WASM via emscripten (see https://github.com/sql-js/sql.js). So the next step would be figuring out how to first build sqlite3 via emscripten then use that built sqlite3 to link to proj. Maybe relevant: https://emscripten.org/docs/compiling/Building-Projects.html#using-libraries
There seems to be a Proj build for WASM: https://github.com/jvail/spl.js
Has anyone had any luck compiling for WASM?
Also a note that someone on this rust+wasm+c thread seems to have made an example repo for creating a wasm-pack build using targets other than wasm32-unknown-unknown
.
Useful thread: https://github.com/rustwasm/team/issues/291