t-rex-tileserver / t-rex

t-rex is a vector tile server specialized on publishing MVT tiles from your own data
https://t-rex.tileserver.ch/
MIT License
545 stars 68 forks source link

Docker image for Apple M1 #245

Open musicformellons opened 3 years ago

musicformellons commented 3 years ago

When trying to use the docker version I get:

 ~  docker run sourcepole/t-rex --version                                              20.4s  Wed Jun  2 18:38:01 2021

WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
t_rex 0.13.0 (GDAL version 3.0.4)

 ~  docker run -p 6767:6767 sourcepole/t-rex serve --bind=0.0.0.0 --openbrowser=false --config=myconfig.toml

WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
2021-06-02 18:38:57.501 INFO Reading configuration from 'myconfig.toml'
Error reading configuration - Could not find config file!

Would it be possible to have an image for ARM64 ?

musicformellons commented 3 years ago

I tried to make it. After installing latest (12.5.1) xcode, I ran:

SDKROOT=$(xcrun -sdk macosx --show-sdk-path) \
MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version) \
cargo build --release --target=aarch64-apple-darwin --verbose

It compiles without errors. When I try to run it (doubleclick on the created t_rex file) I get:

Last login: Tue Jun 29 22:31:42 on ttys006
/Users/usr/Downloads/t-rex-0.13.0/target/aarch64-apple-darwin/release/t_rex ; exit;
Darwin MacBook-Pro.local 20.5.0 x86_64
22:39  up 11 days,  1:36, 3 users, load averages: 1.79 3.04 3.58
 ~  /Users/usr/Downloads/t-rex-0.13.0/target/aarch64-apple-darwin/release/t_rex ; exit;
dyld: lazy symbol binding failed: Symbol not found: _GDALVersionInfo
  Referenced from: /Users/usr/Downloads/t-rex-0.13.0/target/aarch64-apple-darwin/release/t_rex
  Expected in: flat namespace

dyld: Symbol not found: _GDALVersionInfo
  Referenced from: /Users/usr/Downloads/t-rex-0.13.0/target/aarch64-apple-darwin/release/t_rex
  Expected in: flat namespace

fish: '/Users/usr/Downloads/t-rex-0.13.…' terminated by signal SIGABRT (Abort)

[Process completed]

Any suggestions how to proceed as I am kind of stuck now?

musicformellons commented 3 years ago

I updated rust (from 1.51.0 to 1.53.0) and when compiling t-rex-core it gives:

error: custom inner attributes are unstable
 --> t-rex-core/src/mvt/vector_tile.rs:9:4
  |
9 | #![rustfmt::skip]
  |    ^^^^^^^^^^^^^
  |
  = note: `#[deny(soft_unstable)]` on by default
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #64266 <https://github.com/rust-lang/rust/issues/64266>

error: aborting due to previous error

error: could not compile `t-rex-core`

when I comment line 9 out it compiles, but the symbol error returns.

pka commented 3 years ago

The build error with [rustfmt::skip] is fixed in current master (#244). But this probably doesn't solve the build problem.

zouterover commented 3 years ago

Retried with the master branch:

error: failed to run custom build command for `gdal-sys v0.3.1`

Caused by:
  process didn't exit successfully: `/Users/pq/Projects/t-rex/target/release/build/gdal-sys-5f325f970b7f9ed2/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=GDAL_STATIC
  cargo:rerun-if-env-changed=GDAL_DYNAMIC
  cargo:rerun-if-env-changed=GDAL_INCLUDE_DIR
  cargo:rerun-if-env-changed=GDAL_LIB_DIR
  cargo:rerun-if-env-changed=GDAL_HOME
  cargo:rerun-if-env-changed=GDAL_VERSION
  cargo:rerun-if-env-changed=GDAL_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_aarch64_apple_darwin
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_aarch64_apple_darwin
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_apple_darwin
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:rustc-link-search=native=/usr/local/Cellar/gdal/3.3.1/lib
  cargo:rustc-link-lib=gdal
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_aarch64_apple_darwin
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_aarch64_apple_darwin
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_apple_darwin
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:rustc-cfg=gdal_sys_3_3_1

  --- stderr
  thread 'main' panicked at 'No pre-built bindings available for GDAL version 3.3. Use `--features bindgen` to generate your own bindings.', /Users/pq/.cargo/registry/src/github.com-1ecc6299db9ec823/gdal-sys-0.3.1/build.rs:219:17
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

I installed gdal with brew.

zouterover commented 3 years ago

I could not easily figure out how to leave out the optional gdal, so I commented out the features and gdal dependency lines in the main cargo.toml. It compiles and when I run the t_rex build it gives:

Last login: Wed Jul  7 16:11:11 on ttys000
/Users/pq/Projects/t-rex/target/aarch64-apple-darwin/release/t_rex ; exit;
Darwin MacBook-Pro.local 20.5.0 x86_64
16:37  up 5 days, 18:32, 3 users, load averages: 5.37 3.07 2.15
 ~  /Users/pq/Projects/t-rex/target/aarch64-apple-darwin/release/t_rex ; exit;
t_rex 0.14.0-dev
Pirmin Kalberer <pka@sourcepole.ch>
vector tile server specialized on publishing MVT tiles from your own data

USAGE:
    t_rex [SUBCOMMAND]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    drilldown    Tile layer statistics
    genconfig    Generate configuration template
    generate     Generate tiles for cache
    help         Prints this message or the help of the given subcommand(s)
    serve        Start web server and serve MVT vector tiles

[Process completed]

I don't really know whether I need the gdal dependency, but kind of looks like it works right?!

pka commented 3 years ago

This looks good. You need GDAL for non-PostGIS data (like GPKG or Shp) only. The proper way for building without GDAL is cargo build --all --no-default-features

musicformellons commented 2 years ago

when I run cargo build --all --no-default-features it seems GDAL is still troubling me:

 ...
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:rustc-cfg=gdal_sys_3_3_1

  --- stderr
  thread 'main' panicked at 'No pre-built bindings available for GDAL version 3.3. Use `--features bindgen` to generate your own bindings.', /Users/pq/.cargo/registry/src/github.com-1ecc6299db9ec823/gdal-sys-0.4.0/build.rs:219:17
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed
musicformellons commented 2 years ago

The above is actually an attempt to have a t-rex app that works on Apple Silicon. I think I got that working (without gdal) by cross-compiling to aarch64-apple-darwin. In the meantime I noticed however what I really need is a (ubuntu) container that runs on Apple Silicon with T-rex in it. For that to work I need to cross-compile T-rex to aarch64-unknown-linux-gnu so it matches an ubuntu container that runs on Apple Silicon. When doing so I run into openssl-sys cross-compile issues which are 'known' and apparently hard to tackle.

musicformellons commented 2 years ago

Looks like openssl could be swapped by rustls: https://github.com/rustls/rustls which might solve above issue.