Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't build crate as wasm target #115

Open
frewsxcv opened this issue Feb 24, 2022 · 12 comments
Open

Can't build crate as wasm target #115

frewsxcv opened this issue Feb 24, 2022 · 12 comments

Comments

@frewsxcv
Copy link
Member

cargo build --target wasm32-unknown-unknown
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 --target=wasm32-unknown-unknown" "-DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm/bin/clang" "-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 --target=wasm32-unknown-unknown" "-DCMAKE_ASM_COMPILER=/opt/homebrew/opt/llvm/bin/clang" "-DCMAKE_BUILD_TYPE=Debug"
  -- The C compiler identification is Clang 13.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/opt/llvm/bin/clang
  -- Check for working C compiler: /opt/homebrew/opt/llvm/bin/clang - 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/opt/llvm/bin/clang"

    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_87c4b/fast && /Library/Developer/CommandLineTools/usr/bin/make  -f CMakeFiles/cmTC_87c4b.dir/build.make CMakeFiles/cmTC_87c4b.dir/build
      Building C object CMakeFiles/cmTC_87c4b.dir/testCCompiler.c.o
      /opt/homebrew/opt/llvm/bin/clang   -ffunction-sections -fdata-sections -fPIC --target=wasm32-unknown-unknown  -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk -MD -MT CMakeFiles/cmTC_87c4b.dir/testCCompiler.c.o -MF CMakeFiles/cmTC_87c4b.dir/testCCompiler.c.o.d -o CMakeFiles/cmTC_87c4b.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
      clang-13: warning: argument unused during compilation: '-arch arm64' [-Wunused-command-line-argument]
      Linking C executable cmTC_87c4b
      /opt/homebrew/Cellar/cmake/3.22.2/bin/cmake -E cmake_link_script CMakeFiles/cmTC_87c4b.dir/link.txt --verbose=1
      /opt/homebrew/opt/llvm/bin/clang  -ffunction-sections -fdata-sections -fPIC --target=wasm32-unknown-unknown  -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names -L/opt/homebrew/opt/llvm/lib  CMakeFiles/cmTC_87c4b.dir/testCCompiler.c.o -o cmTC_87c4b 
      clang-13: warning: argument unused during compilation: '-arch arm64' [-Wunused-command-line-argument]
      wasm-ld: error: unknown argument: -search_paths_first
      wasm-ld: error: unknown argument: -headerpad_max_install_names
      wasm-ld: error: cannot open crt1.o: No such file or directory
      wasm-ld: error: unable to find library -lc
      wasm-ld: error: cannot open /opt/homebrew/Cellar/llvm/13.0.0_2/lib/clang/13.0.0/lib/libclang_rt.builtins-wasm32.a: No such file or directory
      clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
      make[1]: *** [cmTC_87c4b] Error 1
      make: *** [cmTC_87c4b/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
@michaelkirk
Copy link
Member

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.

@frewsxcv
Copy link
Member Author

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.

@frewsxcv
Copy link
Member Author

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

@kylebarron
Copy link
Contributor

Maybe relevant: ZSTD added support for wasm32-unknown-unknown in gyscos/zstd-rs#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

@frewsxcv
Copy link
Member Author

frewsxcv commented Mar 5, 2022

Another relevant link rustwasm/team#291

@kylebarron
Copy link
Contributor

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");

@kylebarron
Copy link
Contributor

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

@pka
Copy link
Member

pka commented Mar 12, 2022

There seems to be a Proj build for WASM: https://github.com/jvail/spl.js

@Rennzie
Copy link

Rennzie commented Jun 7, 2022

Has anyone had any luck compiling for WASM?

@frewsxcv
Copy link
Member Author

OSGeo/PROJ-JNI#40

@kylebarron
Copy link
Contributor

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.

@urschrei
Copy link
Member

Useful thread: rustwasm/team#291

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants