summaryrefslogtreecommitdiff
path: root/rust/builder.go
diff options
context:
space:
mode:
author Ivan Lozano <ivanlozano@google.com> 2023-07-28 12:42:20 -0400
committer Ivan Lozano <ivanlozano@google.com> 2023-07-31 09:25:18 -0400
commitf445562840786b5f0f011df2d8ccb882d0f95ffd (patch)
tree97e9d4381731b9aa799c853ab24b909b3b9d37b5 /rust/builder.go
parent5c2b3e2ea6d332c876a20019153f67032e58f43e (diff)
rust: Add support for more cargo pkg version vars
Add support for CARGO_PKG_VERSION_{MAJOR,MINOR,PATCH}. Bug: 293602526 Test: m Test: check build flags for cargo_env_compat module Change-Id: I6b2796656e3a489cd077c2f42b0bbd04de610ba4
Diffstat (limited to 'rust/builder.go')
-rw-r--r--rust/builder.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/rust/builder.go b/rust/builder.go
index c31bc88d1..fbceecc80 100644
--- a/rust/builder.go
+++ b/rust/builder.go
@@ -228,6 +228,17 @@ func rustEnvVars(ctx ModuleContext, deps PathDeps) []string {
pkgVersion := ctx.RustModule().compiler.CargoPkgVersion()
if pkgVersion != "" {
envVars = append(envVars, "CARGO_PKG_VERSION="+pkgVersion)
+
+ // Ensure the version is in the form of "x.y.z" (approximately semver compliant).
+ //
+ // For our purposes, we don't care to enforce that these are integers since they may
+ // include other characters at times (e.g. sometimes the patch version is more than an integer).
+ if strings.Count(pkgVersion, ".") == 2 {
+ var semver_parts = strings.Split(pkgVersion, ".")
+ envVars = append(envVars, "CARGO_PKG_VERSION_MAJOR="+semver_parts[0])
+ envVars = append(envVars, "CARGO_PKG_VERSION_MINOR="+semver_parts[1])
+ envVars = append(envVars, "CARGO_PKG_VERSION_PATCH="+semver_parts[2])
+ }
}
}