From ff642df4046e42f64bcb7198499ca663075402d6 Mon Sep 17 00:00:00 2001 From: Maximilian Ammann Date: Mon, 18 Apr 2022 20:13:21 +0200 Subject: [PATCH] Replace tools directory with cargo-make --- .github/workflows/rust.yml | 21 +++---- Cargo.lock | 12 ---- Cargo.toml | 2 - Makefile.toml | 113 +++++++++++++++++++++++++++++++++++++ tools/build-android | 31 ---------- tools/build-web | 39 ------------- tools/extract-region | 20 ------- 7 files changed, 122 insertions(+), 116 deletions(-) create mode 100644 Makefile.toml delete mode 100755 tools/build-android delete mode 100755 tools/build-web delete mode 100755 tools/extract-region diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index f0d70815..fdaa3829 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -79,12 +79,11 @@ jobs: ~/.cargo/.crates* target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Prepare Rust Toolchain # This is required because we are recompiling the stdlib + - name: Install cargo-make run: | - rustup install nightly-2022-04-04-x86_64-unknown-linux-gnu - rustup component add rust-src --toolchain nightly-2022-04-04-x86_64-unknown-linux-gnu + cargo install cargo-make - name: Build - run: tools/build-android + run: cargo make --no-workspace build-apk - uses: actions/upload-artifact@v2 with: name: mapr.apk @@ -110,14 +109,13 @@ jobs: ~/.cargo/.crates* target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Prepare Rust Toolchain # This is required because we are recompiling the stdlib + - name: Install cargo-make run: | - rustup install nightly-2022-04-04-x86_64-unknown-linux-gnu - rustup component add rust-src --toolchain nightly-2022-04-04-x86_64-unknown-linux-gnu + cargo install cargo-make - name: NPM Install run: npm install - name: Build - run: npm run webgl-production-build + run: cargo make --cwd ../ --no-workspace build-webpack-webgl-production - name: Deploy to maxammann.org env: SSH_KEY: ${{ secrets.SSH_KEY_MAXAMMANN_ORG }} @@ -147,14 +145,13 @@ jobs: ~/.cargo/.crates* target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Prepare Rust Toolchain # This is required because we are recompiling the stdlib + - name: Install cargo-make run: | - rustup install nightly-2022-04-04-x86_64-unknown-linux-gnu - rustup component add rust-src --toolchain nightly-2022-04-04-x86_64-unknown-linux-gnu + cargo install cargo-make - name: NPM Install run: npm install - name: Build - run: npm run production-build + run: cargo make --cwd ../ --no-workspace build-webpack-production - name: Deploy to maxammann.org env: SSH_KEY: ${{ secrets.SSH_KEY_MAXAMMANN_ORG }} diff --git a/Cargo.lock b/Cargo.lock index d10664c0..ab381c0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1777,7 +1777,6 @@ dependencies = [ "reqwest-middleware-cache", "rstar 0.9.2", "style-spec", - "test-env-log", "tilejson-spec", "tokio", "tracing", @@ -3040,17 +3039,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "test-env-log" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877189d680101869f65ef94168105d6c188b3a143c13a2d42cf8a09c4c704f8a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "textwrap" version = "0.11.0" diff --git a/Cargo.toml b/Cargo.toml index c2b6d724..cd17c7e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -104,8 +104,6 @@ include_dir = "0.7.2" [dev-dependencies] criterion = "0.3" -# Support logging in tests -test-env-log = "0.2" [build-dependencies] wgsl-validate = { path = "./libs/wgsl_validate" } diff --git a/Makefile.toml b/Makefile.toml new file mode 100644 index 00000000..2c400672 --- /dev/null +++ b/Makefile.toml @@ -0,0 +1,113 @@ +[config] +skip_core_tasks = true + +[tasks.format] +install_crate = "rustfmt" +command = "cargo" +args = ["fmt", "--all", "--"] + +[tasks.clippy] +command = "cargo" +args = ["clippy", "--all-targets", "--all-features"] + +[tasks.build-webpack-webgl-production] +cwd = "./web" +toolchain = "nightly-2022-04-04" +install_crate = { rustup_component_name = "rust-src" } +command = "npm" +args = ["run", "webgl-production-build"] + +[tasks.build-webpack-production] +cwd = "./web" +toolchain = "nightly-2022-04-04" +install_crate = { rustup_component_name = "rust-src" } +command = "npm" +args = ["run", "production-build"] + +[tasks.wasm-pack-webgl] +script_runner = "bash" +# language=bash +script = ''' +./wasm-pack-v0.10.1-x86_64-unknown-linux-musl/wasm-pack build . \ + --release --target web --out-dir dist/mapr -- \ + --features "web-webgl" -Z build-std=std,panic_abort +''' + +[tasks.wasm-pack] +script_runner = "bash" +# language=bash +script = ''' +./wasm-pack-v0.10.1-x86_64-unknown-linux-musl/wasm-pack build . \ + --release --target web --out-dir dist/mapr -- \ + -Z build-std=std,panic_abort +''' + +[tasks.build-web-webgl] +toolchain = "nightly-2022-04-04" +install_crate = { rustup_component_name = "rust-src" } +command = "cargo" +# -Zbuild-std is required for shared memory/atomics support +args = ["build", "--features", "web-webgl", "--target", "wasm32-unknown-unknown", "-Z", "build-std=std,panic_abort"] +run_task = "wasm-bindgen" + +[tasks.build-web] +toolchain = "nightly-2022-04-04" +install_crate = { rustup_component_name = "rust-src" } +command = "cargo" +# -Zbuild-std is required for shared memory/atomics support +args = ["build", "--target", "wasm32-unknown-unknown", "-Z", "build-std=std,panic_abort"] +run_task = "wasm-bindgen" + +[tasks.wasm-bindgen] +script_runner = "bash" +# language=bash +script = ''' +# TODO: Untested: --reference-types +wasm-bindgen --target web --out-dir dist/mapr-pain-bindgen target/wasm32-unknown-unknown/debug/mapr.wasm +''' + +[tasks.extract-tiles] +script_runner = "bash" +# language=bash +script = ''' +if ! command -v tilelive-copy &> /dev/null +then + echo "tilelive-copy could not be found. Install it with 'yarn global add @mapbox/tilelive @mapbox/mbtiles'" + exit 1 +fi + +# Bounds copied from https://boundingbox.klokantech.com/ +tilelive-copy \ + --minzoom=12 --maxzoom=12 \ + --bounds="11.395769,48.083436,11.618242,48.220866" \ + test-data/europe_germany-2020-02-13-openmaptiles-v3.12.1.mbtiles test-data/munich-12.mbtiles + +tilelive-copy \ + --minzoom=15 --maxzoom=15 \ + --bounds="11.395769,48.083436,11.618242,48.220866" \ + test-data/europe_germany-2020-02-13-openmaptiles-v3.12.1.mbtiles test-data/munich-15.mbtiles +''' + +[tasks.print-android-env] +script_runner = "bash" +# language=bash +script = ''' +echo "ANDROID_HOME: $ANDROID_HOME" +echo "ANDROID_SDK_ROOT: $ANDROID_SDK_ROOT" +echo "ANDROID_NDK_ROOT: $ANDROID_NDK_ROOT" +''' + +[tasks.build-apk] +toolchain = "nightly-2022-04-04" +install_crate = { rustup_component_name = "rust-src" } +command = "cargo" +# -Zbuild-std is required for latest NDK: https://github.com/rust-windowing/android-ndk-rs/pull/189 +args = ["apk", "run", "--lib", "-Zbuild-std"] +dependencies = [ "print-android-env" ] + +[tasks.run-apk] +toolchain = "nightly-2022-04-04" +install_crate = { rustup_component_name = "rust-src" } +command = "cargo" +args = ["apk", "build", "--lib", "-Zbuild-std"] +dependencies = [ "print-android-env" ] diff --git a/tools/build-android b/tools/build-android deleted file mode 100755 index 8646d7bf..00000000 --- a/tools/build-android +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -set -e - -run=false - -TEMP=$(getopt --long -o "g" "$@") -eval set -- "$TEMP" -while true; do - case "$1" in - -g) - run=true - shift 2 - ;; - *) - break - ;; - esac -done - -echo "ANDROID_HOME: $ANDROID_HOME" -echo "ANDROID_SDK_ROOT: $ANDROID_SDK_ROOT" -echo "ANDROID_NDK_ROOT: $ANDROID_NDK_ROOT" - -cargo install cargo-apk - -if [ "$run" = true ] ; then - # -Zbuild-std is required for latest NDK: https://github.com/rust-windowing/android-ndk-rs/pull/189 - cargo +nightly-2022-04-04 apk run --lib -Zbuild-std -else - cargo +nightly-2022-04-04 apk build --lib -Zbuild-std -fi diff --git a/tools/build-web b/tools/build-web deleted file mode 100755 index 23dbde7d..00000000 --- a/tools/build-web +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -set -e - -webgl_flag="" - -TEMP=$(getopt --long -o "g" "$@") -eval set -- "$TEMP" -while true; do - case "$1" in - -g) - webgl_flag="web-webgl," - shift 2 - ;; - *) - break - ;; - esac -done - -export RUSTUP_TOOLCHAIN=nightly-2022-04-04-x86_64-unknown-linux-gnu - -rustup component add rust-src --toolchain nightly-2022-04-04-x86_64-unknown-linux-gnu - -function plain_build() { - cargo build --features "$webgl_flag" --target wasm32-unknown-unknown -Z build-std=std,panic_abort - # TODO: Untested: --reference-types - wasm-bindgen --target web --out-dir dist/mapr-pain-bindgen target/wasm32-unknown-unknown/debug/mapr.wasm -} - -function wasm_pack_build() { - ~/Downloads/wasm-pack-v0.10.1-x86_64-unknown-linux-musl/wasm-pack build . \ - --release --target web --out-dir dist/mapr -- \ - --features "$webgl_flag" -Z build-std=std,panic_abort -} - -wasm_pack_build - -#xdg-open "https://localhost:5555/web/mapr.html" -#python3 tools/tls-http-server.py diff --git a/tools/extract-region b/tools/extract-region deleted file mode 100755 index a34c3459..00000000 --- a/tools/extract-region +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - - - -if ! command -v tilelive-copy &> /dev/null -then - echo "tilelive-copy could not be found. Install it with 'yarn global add @mapbox/tilelive @mapbox/mbtiles'" - exit 1 -fi - -# Bounds copied from https://boundingbox.klokantech.com/ -tilelive-copy \ - --minzoom=12 --maxzoom=12 \ - --bounds="11.395769,48.083436,11.618242,48.220866" \ - test-data/europe_germany-2020-02-13-openmaptiles-v3.12.1.mbtiles test-data/munich-12.mbtiles - -tilelive-copy \ - --minzoom=15 --maxzoom=15 \ - --bounds="11.395769,48.083436,11.618242,48.220866" \ - test-data/europe_germany-2020-02-13-openmaptiles-v3.12.1.mbtiles test-data/munich-15.mbtiles