Skip to content

Commit 1123cb1

Browse files
authored
Merge pull request #18 from yuchanns/feat/generate-version-at-compile
feat(version): generate version at compile time
2 parents b94746f + cd59e77 commit 1123cb1

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

clibs/soluna/make.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
11
local lm = require "luamake"
2+
local subprocess = require "bee.subprocess"
23

34
lm.rootdir = lm.basedir
45

6+
local ok, process, errMsg = pcall(subprocess.spawn, {
7+
lm.os ~= "windows" and "git" or "C:\\Program Files\\Git\\cmd\\git.exe",
8+
"rev-parse",
9+
"HEAD",
10+
stdout = true,
11+
})
12+
local commit
13+
if ok then
14+
if errMsg then
15+
print("Failed to start git process: " .. errMsg)
16+
else
17+
local output = process.stdout:read "a"
18+
commit = output:match "^%s*(.-)%s*$"
19+
process:wait()
20+
print("Hash version: " .. commit)
21+
end
22+
end
23+
524
lm:source_set "soluna_src" {
625
sources = {
726
"src/*.c",
827
},
28+
defines = {
29+
commit and string.format('SOLUNA_HASH_VERSION=\\"%s\\"', commit),
30+
},
931
includes = {
1032
"build",
1133
"3rd/lua",

src/version.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#define soluna_version_h
33

44
#define SOLUNA_API_VERSION 1
5-
#define SOLUNA_HASH_VERSION "16fd5b12ef47b7cb3aba5869c83705f52ccd4645"
5+
#ifndef SOLUNA_HASH_VERSION
6+
#define SOLUNA_HASH_VERSION "dev"
7+
#endif
68

79
#endif

0 commit comments

Comments
 (0)