diff --git a/.github/workflows/pr_build.yaml b/.github/workflows/pr_build.yaml index e9f638f9b..8c11ce6d6 100644 --- a/.github/workflows/pr_build.yaml +++ b/.github/workflows/pr_build.yaml @@ -39,7 +39,9 @@ jobs: run: echo $SHA_SHORT - name: Extract branch name shell: bash - run: echo "BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_ENV + run: | + BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} + echo "BRANCH=${BRANCH_NAME/\//\\\/}" >> $GITHUB_ENV - name: Confirm nightly build name id: build_name run: | @@ -54,10 +56,12 @@ jobs: - uses: actions/checkout@v4 - name: Update build number run: | - sed -i 's/Config.gameVersion = \".*\"/Config.gameVersion = \"${{ needs.gen-build-version.outputs.build }}\"/' "${env:GITHUB_WORKSPACE}/script/Config/App.lua" + sed -i 's/Config.gameVersion = \".*\"/Config.gameVersion = \"${{ needs.gen-build-version.outputs.build }}\"/' "${env:GITHUB_WORKSPACE}/script/Config/Version.lua" - name: Build shell: bash - run: ./build.sh + run: | + PHX_VERSION="${{ needs.gen-build-version.outputs.build }}" + ./build.sh - name: Upload binary uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/release_build.yaml b/.github/workflows/release_build.yaml index d150a24f3..def646735 100644 --- a/.github/workflows/release_build.yaml +++ b/.github/workflows/release_build.yaml @@ -60,7 +60,9 @@ jobs: sed -i 's/Config.gameVersion = \".*\"/Config.gameVersion = \"${{ needs.gen-build-version.outputs.build }}\"/' "${env:GITHUB_WORKSPACE}/script/Config/Version.lua" - name: Build shell: bash - run: ./build.sh + run: | + PHX_VERSION="${{ needs.gen-build-version.outputs.build }}" + ./build.sh - name: Upload binary uses: actions/upload-artifact@v3 with: diff --git a/Cargo.lock b/Cargo.lock index a7b653237..b61f66a97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -250,6 +250,19 @@ dependencies = [ "serde", ] +[[package]] +name = "build-time" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1219c19fc29b7bfd74b7968b420aff5bc951cf517800176e795d6b2300dd382" +dependencies = [ + "chrono", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.37", +] + [[package]] name = "bumpalo" version = "3.14.0" @@ -811,6 +824,26 @@ dependencies = [ "windows 0.48.0", ] +[[package]] +name = "git-version" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13ad01ffa8221f7fe8b936d6ffb2a3e7ad428885a04fad51866a5f33eafda57c" +dependencies = [ + "git-version-macro", +] + +[[package]] +name = "git-version-macro" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84488ccbdb24ad6f56dc1863b4a8154a7856cd3c6c7610401634fab3cb588dae" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.37", +] + [[package]] name = "gl_generator" version = "0.14.0" @@ -1197,7 +1230,9 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" name = "ltr" version = "0.1.0" dependencies = [ + "build-time", "clap", + "git-version", "libc", "phx", "winres", diff --git a/build.sh b/build.sh index d8aafecfb..0b7663828 100755 --- a/build.sh +++ b/build.sh @@ -33,10 +33,12 @@ fi mkdir -p bin if [[ $debug = 1 ]]; then cargo build + cargo test --no-fail-fast cp target/debug/ltr${binsuffix} bin/lt64d${binsuffix} cp target/debug/deps/${libprefix}phx${libsuffix} bin/${libprefix}phx${libsuffix} else cargo build --release + cargo test --release cp target/release/ltr${binsuffix} bin/lt64${binsuffix} cp target/release/deps/${libprefix}phx${libsuffix} bin/${libprefix}phx${libsuffix} fi diff --git a/engine/bin/ltr/Cargo.toml b/engine/bin/ltr/Cargo.toml index ff2682209..d8c25b270 100644 --- a/engine/bin/ltr/Cargo.toml +++ b/engine/bin/ltr/Cargo.toml @@ -11,7 +11,9 @@ edition.workspace = true phx.workspace = true # external crates +build-time = "0.1" clap = { version = "4.4", features = ["derive"] } +git-version = "0.3" libc = "0.2" [build-dependencies] diff --git a/engine/bin/ltr/src/main.rs b/engine/bin/ltr/src/main.rs index 0968718a5..42d0c6ef1 100644 --- a/engine/bin/ltr/src/main.rs +++ b/engine/bin/ltr/src/main.rs @@ -13,6 +13,9 @@ use std::ffi::CString; use clap::Parser; +const BUILD_TIME: &str = build_time::build_time_utc!("%Y-%m-%d / %H:%M:%S UTC"); +const GIT_VERSION: &str = git_version::git_version!(args = ["--tags", "--always", "--dirty=M"]); + #[derive(Parser)] #[command(author, version, about, long_about = None)] struct Cli { @@ -41,6 +44,14 @@ extern "C" { } pub fn main() { + println!( + "App: {}, ver: {}, git: {}, build time: {}", + env!("CARGO_PKG_NAME"), + env!("CARGO_PKG_VERSION"), + GIT_VERSION, + BUILD_TIME + ); + let cli = Cli::parse(); let entry_point = CString::new(cli.entry_point) diff --git a/engine/lib/phx/script/ffi_ext/Engine.lua b/engine/lib/phx/script/ffi_ext/Engine.lua new file mode 100644 index 000000000..9e0eb7595 --- /dev/null +++ b/engine/lib/phx/script/ffi_ext/Engine.lua @@ -0,0 +1,7 @@ +local libphx = require('libphx').lib + +function onDef_Engine(t, mt) + t.GetVersion = function() + return ffi.string(libphx.Engine_GetVersion()) + end +end diff --git a/script/Main.lua b/script/Main.lua index 9898298f1..a40f590a2 100644 --- a/script/Main.lua +++ b/script/Main.lua @@ -31,6 +31,10 @@ function InitSystem() GlobalRestrict.On() dofile('./script/Config/Version.lua') + if Config.gameVersion ~= "0.0.0" and Config.gameVersion ~= Engine.GetVersion() then + Log.Error("Engine and script version mismatch. Engine: %s. Script: %s.", Engine.GetVersion(), Config.gameVersion) + end + dofile('./script/Config/App.lua') -- Load Enums