mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 23:34:47 -05:00
Support building multiple versions of a rust crate
This is only to be used in exceptional cases. Generally we don't allow using multiple versions of a crate.
This commit is contained in:
parent
58b2362a24
commit
4b75dd7cf5
1 changed files with 74 additions and 23 deletions
|
@ -43,8 +43,10 @@ template("run_rustc") {
|
||||||
"cfg",
|
"cfg",
|
||||||
"crate_name",
|
"crate_name",
|
||||||
"crate_type",
|
"crate_type",
|
||||||
|
"crate_version",
|
||||||
"deps",
|
"deps",
|
||||||
"extern",
|
"extern",
|
||||||
|
"extern_version",
|
||||||
"features",
|
"features",
|
||||||
"is_test",
|
"is_test",
|
||||||
"source_root",
|
"source_root",
|
||||||
|
@ -75,21 +77,27 @@ template("run_rustc") {
|
||||||
args += [ "--color=always" ]
|
args += [ "--color=always" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!defined(crate_version)) {
|
||||||
|
crate_name_and_version = crate_name
|
||||||
|
} else {
|
||||||
|
crate_name_and_version = "$crate_name-$crate_version"
|
||||||
|
}
|
||||||
|
|
||||||
if (crate_type == "staticlib") {
|
if (crate_type == "staticlib") {
|
||||||
output_file = "$target_out_dir/$crate_name.a"
|
output_file = "$target_out_dir/$crate_name_and_version.a"
|
||||||
emit_type = "link"
|
emit_type = "link"
|
||||||
} else if (crate_type == "bin") {
|
} else if (crate_type == "bin") {
|
||||||
output_file = "$target_out_dir/$crate_name.o"
|
output_file = "$target_out_dir/$crate_name_and_version.o"
|
||||||
emit_type = "obj"
|
emit_type = "obj"
|
||||||
} else if (crate_type == "rlib") {
|
} else if (crate_type == "rlib") {
|
||||||
output_file = "$target_out_dir/lib$crate_name.rlib"
|
output_file = "$target_out_dir/lib$crate_name_and_version.rlib"
|
||||||
emit_type = "link"
|
emit_type = "link"
|
||||||
}
|
}
|
||||||
outputs += [ output_file ]
|
outputs += [ output_file ]
|
||||||
output_file_rel = rebase_path(output_file, root_build_dir)
|
output_file_rel = rebase_path(output_file, root_build_dir)
|
||||||
args += [ "--emit=$emit_type=$output_file_rel" ]
|
args += [ "--emit=$emit_type=$output_file_rel" ]
|
||||||
|
|
||||||
depfile = "$target_out_dir/$crate_name.d"
|
depfile = "$target_out_dir/$crate_name_and_version.d"
|
||||||
args += [
|
args += [
|
||||||
"--emit=dep-info=" + rebase_path(depfile, root_build_dir),
|
"--emit=dep-info=" + rebase_path(depfile, root_build_dir),
|
||||||
|
|
||||||
|
@ -99,6 +107,13 @@ template("run_rustc") {
|
||||||
"--output_file=" + output_file_rel,
|
"--output_file=" + output_file_rel,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if (defined(crate_version)) {
|
||||||
|
args += [
|
||||||
|
"-C",
|
||||||
|
"metadata=$crate_version",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
if (is_debug) {
|
if (is_debug) {
|
||||||
args += [ "-g" ]
|
args += [ "-g" ]
|
||||||
}
|
}
|
||||||
|
@ -137,48 +152,77 @@ template("run_rustc") {
|
||||||
deps = []
|
deps = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Convert all 'extern' and 'extern_version' items to a single format.
|
||||||
|
extern_infos = []
|
||||||
if (defined(extern)) {
|
if (defined(extern)) {
|
||||||
deps += extern
|
|
||||||
foreach(label, extern) {
|
foreach(label, extern) {
|
||||||
name = get_label_info(label, "name")
|
extern_infos += [
|
||||||
dir = get_label_info(label, "target_out_dir")
|
{
|
||||||
rlib = "$dir/lib$name.rlib"
|
label = label
|
||||||
args += [
|
crate_name = get_label_info(label, "name")
|
||||||
"--extern",
|
crate_name_and_version = crate_name
|
||||||
"$name=" + rebase_path(rlib, root_build_dir),
|
},
|
||||||
]
|
|
||||||
|
|
||||||
# This is needed for transitive dependencies.
|
|
||||||
args += [
|
|
||||||
"-L",
|
|
||||||
"dependency=" + rebase_path(dir, root_build_dir),
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (defined(extern_version)) {
|
||||||
|
foreach(info, extern_version) {
|
||||||
|
extern_infos += [
|
||||||
|
{
|
||||||
|
forward_variables_from(info, "*")
|
||||||
|
crate_name_and_version = "$crate_name-$crate_version"
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Build the list of '--extern' arguments from the 'extern_infos' array.
|
||||||
|
foreach(info, extern_infos) {
|
||||||
|
dir = get_label_info(info.label, "target_out_dir")
|
||||||
|
rlib = "$dir/lib${info.crate_name_and_version}.rlib"
|
||||||
|
args += [
|
||||||
|
"--extern",
|
||||||
|
info.crate_name + "=" + rebase_path(rlib, root_build_dir),
|
||||||
|
|
||||||
|
# This is needed for transitive dependencies.
|
||||||
|
"-L",
|
||||||
|
"dependency=" + rebase_path(dir, root_build_dir),
|
||||||
|
]
|
||||||
|
deps += [ info.label ]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template("rust_component") {
|
template("rust_component") {
|
||||||
rustc_name = target_name + "_rustc"
|
rustc_name = target_name + "_rustc"
|
||||||
rustc_label = ":" + rustc_name
|
rustc_label = ":" + rustc_name
|
||||||
crate_name = target_name
|
|
||||||
|
forward_variables_from(invoker,
|
||||||
|
[
|
||||||
|
"crate_name",
|
||||||
|
"crate_type",
|
||||||
|
])
|
||||||
|
if (!defined(crate_name)) {
|
||||||
|
crate_name = target_name
|
||||||
|
}
|
||||||
|
if (!defined(crate_type)) {
|
||||||
|
crate_type = "rlib"
|
||||||
|
}
|
||||||
|
|
||||||
run_rustc(rustc_name) {
|
run_rustc(rustc_name) {
|
||||||
forward_variables_from(invoker,
|
forward_variables_from(invoker,
|
||||||
[
|
[
|
||||||
"args",
|
"args",
|
||||||
"cfg",
|
"cfg",
|
||||||
"crate_name",
|
"crate_version",
|
||||||
"crate_type",
|
|
||||||
"deps",
|
"deps",
|
||||||
"extern",
|
"extern",
|
||||||
|
"extern_version",
|
||||||
"features",
|
"features",
|
||||||
"is_test",
|
"is_test",
|
||||||
"source_root",
|
"source_root",
|
||||||
"testonly",
|
"testonly",
|
||||||
])
|
])
|
||||||
if (!defined(invoker.crate_type)) {
|
|
||||||
crate_type = "rlib"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
crate_outputs = get_target_outputs(rustc_label)
|
crate_outputs = get_target_outputs(rustc_label)
|
||||||
|
@ -208,7 +252,9 @@ template("rust_staticlib") {
|
||||||
[
|
[
|
||||||
"cfg",
|
"cfg",
|
||||||
"crate_name",
|
"crate_name",
|
||||||
|
"crate_version",
|
||||||
"extern",
|
"extern",
|
||||||
|
"extern_version",
|
||||||
"features",
|
"features",
|
||||||
"source_root",
|
"source_root",
|
||||||
"testonly",
|
"testonly",
|
||||||
|
@ -244,6 +290,11 @@ template("rust_executable") {
|
||||||
if (defined(extern)) {
|
if (defined(extern)) {
|
||||||
deps += extern
|
deps += extern
|
||||||
}
|
}
|
||||||
|
if (defined(extern_version)) {
|
||||||
|
foreach(info, extern_version) {
|
||||||
|
deps += [ info.label ]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue