diff options
-rw-r--r-- | BUILD.gn | 61 | ||||
-rw-r--r-- | build_extra/rust/rust.gni | 100 |
2 files changed, 63 insertions, 98 deletions
@@ -35,76 +35,21 @@ config("deno_config") { } main_extern = [ + "$rust_build:futures", "$rust_build:libc", "$rust_build:log", "$rust_build:sha1", "$rust_build:tempfile", "$rust_build:tokio", + "$rust_build:tokio_current_thread", "$rust_build:url", "//build_extra/flatbuffers/rust:flatbuffers", ":msg_rs", - - # Indirect rust depdendencies also need to be listed here: - # * Linking to `:handlers` or `:libdeno` isn't possible, because they - # already contain some symbols exported by `handlers.rs`. These duplicate - # symbols trip up the linker. - # * The `rust_test` and `rust_executable` templates only produce an object - # file, and then invoke an external linker. Transitive rust depencenies - # are not resolved in either step. - "$rust_build:arrayvec", - "$rust_build:byteorder", - "$rust_build:bytes", - "$rust_build:crossbeam_deque", - "$rust_build:crossbeam_epoch", - "$rust_build:crossbeam_utils", - "$rust_build:futures", - "$rust_build:idna", - "$rust_build:iovec", - "$rust_build:kernel32", - "$rust_build:lazy_static", - "$rust_build:lazycell", - "$rust_build:memoffset", - "$rust_build:mio", - "$rust_build:miow", - "$rust_build:net2", - "$rust_build:nodrop", - "$rust_build:num_cpus", - "$rust_build:percent_encoding", - "$rust_build:rand", - "$rust_build:rand_core", - "$rust_build:remove_dir_all", - "$rust_build:scopeguard", - "$rust_build:slab", - "$rust_build:tokio_executor", - "$rust_build:tokio_fs", - "$rust_build:tokio_io", - "$rust_build:tokio_reactor", - "$rust_build:tokio_tcp", - "$rust_build:tokio_threadpool", - "$rust_build:tokio_current_thread", - "$rust_build:tokio_timer", - "$rust_build:tokio_udp", - "$rust_build:unicode_bidi", - "$rust_build:unicode_normalization", - "$rust_build:winapi", - "$rust_build:ws2_32", -] - -# Old version of the 'winapi' crate, required by 'mio', 'miow', and 'iovec'. -# This exceptional! Generally we don't allow multiple versions of a crate. -# TODO: Remove this dependency. https://github.com/denoland/deno/issues/484 -main_extern_version = [ - { - label = "$rust_build:winapi-0.2" - crate_name = "winapi" - crate_version = "0.2" - }, ] rust_executable("deno") { source_root = "src/main.rs" extern = main_extern - extern_version = main_extern_version deps = [ ":libdeno", ] @@ -117,7 +62,6 @@ rust_executable("deno") { rust_executable("deno_ns") { source_root = "src/main.rs" extern = main_extern - extern_version = main_extern_version deps = [ ":libdeno_nosnapshot", ] @@ -126,7 +70,6 @@ rust_executable("deno_ns") { rust_test("test_rs") { source_root = "src/main.rs" extern = main_extern - extern_version = main_extern_version deps = [ ":libdeno", ] diff --git a/build_extra/rust/rust.gni b/build_extra/rust/rust.gni index 6cb3c6fa7..c7e951c4b 100644 --- a/build_extra/rust/rust.gni +++ b/build_extra/rust/rust.gni @@ -9,6 +9,11 @@ if (is_win) { executable_suffix = "" } +# To simplify transitive dependency management with gn, we build all rust +# crates into the same directory. We need to be careful not to have crates +# with the same name. +out_dir = "$root_out_dir/rust_crates" + # The official way of building Rust executables is to to let rustc do the # linking. However, we'd prefer to leave it in the hands of gn/ninja: # * It allows us to use source sets. @@ -44,8 +49,7 @@ template("run_rustc") { "crate_type", "crate_version", "deps", - "extern", - "extern_version", + "extern_infos", "features", "is_test", "source_root", @@ -61,7 +65,6 @@ template("run_rustc") { sources = [ source_root, ] - outputs = [] script = "//tools/run_rustc.py" # TODO: We want to apply "-Dwarnings" only when treat_warnings_as_errors is not false @@ -83,17 +86,19 @@ template("run_rustc") { } if (crate_type == "bin") { - output_file = "$target_out_dir/$crate_name_and_version.o" + output_file = "$out_dir/$crate_name_and_version.o" emit_type = "obj" } else if (crate_type == "rlib") { - output_file = "$target_out_dir/lib$crate_name_and_version.rlib" + output_file = "$out_dir/lib$crate_name_and_version.rlib" emit_type = "link" } - outputs += [ output_file ] + outputs = [ + output_file, + ] output_file_rel = rebase_path(output_file, root_build_dir) args += [ "--emit=$emit_type=$output_file_rel" ] - depfile = "$target_out_dir/$crate_name_and_version.d" + depfile = "$out_dir/$crate_name_and_version.d" args += [ "--emit=dep-info=" + rebase_path(depfile, root_build_dir), @@ -101,6 +106,10 @@ template("run_rustc") { # the depfile on the fly. They are not passed thru to rustc. "--depfile=" + rebase_path(depfile, root_build_dir), "--output_file=" + output_file_rel, + + # This is needed for transitive dependencies. + "-L", + "dependency=" + rebase_path(out_dir, root_build_dir), ] if (defined(crate_version)) { @@ -139,41 +148,12 @@ template("run_rustc") { deps = [] } - # Convert all 'extern' and 'extern_version' items to a single format. - extern_infos = [] - if (defined(extern)) { - foreach(label, extern) { - extern_infos += [ - { - label = label - crate_name = get_label_info(label, "name") - crate_name_and_version = crate_name - }, - ] - } - } - 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" + rlib = "$out_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 ] } @@ -183,6 +163,36 @@ template("run_rustc") { template("rust_crate") { rustc_name = target_name + "_rustc" rustc_label = ":" + rustc_name + config_name = target_name + "_config" + + # Convert all 'extern' and 'extern_version' items to a single format. + extern_infos = [] + if (defined(invoker.extern)) { + foreach(label, invoker.extern) { + extern_infos += [ + { + label = label + crate_name = get_label_info(label, "name") + crate_name_and_version = crate_name + }, + ] + } + } + if (defined(invoker.extern_version)) { + foreach(info, invoker.extern_version) { + extern_infos += [ + { + forward_variables_from(info, + [ + "label", + "crate_name", + "crate_version", + ]) + crate_name_and_version = "$crate_name-$crate_version" + }, + ] + } + } forward_variables_from(invoker, [ @@ -202,8 +212,6 @@ template("rust_crate") { "args", "crate_version", "deps", - "extern", - "extern_version", "features", "is_test", "source_root", @@ -214,6 +222,19 @@ template("rust_crate") { crate_outputs = get_target_outputs(rustc_label) crate_obj = crate_outputs[0] + config(config_name) { + lib_dirs = [] + forward_variables_from(invoker, [ "libs" ]) + if (!defined(libs)) { + libs = [] + } + foreach(info, extern_infos) { + rlib = "$out_dir/lib${info.crate_name_and_version}.rlib" + libs += [ rlib ] + } + lib_dirs = [ out_dir ] + } + source_set(target_name) { forward_variables_from(invoker, [ @@ -229,6 +250,7 @@ template("rust_crate") { } libs += [ crate_obj ] deps += [ rustc_label ] + all_dependent_configs = [ ":" + config_name ] } } |