summaryrefslogtreecommitdiff
path: root/build_extra/rust
diff options
context:
space:
mode:
Diffstat (limited to 'build_extra/rust')
-rw-r--r--build_extra/rust/get_cargo_info.cmd1
-rwxr-xr-xbuild_extra/rust/get_cargo_info.py14
-rw-r--r--build_extra/rust/run.py17
-rw-r--r--build_extra/rust/rust.gni8
4 files changed, 37 insertions, 3 deletions
diff --git a/build_extra/rust/get_cargo_info.cmd b/build_extra/rust/get_cargo_info.cmd
new file mode 100644
index 000000000..9d5ce12a1
--- /dev/null
+++ b/build_extra/rust/get_cargo_info.cmd
@@ -0,0 +1 @@
+@"%PYTHON_EXE%" "%~dpn0.py" %*
diff --git a/build_extra/rust/get_cargo_info.py b/build_extra/rust/get_cargo_info.py
new file mode 100755
index 000000000..43c964ab7
--- /dev/null
+++ b/build_extra/rust/get_cargo_info.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+# Copyright 2018 the Deno authors. All rights reserved. MIT license.
+
+import sys
+import re
+
+# Read the package version from Cargo.toml and output as json
+cargo_toml_path = sys.argv[1]
+
+for line in open(cargo_toml_path):
+ match = re.search('version = "(.*)"', line)
+ if match:
+ print('{"version": "' + match.group(1) + '"}')
+ break
diff --git a/build_extra/rust/run.py b/build_extra/rust/run.py
index 3a86c423c..dc89c09a1 100644
--- a/build_extra/rust/run.py
+++ b/build_extra/rust/run.py
@@ -1,13 +1,24 @@
#!/usr/bin/env python
-# This file just executes its arguments, except that also adds GN_OUT_DIR to the
-# environ. This is for compatibility with cargo.
+# This file just executes its arguments, except that also adds GN_OUT_DIR and
+# CARGO_PKG_VERSION to the environ. This is for compatibility with cargo.
import subprocess
import sys
import os
+import re
# This is for src/msg.rs to know where to find msg_generated.rs.
# When building with Cargo this variable is set by build.rs.
os.environ["GN_OUT_DIR"] = os.path.abspath(".")
assert os.path.isdir(os.environ["GN_OUT_DIR"])
-sys.exit(subprocess.call(sys.argv[1:]))
+# Set the CARGO_PKG_VERSION env variable if provided as an argument
+# When building with Cargo this variable is set automatically
+args = sys.argv[1:]
+for i, arg in enumerate(args):
+ match = re.search('--cargo-pkg-version="?([^"]*)"?', arg)
+ if match:
+ os.environ["CARGO_PKG_VERSION"] = match.group(1)
+ del args[i]
+ break
+
+sys.exit(subprocess.call(args))
diff --git a/build_extra/rust/rust.gni b/build_extra/rust/rust.gni
index 3263f0018..61731d21c 100644
--- a/build_extra/rust/rust.gni
+++ b/build_extra/rust/rust.gni
@@ -49,6 +49,7 @@ template("rust_crate") {
"crate_type",
"crate_version",
"deps",
+ "inputs",
"features",
"is_test",
"libs",
@@ -190,6 +191,13 @@ template("rust_crate") {
"--color=always",
]
+ if (defined(crate_version)) {
+ args += [
+ # This is used to set env variables for Cargo build compatibility
+ "--cargo-pkg-version=$crate_version",
+ ]
+ }
+
if (is_debug) {
args += [ "-g" ]
}