Skip to content

Conversation

@thomasballivet
Copy link
Contributor

@thomasballivet thomasballivet commented May 4, 2025

I introduced a GIT_HASH environment variable created for each crate that would need it. This is done in the build.rs file of each crate. The latter uses a tiny new crate build-helpers to factor out the code that gets the commit hash and which could also be used for other build purposes.

Then I adapted the impl fmt::Display for Version .
Also since the Version struct is used in both lianad and liana-gui don't you think it could be moved to liana ?

So now ./lianad --version and ./liana-gui --version return 10.0.0-dev-f43bed5, and the same goes for the window title.

Closes #1601

@thomasballivet thomasballivet force-pushed the add-commit-hash-dev-builds branch 3 times, most recently from 0d72aa3 to e55c3b0 Compare May 4, 2025 21:42
@pythcoiner
Copy link
Collaborator

overall LGTM
image

but I'm not sure it's needed for liana and 'liana-ui' as they are not binaries

@edouardparis
Copy link
Member

Thanks for the contribution, but it is currently introducing a new crate which seems overkill and add more work for the release process (that generally requires for me to comment the -dev part etc). We need to discuss first on the issue about the needs and the way of doing it. Is it only for quick development in debug mode, or for all binaries, etc.

@thomasballivet thomasballivet force-pushed the add-commit-hash-dev-builds branch from e55c3b0 to 8840ea1 Compare May 5, 2025 12:35
@thomasballivet
Copy link
Contributor Author

I adapted following your comments.
Now the version is displayed as : "{}.{}.{}-{}", without "-dev-".
And I use now include!("../build_common.rs"); instead of a crate for build.rss, and only for lianad and liana-gui, not for liana and liana-ui (easy to add if needed).

@thomasballivet thomasballivet force-pushed the add-commit-hash-dev-builds branch 2 times, most recently from 04d37e7 to 6b770bf Compare May 5, 2025 12:50
@thomasballivet
Copy link
Contributor Author

thomasballivet commented May 5, 2025

To simplify the release process we could add version and profile as environment variables at compile time and use them at runtime to build Version and adapt impl fmt::Display for Version (to add commit hash only for dev profile).

EDIT: the profile is already set by cargo during the build process

@pythcoiner
Copy link
Collaborator

from an internal discussion:

add

export LIANA_VERSION=${VERSION}

after this line

then:

  • we do not hardcode the version
  • if LIANA_VERSION is defined the version should be of type v10.0.0
  • if LIANA_VERSION not defined the version should be of type <COMMIT_HASH>

I think by this way we do not have to edit/comment any file during a release

@thomasballivet thomasballivet force-pushed the add-commit-hash-dev-builds branch 2 times, most recently from f0d17cf to 2fc1bbe Compare May 6, 2025 23:14
@thomasballivet thomasballivet marked this pull request as draft May 6, 2025 23:15
@thomasballivet
Copy link
Contributor Author

I converted the PR to draft because I've been unable to test the release.sh script yet. If someone can have a look just to tell me if i'm the right track before I put too much effort at testing the script it would be great! Thanks

@thomasballivet thomasballivet force-pushed the add-commit-hash-dev-builds branch from 64980f0 to 3ff5999 Compare May 8, 2025 01:08
@pythcoiner
Copy link
Collaborator

I finally had time to test this, the release script fails, while a normal cargo build --release is successful:

[...]
error: environment variable `GIT_HASH` not defined at compile time
  --> lianad/src/lib.rs:74:9
   |
74 |         env!("GIT_HASH")
   |         ^^^^^^^^^^^^^^^^
   |
   = help: use `std::env::var("GIT_HASH")` to read the variable at run time
   = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `lianad` (lib) due to 1 previous error

Caused by:
  process didn't exit successfully: `CARGO=/gnu/store/ak2hg0xx2z36pyjnjphzlgakn7wrk1zp-rust-1.82.0-cargo/bin/cargo CARGO_CRATE_NAME=lianad CARGO_MANIFEST_DIR=/liana/lianad CARGO_PKG_AUTHORS='Antoine Poinsot <[email protected]>' CARGO_PKG_DESCRIPTION='Liana wallet daemon' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE=LICENCE CARGO_PKG_NAME=lianad CARGO_PKG_README='' CARGO_PKG_REPOSITORY='https://github.com/wizardsardine/liana' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=10.0.0 CARGO_PKG_VERSION_MAJOR=10 CARGO_PKG_VERSION_MINOR=0 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 CARGO_RUSTC_CURRENT_DIR=/liana LD_LIBRARY_PATH=/out/release/deps rustc --crate-name lianad --edition=2018 lianad/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=142 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values("nonblocking_shutdown"))' -C metadata=bee94398826d4efb -C extra-filename=-bee94398826d4efb --out-dir /out/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -C linker=/home/pyth/.cache/cargo-zigbuild/0.19.4/zigcc-x86_64-unknown-linux-gnu.2.31-95bd.sh -C strip=debuginfo -L dependency=/out/x86_64-unknown-linux-gnu/release/deps -L dependency=/out/release/deps --extern backtrace=/out/x86_64-unknown-linux-gnu/release/deps/libbacktrace-a2e9620cd93274ea.rmeta --extern bdk_electrum=/out/x86_64-unknown-linux-gnu/release/deps/libbdk_electrum-a0fcccc582084893.rmeta --extern bip329=/out/x86_64-unknown-linux-gnu/release/deps/libbip329-63111521d8896e29.rmeta --extern dirs=/out/x86_64-unknown-linux-gnu/release/deps/libdirs-3cf081609d82f9b9.rmeta --extern fern=/out/x86_64-unknown-linux-gnu/release/deps/libfern-89318ce6ada16f1f.rmeta --extern jsonrpc=/out/x86_64-unknown-linux-gnu/release/deps/libjsonrpc-258308fb29ecade9.rmeta --extern liana=/out/x86_64-unknown-linux-gnu/release/deps/libliana-32d185aa2c6106f1.rmeta --extern log=/out/x86_64-unknown-linux-gnu/release/deps/liblog-40232d9722768c33.rmeta --extern miniscript=/out/x86_64-unknown-linux-gnu/release/deps/libminiscript-34f6be7f5f067b57.rmeta --extern rusqlite=/out/x86_64-unknown-linux-gnu/release/deps/librusqlite-04a6a215e116603b.rmeta --extern serde=/out/x86_64-unknown-linux-gnu/release/deps/libserde-6964e9fb5e908fd5.rmeta --extern serde_json=/out/x86_64-unknown-linux-gnu/release/deps/libserde_json-8a4e2b4a87cee16a.rmeta --extern toml=/out/x86_64-unknown-linux-gnu/release/deps/libtoml-3ab4e1db301b190b.rmeta -L native=/out/x86_64-unknown-linux-gnu/release/build/secp256k1-sys-c9f85793103f13ca/out -L native=/out/x86_64-unknown-linux-gnu/release/build/ring-f32f129c3eb18b67/out -L native=/out/x86_64-unknown-linux-gnu/release/build/libsqlite3-sys-3e06f46af9b62aa1/out` (exit status: 1)

@thomasballivet thomasballivet force-pushed the add-commit-hash-dev-builds branch 4 times, most recently from 2661773 to 44e3c7f Compare September 4, 2025 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add commit hash to the version for dev builds

3 participants