From 65e0ad1fd8ac83c33ace85bcdf0e047c96b1a098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=91=E5=8F=AF=E8=83=BD=E5=BE=88=E5=BB=A2?= Date: Fri, 17 Jan 2025 12:59:25 +0800 Subject: [PATCH] :sparkles: Add git commit hash in main branch build version (#63) * :sparkles: add git commit hash in main branch build version * :see_no_evil: ignore dirty submodule * :alembic: try vergen-gitcl * :construction_worker: we don't need codemagic anymore since macos-latest in github actions is now in arm64 * :construction_worker: use git describe in exe name * :sparkles: verbose version output * :heavy_minus_sign: remove build feature in vergen * :construction_worker: build on tag push --- .github/workflows/build.yaml | 31 ++--- .gitmodules | 1 + Cargo.lock | 229 +++++++++++++++++++++++++++++++- Cargo.toml | 9 +- README.md | 1 + README.zh-TW.md | 1 + build.rs | 31 +++++ codemagic.yaml | 29 ---- crates/vgmstream-sys/Cargo.toml | 2 +- src/bin/mltd/main.rs | 8 +- 10 files changed, 288 insertions(+), 54 deletions(-) create mode 100644 build.rs delete mode 100644 codemagic.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 5349ac8..3a81a6b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -3,6 +3,7 @@ name: Build on: push: branches: ["main"] + tags: ["*"] env: CARGO_TERM_COLOR: always @@ -32,36 +33,26 @@ jobs: - name: Build run: cargo build --release - - name: Get git commit hash (Windows) + - name: Get version (Windows) if: ${{ contains('Windows', runner.os) }} - id: hash_windows - run: echo "hash=$("${{ github.sha }}".SubString(0, 10))" >> $env:GITHUB_OUTPUT + id: version_windows + run: echo "version=$(git describe --tags --dirty)" >> $env:GITHUB_OUTPUT - - name: Get git commit hash + - name: Get version if: ${{ !contains('Windows', runner.os) }} - id: hash - run: echo "hash=${GITHUB_SHA:0:10}" >> $GITHUB_OUTPUT - - - name: Rename artifact (Windows) - if: ${{ contains('Windows', runner.os) }} - run: mv target/release/mltd.exe mltd-git-${{ steps.hash_windows.outputs.hash }}-Windows.exe - - - name: Rename artifact - if: ${{ !contains('Windows', runner.os) }} - run: | - chmod +x target/release/mltd - mv target/release/mltd mltd-git-${{ steps.hash.outputs.hash }}-${{ runner.os }} + id: version + run: echo "version=$(git describe --tags --dirty)" >> $GITHUB_OUTPUT - name: Publish artifact (Windows) if: ${{ contains('Windows', runner.os) }} uses: actions/upload-artifact@v4 with: - name: mltd-git-${{ steps.hash_windows.outputs.hash }}-Windows.exe - path: mltd-git-${{ steps.hash_windows.outputs.hash }}-Windows.exe + name: mltd-git-${{ steps.version_windows.outputs.version }}-Windows.exe + path: target/release/mltd.exe - name: Publish artifact if: ${{ !contains('Windows', runner.os) }} uses: actions/upload-artifact@v4 with: - name: mltd-git-${{ steps.hash.outputs.hash }}-${{ runner.os }} - path: mltd-git-${{ steps.hash.outputs.hash }}-${{ runner.os }} + name: mltd-git-${{ steps.version.outputs.version }}-${{ runner.os }} + path: target/release/mltd diff --git a/.gitmodules b/.gitmodules index 872e2ca..d2858e2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "crates/vgmstream-sys/vgmstream"] path = crates/vgmstream-sys/vgmstream url = https://github.com/vgmstream/vgmstream.git + ignore = dirty diff --git a/Cargo.lock b/Cargo.lock index 224c579..b7b66a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -276,6 +276,38 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" +[[package]] +name = "camino" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8769706aad5d996120af43197bf46ef6ad0fda35216b4505f926a365a232d924" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "cbc" version = "0.1.2" @@ -506,6 +538,81 @@ dependencies = [ "syn 2.0.96", ] +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.96", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.96", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "derive_builder" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "507dfb09ea8b7fa618fcf76e953f4f5e192547945816d5358edffe39f6f94947" +dependencies = [ + "derive_builder_macro", +] + +[[package]] +name = "derive_builder_core" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d5bcf7b024d6835cfb3d473887cd966994907effbe9227e8c8219824d06c4e8" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.96", +] + +[[package]] +name = "derive_builder_macro" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c" +dependencies = [ + "derive_builder_core", + "syn 2.0.96", +] + [[package]] name = "displaydoc" version = "0.2.5" @@ -1030,6 +1137,12 @@ dependencies = [ "syn 2.0.96", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "1.0.3" @@ -1326,6 +1439,8 @@ dependencies = [ "tokio", "tokio-test", "tokio-util", + "vergen", + "vergen-gitcl", "vgmstream", ] @@ -1356,6 +1471,12 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-derive" version = "0.4.2" @@ -1407,6 +1528,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + [[package]] name = "number_prefix" version = "0.4.0" @@ -1541,6 +1671,12 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6" +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.20" @@ -1802,6 +1938,15 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "0.38.43" @@ -1898,6 +2043,15 @@ dependencies = [ "libc", ] +[[package]] +name = "semver" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba" +dependencies = [ + "serde", +] + [[package]] name = "serde" version = "1.0.217" @@ -2138,6 +2292,39 @@ dependencies = [ "syn 2.0.96", ] +[[package]] +name = "time" +version = "0.3.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" +dependencies = [ + "deranged", + "itoa", + "libc", + "num-conv", + "num_threads", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tinystr" version = "0.7.6" @@ -2383,6 +2570,46 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "vergen" +version = "9.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0d2f179f8075b805a43a2a21728a46f0cc2921b3c58695b28fa8817e103cd9a" +dependencies = [ + "anyhow", + "cargo_metadata", + "derive_builder", + "regex", + "rustc_version", + "rustversion", + "vergen-lib", +] + +[[package]] +name = "vergen-gitcl" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2f89d70a58a4506a6079cedf575c64cf51649ccbb4e02a63dac539b264b7711" +dependencies = [ + "anyhow", + "derive_builder", + "rustversion", + "time", + "vergen", + "vergen-lib", +] + +[[package]] +name = "vergen-lib" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b07e6010c0f3e59fcb164e0163834597da68d1f864e2b8ca49f74de01e9c166" +dependencies = [ + "anyhow", + "derive_builder", + "rustversion", +] + [[package]] name = "version_check" version = "0.9.5" @@ -2401,7 +2628,7 @@ dependencies = [ [[package]] name = "vgmstream-sys" -version = "0.1.0-vgmstream-r1980" +version = "0.1.0-vgmstream-r1980-16-g1f3a6b36" dependencies = [ "bindgen", "cmake", diff --git a/Cargo.toml b/Cargo.toml index 9b7cbe4..9b33919 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ repository = "https://github.com/nicks96432/mltd-asset-downloader" [package] authors = { workspace = true } +build = "build.rs" categories = ["command-line-utilities"] description = "A CLI made for assets in THE iDOLM@STER® MILLION LIVE! THEATER DAYS (MLTD)" edition = { workspace = true } @@ -47,10 +48,14 @@ rmp-serde = "1.3.0" serde = { features = ["derive"], version = "1.0.217" } texture2ddecoder = { optional = true, version = "0.1.1" } thiserror = "2.0.10" -tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] } -tokio-util = { version = "0.7.13", features = ["compat"] } +tokio = { features = ["macros", "rt-multi-thread"], version = "1.43.0" } +tokio-util = { features = ["compat"], version = "0.7.13" } vgmstream = { optional = true, path = "crates/vgmstream" } +[build-dependencies] +vergen = { features = ["cargo", "emit_and_set", "rustc"], version = "9.0.4" } +vergen-gitcl = { version = "1.0.5" } + [dev-dependencies] ctor = "0.2.9" rand = "0.8.5" diff --git a/README.md b/README.md index 7036ced..caad847 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Options: The following tools are required: +* git * A rust toolchain ([installation guide](https://www.rust-lang.org/tools/install)) * cmake >= 3.6 (for vgmstream) * clang (for bindgen) ([installation guide](https://rust-lang.github.io/rust-bindgen/requirements.html)) diff --git a/README.zh-TW.md b/README.zh-TW.md index dba3ca0..d260dc6 100644 --- a/README.zh-TW.md +++ b/README.zh-TW.md @@ -42,6 +42,7 @@ Commands: 你需要這些工具: +* git * rust 編譯工具 ([安裝教學](https://www.rust-lang.org/tools/install)) * cmake >= 3.6 (vgmstream要用到) * clang (bindgen要用到) ([安裝教學](https://rust-lang.github.io/rust-bindgen/requirements.html)) diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..cbc65e6 --- /dev/null +++ b/build.rs @@ -0,0 +1,31 @@ +use std::env::var; +use std::error::Error; + +use vergen::{CargoBuilder, Emitter, RustcBuilder}; +use vergen_gitcl::GitclBuilder; + +fn main() -> Result<(), Box> { + let cargo = CargoBuilder::default().features(true).build()?; + let git2 = GitclBuilder::default().describe(true, true, None).build()?; + let rustc = RustcBuilder::default().semver(true).build()?; + + Emitter::default() + .idempotent() + .add_instructions(&cargo)? + .add_instructions(&git2)? + .add_instructions(&rustc)? + .emit_and_set()?; + + let long_version = format!( + "{} (enabled features: {}), built with rustc {}", + var("VERGEN_GIT_DESCRIBE").unwrap_or("unknown version".to_string()), + var("VERGEN_CARGO_FEATURES").unwrap_or("unknown features".to_string()), + var("VERGEN_RUSTC_SEMVER").unwrap_or("unknown rustc version".to_string()), + ) + .trim() + .to_string(); + + println!("cargo:rustc-env=MLTD_VERSION_LONG={}", long_version); + + Ok(()) +} diff --git a/codemagic.yaml b/codemagic.yaml deleted file mode 100644 index d67262d..0000000 --- a/codemagic.yaml +++ /dev/null @@ -1,29 +0,0 @@ -workflows: - aarch64-darwin-build: - triggering: - events: - - tag - scripts: - - name: Update submodule - script: git submodule update --init --recursive - - name: Install rust non-interactively - script: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - - name: Init rust - script: $HOME/.cargo/bin/rustup default stable - - name: Build - script: $HOME/.cargo/bin/cargo build --release - - name: Move artifact - script: | - chmod +x target/release/mltd - mv target/release/mltd mltd-$(git describe --tags --always)-aarch64-apple-darwin - - artifacts: - - mltd-* - - cache: - cache_paths: - - $HOME/.cargo/bin/ - - $HOME/.cargo/registry/index/ - - $HOME/.cargo/registry/cache/ - - $HOME/.cargo/git/db/ - - target/ diff --git a/crates/vgmstream-sys/Cargo.toml b/crates/vgmstream-sys/Cargo.toml index b6eb78e..471592e 100644 --- a/crates/vgmstream-sys/Cargo.toml +++ b/crates/vgmstream-sys/Cargo.toml @@ -5,7 +5,7 @@ license.workspace = true links = "vgmstream" name = "vgmstream-sys" repository.workspace = true -version = "0.1.0-vgmstream-r1980" +version = "0.1.0-vgmstream-r1980-16-g1f3a6b36" [build-dependencies] bindgen = "0.71.1" diff --git a/src/bin/mltd/main.rs b/src/bin/mltd/main.rs index 585a2cc..b4a04b1 100644 --- a/src/bin/mltd/main.rs +++ b/src/bin/mltd/main.rs @@ -10,7 +10,13 @@ use clap_verbosity_flag::{InfoLevel, Verbosity}; use mltd::util::log_formatter; #[derive(Parser)] -#[command(author, version, about, arg_required_else_help = true)] +#[command( + author, + version = env!("VERGEN_GIT_DESCRIBE"), + long_version = env!("MLTD_VERSION_LONG"), + about, + arg_required_else_help = true +)] struct Cli { #[command(subcommand)] pub command: Command,