From ee2ad13ee5266e6ab44706595dc6042e37010955 Mon Sep 17 00:00:00 2001 From: Oleg Khryptul Date: Tue, 21 Nov 2023 09:55:22 +0100 Subject: [PATCH 01/11] Various improvements for app startup --- Cargo.lock | 35 ++++++++++++++++++++++++++++++++ build.sh | 2 ++ engine/bin/ltr/Cargo.toml | 2 ++ engine/bin/ltr/src/main.rs | 11 ++++++++++ engine/lib/phx/src/engine/mod.rs | 2 +- script/Config/Version.lua | 2 +- script/Main.lua | 4 ++++ 7 files changed, 56 insertions(+), 2 deletions(-) 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/src/engine/mod.rs b/engine/lib/phx/src/engine/mod.rs index d1edb2f9a..76dccc4b0 100644 --- a/engine/lib/phx/src/engine/mod.rs +++ b/engine/lib/phx/src/engine/mod.rs @@ -599,7 +599,7 @@ impl Engine { } pub fn get_version() -> &'static str { - env!("PHX_VERSION") + env!("CARGO_PKG_VERSION") } pub fn exit(&mut self) { diff --git a/script/Config/Version.lua b/script/Config/Version.lua index 0e6410002..ba593743d 100644 --- a/script/Config/Version.lua +++ b/script/Config/Version.lua @@ -1,2 +1,2 @@ --! Automatically set by a GitHub Action - Don´t modify -Config.gameVersion = "0.0.0" +Config.gameVersion = "0.1.0" diff --git a/script/Main.lua b/script/Main.lua index 9898298f1..1ec94b234 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 ~= ffi.string(Engine.GetVersion()) then + Log.Error("Engine and script version mismatch. Engine: %s. Script: %s.", ffi.string(Engine.GetVersion()), Config.gameVersion) + end + dofile('./script/Config/App.lua') -- Load Enums From d1a36bb63b0aeef70af68cc2669ff20c946c62b8 Mon Sep 17 00:00:00 2001 From: Oleg Khryptul Date: Tue, 21 Nov 2023 12:40:51 +0100 Subject: [PATCH 02/11] Fix CI --- .github/workflows/pr_build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr_build.yaml b/.github/workflows/pr_build.yaml index e9f638f9b..5ad50615a 100644 --- a/.github/workflows/pr_build.yaml +++ b/.github/workflows/pr_build.yaml @@ -39,7 +39,7 @@ jobs: run: echo $SHA_SHORT - name: Extract branch name shell: bash - run: echo "BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_ENV + run: echo "BRANCH=${${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}/\//\\\/}" >> $GITHUB_ENV - name: Confirm nightly build name id: build_name run: | @@ -54,7 +54,7 @@ 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 From 03a57d95856bca087d1ef7c83144c15140dff9c1 Mon Sep 17 00:00:00 2001 From: Oleg Khryptul Date: Tue, 21 Nov 2023 13:12:51 +0100 Subject: [PATCH 03/11] Fix CI --- .github/workflows/pr_build.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr_build.yaml b/.github/workflows/pr_build.yaml index 5ad50615a..8a2e9139f 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: | From 7af9dc2b2bc0c5020c7adf0fcfe993894d507a19 Mon Sep 17 00:00:00 2001 From: Oleg Khryptul Date: Tue, 21 Nov 2023 13:39:44 +0100 Subject: [PATCH 04/11] Fix version check --- script/Config/Version.lua | 2 +- script/Main.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/script/Config/Version.lua b/script/Config/Version.lua index ba593743d..0e6410002 100644 --- a/script/Config/Version.lua +++ b/script/Config/Version.lua @@ -1,2 +1,2 @@ --! Automatically set by a GitHub Action - Don´t modify -Config.gameVersion = "0.1.0" +Config.gameVersion = "0.0.0" diff --git a/script/Main.lua b/script/Main.lua index 1ec94b234..0c8cb5685 100644 --- a/script/Main.lua +++ b/script/Main.lua @@ -31,7 +31,7 @@ function InitSystem() GlobalRestrict.On() dofile('./script/Config/Version.lua') - if Config.gameVersion ~= ffi.string(Engine.GetVersion()) then + if Config.gameVersion ~= "0.0.0" and Config.gameVersion ~= ffi.string(Engine.GetVersion()) then Log.Error("Engine and script version mismatch. Engine: %s. Script: %s.", ffi.string(Engine.GetVersion()), Config.gameVersion) end From 548fde2db9646ff0a32f5de71f128d66e53f1af5 Mon Sep 17 00:00:00 2001 From: IllustrisJack <76592751+IllustrisJack@users.noreply.github.com> Date: Tue, 21 Nov 2023 16:50:16 +0100 Subject: [PATCH 05/11] Allow direct call of Engine:GetVersion() in Lua --- engine/lib/phx/script/ffi_ext/Engine.lua | 7 +++++++ engine/lib/phx/script/ffi_gen/Engine.lua | 16 +++++++++++----- script/Main.lua | 4 ++-- 3 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 engine/lib/phx/script/ffi_ext/Engine.lua 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..a4268b84e --- /dev/null +++ b/engine/lib/phx/script/ffi_ext/Engine.lua @@ -0,0 +1,7 @@ +local libphx = require('libphx').lib + +function onDef_Engine_t(t, mt) + mt.__index.getVersion = function(...) + return ffi.string(...) + end +end diff --git a/engine/lib/phx/script/ffi_gen/Engine.lua b/engine/lib/phx/script/ffi_gen/Engine.lua index a31806d68..bb888f75e 100644 --- a/engine/lib/phx/script/ffi_gen/Engine.lua +++ b/engine/lib/phx/script/ffi_gen/Engine.lua @@ -53,11 +53,17 @@ function Loader.defineType() local t = ffi.typeof('Engine') local mt = { __index = { - window = libphx.Engine_Window, - input = libphx.Engine_Input, - hmGui = libphx.Engine_HmGui, - getTime = libphx.Engine_GetTime, - exit = libphx.Engine_Exit, + window = libphx.Engine_Window, + input = libphx.Engine_Input, + hmGui = libphx.Engine_HmGui, + free = libphx.Engine_Free, + abort = libphx.Engine_Abort, + getBits = libphx.Engine_GetBits, + getTime = libphx.Engine_GetTime, + getVersion = libphx.Engine_GetVersion, + exit = libphx.Engine_Exit, + terminate = libphx.Engine_Terminate, + update = libphx.Engine_Update, }, } diff --git a/script/Main.lua b/script/Main.lua index 0c8cb5685..a40f590a2 100644 --- a/script/Main.lua +++ b/script/Main.lua @@ -31,8 +31,8 @@ function InitSystem() GlobalRestrict.On() dofile('./script/Config/Version.lua') - if Config.gameVersion ~= "0.0.0" and Config.gameVersion ~= ffi.string(Engine.GetVersion()) then - Log.Error("Engine and script version mismatch. Engine: %s. Script: %s.", ffi.string(Engine.GetVersion()), Config.gameVersion) + 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') From 33519ed62860f18803c6133d6f5b448270770661 Mon Sep 17 00:00:00 2001 From: IllustrisJack <76592751+IllustrisJack@users.noreply.github.com> Date: Tue, 21 Nov 2023 18:12:29 +0100 Subject: [PATCH 06/11] refactor: change engine to generate global symbol for get_version --- engine/lib/phx/script/ffi_gen/Engine.lua | 7 +------ engine/lib/phx/src/engine/mod.rs | 6 ++++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/engine/lib/phx/script/ffi_gen/Engine.lua b/engine/lib/phx/script/ffi_gen/Engine.lua index bb888f75e..bebfde82a 100644 --- a/engine/lib/phx/script/ffi_gen/Engine.lua +++ b/engine/lib/phx/script/ffi_gen/Engine.lua @@ -23,7 +23,7 @@ function Loader.defineType() void Engine_Abort (); int Engine_GetBits (); double Engine_GetTime (Engine const*); - cstr Engine_GetVersion (); + cstr Engine_GetVersion (Engine const*); void Engine_Exit (Engine*); void Engine_Terminate (); void Engine_Update (); @@ -56,14 +56,9 @@ function Loader.defineType() window = libphx.Engine_Window, input = libphx.Engine_Input, hmGui = libphx.Engine_HmGui, - free = libphx.Engine_Free, - abort = libphx.Engine_Abort, - getBits = libphx.Engine_GetBits, getTime = libphx.Engine_GetTime, getVersion = libphx.Engine_GetVersion, exit = libphx.Engine_Exit, - terminate = libphx.Engine_Terminate, - update = libphx.Engine_Update, }, } diff --git a/engine/lib/phx/src/engine/mod.rs b/engine/lib/phx/src/engine/mod.rs index 76dccc4b0..f99ce956f 100644 --- a/engine/lib/phx/src/engine/mod.rs +++ b/engine/lib/phx/src/engine/mod.rs @@ -33,6 +33,7 @@ pub struct Engine { input: Input, frame_state: FrameState, exit_app: bool, + app_version: &'static str, lua: Lua, } @@ -75,6 +76,7 @@ impl Engine { input: Default::default(), frame_state: Default::default(), exit_app: false, + app_version: env!("CARGO_PKG_VERSION"), lua, } } @@ -598,8 +600,8 @@ impl Engine { self.init_time.get_elapsed() } - pub fn get_version() -> &'static str { - env!("CARGO_PKG_VERSION") + pub fn get_version(&self) -> &'static str { + self.app_version } pub fn exit(&mut self) { From 3430d7c02324f86a4bcd014da33ffb96270e471e Mon Sep 17 00:00:00 2001 From: IllustrisJack <76592751+IllustrisJack@users.noreply.github.com> Date: Tue, 21 Nov 2023 23:23:24 +0100 Subject: [PATCH 07/11] Update mod.rs --- engine/lib/phx/src/engine/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/engine/lib/phx/src/engine/mod.rs b/engine/lib/phx/src/engine/mod.rs index f99ce956f..05f145728 100644 --- a/engine/lib/phx/src/engine/mod.rs +++ b/engine/lib/phx/src/engine/mod.rs @@ -33,7 +33,6 @@ pub struct Engine { input: Input, frame_state: FrameState, exit_app: bool, - app_version: &'static str, lua: Lua, } @@ -76,7 +75,6 @@ impl Engine { input: Default::default(), frame_state: Default::default(), exit_app: false, - app_version: env!("CARGO_PKG_VERSION"), lua, } } @@ -601,7 +599,7 @@ impl Engine { } pub fn get_version(&self) -> &'static str { - self.app_version + env!("CARGO_PKG_VERSION") } pub fn exit(&mut self) { From 8c26332e75d0682604c8aea3d3381d39b5a6541a Mon Sep 17 00:00:00 2001 From: IllustrisJack <76592751+IllustrisJack@users.noreply.github.com> Date: Tue, 21 Nov 2023 23:30:39 +0100 Subject: [PATCH 08/11] Update mod.rs --- engine/lib/phx/src/engine/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/lib/phx/src/engine/mod.rs b/engine/lib/phx/src/engine/mod.rs index 05f145728..76dccc4b0 100644 --- a/engine/lib/phx/src/engine/mod.rs +++ b/engine/lib/phx/src/engine/mod.rs @@ -598,7 +598,7 @@ impl Engine { self.init_time.get_elapsed() } - pub fn get_version(&self) -> &'static str { + pub fn get_version() -> &'static str { env!("CARGO_PKG_VERSION") } From 06174e5e8434ce6a9c4dc1344293e1a7e08ebb09 Mon Sep 17 00:00:00 2001 From: IllustrisJack <76592751+IllustrisJack@users.noreply.github.com> Date: Tue, 21 Nov 2023 23:34:01 +0100 Subject: [PATCH 09/11] Update Engine.lua --- engine/lib/phx/script/ffi_gen/Engine.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/engine/lib/phx/script/ffi_gen/Engine.lua b/engine/lib/phx/script/ffi_gen/Engine.lua index bebfde82a..a31806d68 100644 --- a/engine/lib/phx/script/ffi_gen/Engine.lua +++ b/engine/lib/phx/script/ffi_gen/Engine.lua @@ -23,7 +23,7 @@ function Loader.defineType() void Engine_Abort (); int Engine_GetBits (); double Engine_GetTime (Engine const*); - cstr Engine_GetVersion (Engine const*); + cstr Engine_GetVersion (); void Engine_Exit (Engine*); void Engine_Terminate (); void Engine_Update (); @@ -53,12 +53,11 @@ function Loader.defineType() local t = ffi.typeof('Engine') local mt = { __index = { - window = libphx.Engine_Window, - input = libphx.Engine_Input, - hmGui = libphx.Engine_HmGui, - getTime = libphx.Engine_GetTime, - getVersion = libphx.Engine_GetVersion, - exit = libphx.Engine_Exit, + window = libphx.Engine_Window, + input = libphx.Engine_Input, + hmGui = libphx.Engine_HmGui, + getTime = libphx.Engine_GetTime, + exit = libphx.Engine_Exit, }, } From e2e2a62b34cff8325c9fd1c99bfd6bf6bf1419e7 Mon Sep 17 00:00:00 2001 From: IllustrisJack <76592751+IllustrisJack@users.noreply.github.com> Date: Tue, 21 Nov 2023 23:36:16 +0100 Subject: [PATCH 10/11] =?UTF-8?q?Don=C2=B4t=20use=20mt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- engine/lib/phx/script/ffi_ext/Engine.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/lib/phx/script/ffi_ext/Engine.lua b/engine/lib/phx/script/ffi_ext/Engine.lua index a4268b84e..9e0eb7595 100644 --- a/engine/lib/phx/script/ffi_ext/Engine.lua +++ b/engine/lib/phx/script/ffi_ext/Engine.lua @@ -1,7 +1,7 @@ local libphx = require('libphx').lib -function onDef_Engine_t(t, mt) - mt.__index.getVersion = function(...) - return ffi.string(...) +function onDef_Engine(t, mt) + t.GetVersion = function() + return ffi.string(libphx.Engine_GetVersion()) end end From 20943f1da26edead8b4b655fc0f93adde44b075c Mon Sep 17 00:00:00 2001 From: Oleg Khryptul Date: Tue, 21 Nov 2023 23:50:32 +0100 Subject: [PATCH 11/11] Use PHX_VERSION for the engine versioning --- .github/workflows/pr_build.yaml | 4 +++- .github/workflows/release_build.yaml | 4 +++- engine/lib/phx/src/engine/mod.rs | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr_build.yaml b/.github/workflows/pr_build.yaml index 8a2e9139f..8c11ce6d6 100644 --- a/.github/workflows/pr_build.yaml +++ b/.github/workflows/pr_build.yaml @@ -59,7 +59,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/.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/engine/lib/phx/src/engine/mod.rs b/engine/lib/phx/src/engine/mod.rs index 76dccc4b0..d1edb2f9a 100644 --- a/engine/lib/phx/src/engine/mod.rs +++ b/engine/lib/phx/src/engine/mod.rs @@ -599,7 +599,7 @@ impl Engine { } pub fn get_version() -> &'static str { - env!("CARGO_PKG_VERSION") + env!("PHX_VERSION") } pub fn exit(&mut self) {