Issues building examples modules
I am super new to rust so please excuse me if this is trivial question but I really struggle to build any of the examples for linux. Building natively on my Mac works just fine but I wanted to build for linux so that I can use modules with redis running in a container.
First I tried cross compiling from mac os by following various articles such as e.g. https://timryan.org/2018/07/27/cross-compiling-linux-binaries-from-macos.html but to no avail. The issues always where that build.rs complained that some files e.g. types.h could not be found. After reinstalling xcode cli tools etc. I finally gave up on getting cross compilation to work for now. The next thing I tried was building using docker
docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp rust:latest cargo build --example hello
which at least did't fail immidiately but at the end failed with
[...]
Compiling redis-module v0.17.0 (/usr/src/myapp)
error: failed to run custom build command for `redis-module v0.17.0 (/usr/src/myapp)`
Caused by:
process didn't exit successfully: `/usr/src/myapp/target/debug/build/redis-module-ba440a6132e376c2/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("x86_64-unknown-linux-gnu")
OPT_LEVEL = Some("0")
HOST = Some("x86_64-unknown-linux-gnu")
CC_x86_64-unknown-linux-gnu = None
CC_x86_64_unknown_linux_gnu = None
HOST_CC = None
CC = None
CFLAGS_x86_64-unknown-linux-gnu = None
CFLAGS_x86_64_unknown_linux_gnu = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("true")
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "src/include/" "-Wall" "-Wextra" "-o" "/usr/src/myapp/target/debug/build/redis-module-fa94a2fb353d85d5/out/src/redismodule.o" "-c" "src/redismodule.c"
exit code: 0
AR_x86_64-unknown-linux-gnu = None
AR_x86_64_unknown_linux_gnu = None
HOST_AR = None
AR = None
running: "ar" "cq" "/usr/src/myapp/target/debug/build/redis-module-fa94a2fb353d85d5/out/libredismodule.a" "/usr/src/myapp/target/debug/build/redis-module-fa94a2fb353d85d5/out/src/redismodule.o"
exit code: 0
running: "ar" "s" "/usr/src/myapp/target/debug/build/redis-module-fa94a2fb353d85d5/out/libredismodule.a"
exit code: 0
cargo:rustc-link-lib=static=redismodule
cargo:rustc-link-search=native=/usr/src/myapp/target/debug/build/redis-module-fa94a2fb353d85d5/out
--- stderr
thread 'main' panicked at 'Unable to find libclang: "couldn\'t find any valid shared libraries matching: [\'libclang.so\', \'libclang-*.so\', \'libclang.so.*\', \'libclang-*.so.*\'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [])"', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.58.1/src/lib.rs:2057:31
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Any suggestions how to quickly get up and running building the examples in this repo would be very appreciated :)
@SDesch I mostly agree with your conclusion regarding cross compilation -- it's a bit complicated since we're not talking about pure Rust code, but code that links to C code and involves bindgen.
The Docker image solution looks much more promising.
I think the issue you ran into is due to bindgen requiring clang and llvm, which are apparently not installed in the rust Docker image.
Adding apt-get update && apt-get install clang fixes it. You can either run these before the cargo build command, or (which I'd recommend) build a custom Docker images FROM rust:latest that adds the package.
@SDesch I mostly agree with your conclusion regarding cross compilation -- it's a bit complicated since we're not talking about pure Rust code, but code that links to C code and involves bindgen.
The Docker image solution looks much more promising.
I think the issue you ran into is due to bindgen requiring clang and llvm, which are apparently not installed in the rust Docker image.
Adding apt-get update && apt-get install clang fixes it. You can either run these before the cargo build command, or (which I'd recommend) build a custom Docker images FROM rust:latest that adds the package.