From 5c0e06eaf4633ed1e1c996c1a1a96c437e7e164e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Sat, 1 Feb 2025 17:28:52 -0500 Subject: [PATCH 1/3] Use `vcs_tag` to get Git version instead of `run_command` This way Meson will automatically keep the Git hash updated as you make new Git commits, rather than forcing you to reconfigure the build again every time you make a new commit to keep the commit hash updated. (cherry picked from commit b9bb3535aeda6e604ff2b9dc2f871c8214aab41f) --- binding/binding-mri.cpp | 4 ++++ meson.build | 5 +---- src/git-hash.h.in | 3 +++ 3 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 src/git-hash.h.in diff --git a/binding/binding-mri.cpp b/binding/binding-mri.cpp index 5c888bac..cb3b2d49 100644 --- a/binding/binding-mri.cpp +++ b/binding/binding-mri.cpp @@ -64,6 +64,10 @@ extern "C" { #include #include +#ifndef MKXPZ_BUILD_XCODE +# include "git-hash.h" +#endif // MKXPZ_BUILD_XCODE + extern const char module_rpg1[]; extern const char module_rpg2[]; extern const char module_rpg3[]; diff --git a/meson.build b/meson.build index 8aa0e836..6c8500da 100644 --- a/meson.build +++ b/meson.build @@ -6,11 +6,9 @@ if host_system == 'darwin' error('\nThis Meson project no longer supports macOS. Please use the Xcode project instead.') endif -git_hash = run_command('git', 'rev-parse', '--short', 'HEAD').stdout().strip() - compilers = {'cpp': meson.get_compiler('cpp')} -global_sources = [] +global_sources = [vcs_tag(command: ['git', 'rev-parse', '--short', 'HEAD'], input: 'src/git-hash.h.in', output: 'git-hash.h')] global_dependencies = [] global_include_dirs = [] global_args = [] @@ -23,7 +21,6 @@ win64 = (sizeof['void*'] != sizeof['long']) global_args += '-DMKXPZ_BUILD_MESON' global_args += '-DMKXPZ_VERSION="@0@"'.format(meson.project_version()) -global_args += '-DMKXPZ_GIT_HASH="@0@"'.format(git_hash) global_args += '-DHAVE_NANOSLEEP' # ==================== # Ext libs diff --git a/src/git-hash.h.in b/src/git-hash.h.in new file mode 100644 index 00000000..6360486e --- /dev/null +++ b/src/git-hash.h.in @@ -0,0 +1,3 @@ +#ifndef MKXPZ_GIT_HASH +# define MKXPZ_GIT_HASH "@VCS_TAG@" +#endif /* MKXPZ_GIT_HASH */ From 923b054fad6e83a0810001c0218cb739eb1bed8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Fri, 28 Feb 2025 00:30:40 -0500 Subject: [PATCH 2/3] Define as `extern const` instead of `const` in embedtool.cpp --- embedtool.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/embedtool.cpp b/embedtool.cpp index f4fd28a6..7ee9dc41 100644 --- a/embedtool.cpp +++ b/embedtool.cpp @@ -41,7 +41,7 @@ int main(int argc, char **argv) { return 3; } - outputf << "#include \n#include \nconst uint8_t " << arrayname << "[] = {"; + outputf << "#include \n#include \nextern const uint8_t " << arrayname << "[] = {"; uint64_t len = 0; for (;;) { @@ -53,7 +53,7 @@ int main(int argc, char **argv) { ++len; } - outputf << "};\nconst size_t " << arrayname << "_len = " << len << "ULL;"; + outputf << "};\nextern const size_t " << arrayname << "_len = " << len << "ULL;"; return 0; } From 5be1f6962e354b991ef6ed53e81926932bdaded5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Fri, 28 Feb 2025 00:40:32 -0500 Subject: [PATCH 3/3] Explicitly request 7-character Git hash in meson.build It seems the length of the hash generated by `git rev-parse --short HEAD` is nondeterministic. GitHub Actions generates 7-character hashes, while my computer currently generates 8-character hashes. To be consistent, I'm forcing the hashes to be 7 characters long. --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 6c8500da..d77ea755 100644 --- a/meson.build +++ b/meson.build @@ -8,7 +8,7 @@ endif compilers = {'cpp': meson.get_compiler('cpp')} -global_sources = [vcs_tag(command: ['git', 'rev-parse', '--short', 'HEAD'], input: 'src/git-hash.h.in', output: 'git-hash.h')] +global_sources = [vcs_tag(command: ['git', 'rev-parse', '--short=7', 'HEAD'], fallback: 'unknown', input: 'src/git-hash.h.in', output: 'git-hash.h')] global_dependencies = [] global_include_dirs = [] global_args = []