mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 07:44:48 -05:00
build: support rust crates that generate sources in their build script
This commit is contained in:
parent
6c7d337960
commit
31aa7c1a5d
2 changed files with 25 additions and 2 deletions
|
@ -7,6 +7,7 @@ import sys
|
|||
import os
|
||||
import re
|
||||
|
||||
args = sys.argv[1:]
|
||||
env = os.environ.copy()
|
||||
|
||||
if sys.platform == 'win32':
|
||||
|
@ -26,9 +27,19 @@ if sys.platform == 'win32':
|
|||
env["GN_OUT_DIR"] = os.path.abspath(".")
|
||||
assert os.path.isdir(env["GN_OUT_DIR"])
|
||||
|
||||
# Some crates (e.g. 'typenum') generate source files and place them in the
|
||||
# directory indicated by the 'OUT_DIR' environment variable, which is normally
|
||||
# set by Cargo. We pre-generate these files and store them in the source repo.
|
||||
# Therefore, set 'OUT_DIR' so these crates can find their generated sources.
|
||||
for i, arg in enumerate(args):
|
||||
match = re.search('--generated-source-dir=(.*)', arg)
|
||||
if match:
|
||||
env["OUT_DIR"] = os.path.abspath(match.group(1))
|
||||
del args[i]
|
||||
break
|
||||
|
||||
# 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:
|
||||
|
|
|
@ -62,8 +62,9 @@ template("_rust_crate") {
|
|||
"crate_version",
|
||||
"deps",
|
||||
"edition",
|
||||
"inputs",
|
||||
"features",
|
||||
"generated_source_dir",
|
||||
"inputs",
|
||||
"is_test",
|
||||
"libs",
|
||||
"source_root",
|
||||
|
@ -237,6 +238,17 @@ template("_rust_crate") {
|
|||
"--color=always",
|
||||
]
|
||||
|
||||
if (defined(generated_source_dir)) {
|
||||
args += [
|
||||
# Some crates (e.g. 'typenum') generate source files and place them in
|
||||
# the directory indicated by the 'OUT_DIR' environment variable, which
|
||||
# is normally set by Cargo. This flag tells run.py to set 'OUT_DIR' to
|
||||
# the path where the current crate can find its generated sources.
|
||||
"--generated-source-dir=" +
|
||||
rebase_path(generated_source_dir, root_build_dir),
|
||||
]
|
||||
}
|
||||
|
||||
if (defined(crate_version)) {
|
||||
args += [
|
||||
# This is used to set env variables for Cargo build compatibility
|
||||
|
|
Loading…
Reference in a new issue