gfx-rs / gfx

[maintenance mode] A low-overhead Vulkan-like GPU API for Rust.
http://gfx-rs.github.io/
Apache License 2.0
5.35k stars 547 forks source link

Failed to compile Vulkan on master branch for Android #2218

Open Michael-Lfx opened 6 years ago

Michael-Lfx commented 6 years ago

When using cargo build --bins --target=aarch64-linux-android --features=vulkan to build so for Android, it fails with the following output.

cargo build --bins --target=aarch64-linux-android --features=vulkan
   Compiling cfg-if v0.1.4
   Compiling nodrop v0.1.12
   Compiling memoffset v0.2.1
   Compiling scopeguard v0.3.3
   Compiling lazy_static v1.0.1
   Compiling libc v0.2.42
   Compiling void v1.0.2
   Compiling rustc-demangle v0.1.8
   Compiling either v1.5.0
   Compiling ucd-util v0.1.1
   Compiling remove_dir_all v0.5.1
   Compiling adler32 v1.0.3
   Compiling byteorder v1.2.3
   Compiling utf8-ranges v1.0.0
   Compiling bitflags v1.0.3
   Compiling smallvec v0.6.2
   Compiling quick-error v1.2.2
   Compiling color_quant v1.0.1
   Compiling lzw v0.10.0
   Compiling termcolor v0.3.6
   Compiling scoped_threadpool v0.1.9
   Compiling android_glue v0.2.3
   Compiling num-traits v0.2.5
   Compiling rayon-core v1.4.0
   Compiling num-integer v0.1.39
   Compiling num-iter v0.1.37
   Compiling serde v1.0.70
   Compiling crossbeam-utils v0.2.2
   Compiling log v0.4.3
   Compiling arrayvec v0.4.7
   Compiling regex v1.0.1
   Compiling unreachable v1.0.0
   Compiling inflate v0.3.4
   Compiling regex-syntax v0.6.1
   Compiling humantime v1.1.1
   Compiling fxhash v0.2.1
   Compiling deflate v0.7.18
   Compiling backtrace-sys v0.1.23
error: failed to run custom build command for `backtrace-sys v0.1.23`
process didn't exit successfully: `/Users/Michael/rust_project/gfx/target/debug/build/backtrace-sys-16ec0a5005974392/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("aarch64-linux-android")
OPT_LEVEL = Some("0")
TARGET = Some("aarch64-linux-android")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("aarch64-linux-android")
TARGET = Some("aarch64-linux-android")
HOST = Some("x86_64-apple-darwin")
CC_aarch64-linux-android = None
CC_aarch64_linux_android = None
TARGET_CC = None
CC = None
TARGET = Some("aarch64-linux-android")
HOST = Some("x86_64-apple-darwin")
CFLAGS_aarch64-linux-android = None
CFLAGS_aarch64_linux_android = None
TARGET_CFLAGS = None
CFLAGS = None
DEBUG = Some("true")
running: "aarch64-linux-android-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-I" "src/libbacktrace" "-I" "/Users/Michael/rust_project/gfx/target/aarch64-linux-android/debug/build/backtrace-sys-f9a5316ca5ad925d/out" "-fvisibility=hidden" "-DBACKTRACE_ELF_SIZE=64" "-DBACKTRACE_SUPPORTED=1" "-DBACKTRACE_USES_MALLOC=1" "-DBACKTRACE_SUPPORTS_THREADS=0" "-DBACKTRACE_SUPPORTS_DATA=0" "-DHAVE_DL_ITERATE_PHDR=1" "-D_GNU_SOURCE=1" "-D_LARGE_FILES=1" "-Dbacktrace_full=__rbt_backtrace_full" "-Dbacktrace_dwarf_add=__rbt_backtrace_dwarf_add" "-Dbacktrace_initialize=__rbt_backtrace_initialize" "-Dbacktrace_pcinfo=__rbt_backtrace_pcinfo" "-Dbacktrace_syminfo=__rbt_backtrace_syminfo" "-Dbacktrace_get_view=__rbt_backtrace_get_view" "-Dbacktrace_release_view=__rbt_backtrace_release_view" "-Dbacktrace_alloc=__rbt_backtrace_alloc" "-Dbacktrace_free=__rbt_backtrace_free" "-Dbacktrace_vector_finish=__rbt_backtrace_vector_finish" "-Dbacktrace_vector_grow=__rbt_backtrace_vector_grow" "-Dbacktrace_vector_release=__rbt_backtrace_vector_release" "-Dbacktrace_close=__rbt_backtrace_close" "-Dbacktrace_open=__rbt_backtrace_open" "-Dbacktrace_print=__rbt_backtrace_print" "-Dbacktrace_simple=__rbt_backtrace_simple" "-Dbacktrace_qsort=__rbt_backtrace_qsort" "-Dbacktrace_create_state=__rbt_backtrace_create_state" "-Dbacktrace_uncompress_zdebug=__rbt_backtrace_uncompress_zdebug" "-o" "/Users/Michael/rust_project/gfx/target/aarch64-linux-android/debug/build/backtrace-sys-f9a5316ca5ad925d/out/src/libbacktrace/alloc.o" "-c" "src/libbacktrace/alloc.c"

--- stderr
thread 'main' panicked at '

Internal error occurred: Failed to find tool. Is `aarch64-linux-android-gcc` installed?

', /Users/Michael/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.17/src/lib.rs:2180:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

warning: build failed, waiting for other jobs to finish...
error: build failed
kvark commented 6 years ago

Thanks for filing the issue! It doesn't appear to be directly related to us, but rather to cc dependency:

Internal error occurred: Failed to find tool. Is aarch64-linux-android-gcc installed?

mtak- commented 6 years ago

This is a configuration issue. Here are the steps I took to get android building (works for lots of projects):

  1. Make standalone toolchains
    mkdir .NDK
    ${NDK_HOME}/build/tools/make_standalone_toolchain.py --api 26 --arch arm64 --install-dir .NDK/arm64
    # any additional architectures here
  2. Modify the PATH variable. Mozilla says to use a cargo config file, but I think that's not enough for certain dependencies (e.g. ones using cc).
    PATH=".NDK/arm64/bin:$PATH"
    # add any additional toolchains to PATH
  3. Build: cargo build --target aarch64-linux-android

Also, the executables won't work - android only supports native code as libraries.. A rooted phone can run binaries, but I'm pretty sure glsl-to-spirv just won't work on mobile - it's not architected with that use case in mind. As a workaround, running glsl-to-spirv in build.rs should work.

I'll try to get Android (and iOS) on CI in the next week or so.