Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add public build metadata [WPB-11001] #767

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ repos:
- id: check-case-conflict
- id: check-merge-conflict
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- id: check-json
- id: check-toml
Expand Down
153 changes: 143 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions crypto-ffi/src/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,44 @@ pub fn version() -> String {
VERSION.to_string()
}

#[derive(uniffi::Record)]
/// Metadata describing the conditions of the build of this software.
pub struct BuildMetadata {
/// Build Timestamp
pub timestamp: String,
/// Whether this build was in Debug mode (true) or Release mode (false)
pub cargo_debug: String,
/// Features enabled for this build
pub cargo_features: String,
/// Optimization level
pub opt_level: String,
/// Build target triple
pub target_triple: String,
/// Git branch
pub git_branch: String,
/// Output of `git describe`
pub git_describe: String,
/// Hash of current git commit
pub git_sha: String,
/// `true` when the source code differed from the commit at the most recent git hash
pub git_dirty: String,
}

#[uniffi::export]
pub fn build_metadata() -> BuildMetadata {
BuildMetadata {
timestamp: core_crypto::BUILD_METADATA.timestamp.to_string(),
cargo_debug: core_crypto::BUILD_METADATA.cargo_debug.to_string(),
cargo_features: core_crypto::BUILD_METADATA.cargo_features.to_string(),
opt_level: core_crypto::BUILD_METADATA.opt_level.to_string(),
target_triple: core_crypto::BUILD_METADATA.target_triple.to_string(),
git_branch: core_crypto::BUILD_METADATA.git_branch.to_string(),
git_describe: core_crypto::BUILD_METADATA.git_describe.to_string(),
git_sha: core_crypto::BUILD_METADATA.git_sha.to_string(),
git_dirty: core_crypto::BUILD_METADATA.git_dirty.to_string(),
}
}

#[derive(Debug, thiserror::Error, uniffi::Error)]
pub enum CoreCryptoError {
#[error(transparent)]
Expand Down
3 changes: 3 additions & 0 deletions crypto-ffi/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ use wasm_bindgen_futures::future_to_promise;
#[allow(dead_code)]
pub(super) const VERSION: &str = env!("CARGO_PKG_VERSION");

#[allow(unused_imports)]
pub(super) use core_crypto::BUILD_METADATA;

// This is intended to hotfix this import:
// ❯ wasmer inspect bindings/js/wasm/core-crypto-ffi_bg.wasm | grep env
// "env"."__stack_chk_fail": [] -> []
Expand Down
7 changes: 7 additions & 0 deletions crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,10 @@ harness = false
[[bench]]
name = "mls_proteus"
harness = false

[build-dependencies]
anyhow = "1.0.93"
# this is appropriate if we always and only build in environments where `git`
# is available on the command line. If not, we should replace this with
# `vergen-gix` or `vergen-git2`.
vergen-gitcl = { version = "1.0.1", features = ["build", "cargo"] }
29 changes: 28 additions & 1 deletion crypto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.

fn main() {
use vergen_gitcl::{BuildBuilder, CargoBuilder, Emitter, GitclBuilder};

fn main() -> anyhow::Result<()> {
// Target aliases
#[cfg(target_os = "ios")]
println!("cargo:rustc-cfg=ios");
Expand All @@ -28,4 +30,29 @@ fn main() {
if let Ok(profile) = std::env::var("PROFILE") {
println!("cargo:rustc-cfg=build=\"{profile}\"");
}

// collect a bunch of build/git information and emit it into the build environment,
// from whence we can extract it and make it public
let build = BuildBuilder::default().build_timestamp(true).build()?;
let cargo = CargoBuilder::default()
.debug(true)
.features(true)
.opt_level(true)
.target_triple(true)
.build()?;
let git = GitclBuilder::default()
.branch(true)
.sha(false)
.dirty(false)
.describe(true, true, Some("v*"))
.build()?;

Emitter::default()
.fail_on_error()
.add_instructions(&build)?
.add_instructions(&cargo)?
.add_instructions(&git)?
.emit()?;

Ok(())
}
Loading
Loading