diff --git a/WORKSPACE b/WORKSPACE index 06a816ecb0..886d8b5b9a 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -11,8 +11,7 @@ local_repository( ) # TODO: Move this to examples/WORKSPACE when recursive repositories are enabled. -load("//rust:rust.bzl", "rust_repositories") - +load("//rust:repositories.bzl", "rust_repositories") rust_repositories() new_git_repository( diff --git a/rust/BUILD b/rust/BUILD index ff067a7e9b..1942c9ac47 100644 --- a/rust/BUILD +++ b/rust/BUILD @@ -37,9 +37,9 @@ filegroup( ) filegroup( - name = "rustlib", + name = "rust_lib", srcs = select({ - ":darwin": ["@rust_darwin_x86_64//:rustlib"], - ":k8": ["@rust_linux_x86_64//:rustlib"], + ":darwin": ["@rust_darwin_x86_64//:rust_lib"], + ":k8": ["@rust_linux_x86_64//:rust_lib"], }), ) diff --git a/rust/repositories.bzl b/rust/repositories.bzl new file mode 100644 index 0000000000..f7d05700e9 --- /dev/null +++ b/rust/repositories.bzl @@ -0,0 +1,83 @@ +RUST_DARWIN_BUILD_FILE = """ +filegroup( + name = "rustc", + srcs = ["rustc/bin/rustc"], + visibility = ["//visibility:public"], +) + +filegroup( + name = "rustc_lib", + srcs = glob(["rustc/lib/*.dylib"]), + visibility = ["//visibility:public"], +) + +filegroup( + name = "rustdoc", + srcs = ["rustc/bin/rustdoc"], + visibility = ["//visibility:public"], +) + +filegroup( + name = "rust_lib", + srcs = glob([ + "rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/*.rlib", + "rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/*.dylib", + "rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/*.a", + "rustc/lib/rustlib/x86_64-apple-darwin/lib/*.rlib", + "rustc/lib/rustlib/x86_64-apple-darwin/lib/*.dylib", + "rustc/lib/rustlib/x86_64-apple-darwin/lib/*.a", + ]), + visibility = ["//visibility:public"], +) +""" + +RUST_LINUX_BUILD_FILE = """ +filegroup( + name = "rustc", + srcs = ["rustc/bin/rustc"], + visibility = ["//visibility:public"], +) + +filegroup( + name = "rustc_lib", + srcs = glob(["rustc/lib/*.so"]), + visibility = ["//visibility:public"], +) + +filegroup( + name = "rustdoc", + srcs = ["rustc/bin/rustdoc"], + visibility = ["//visibility:public"], +) + +filegroup( + name = "rust_lib", + srcs = glob([ + "rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.rlib", + "rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.so", + "rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.a", + "rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.rlib", + "rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.so", + "rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.a", + ]), + visibility = ["//visibility:public"], +) +""" + +# Eventually with better toolchain hosting options we could load only one of these, not both. +def rust_repositories(): + native.new_http_archive( + name = "rust_linux_x86_64", + url = "http://bazel-mirror.storage.googleapis.com/static.rust-lang.org/dist/rust-1.15.1-x86_64-unknown-linux-gnu.tar.gz", + strip_prefix = "rust-1.15.1-x86_64-unknown-linux-gnu", + sha256 = "b1e7c818a3cc8b010932f0efc1cf0ede7471958310f808d543b6e32d2ec748e7", + build_file_content = RUST_LINUX_BUILD_FILE, + ) + + native.new_http_archive( + name = "rust_darwin_x86_64", + url = "http://bazel-mirror.storage.googleapis.com/static.rust-lang.org/dist/rust-1.15.1-x86_64-apple-darwin.tar.gz", + strip_prefix = "rust-1.15.1-x86_64-apple-darwin", + sha256 = "38606e464b31a778ffa7d25d490a9ac53b472102bad8445b52e125f63726ac64", + build_file_content = RUST_DARWIN_BUILD_FILE, + ) diff --git a/rust/rust.bzl b/rust/rust.bzl index ecb123aee2..1fe2fcacc5 100644 --- a/rust/rust.bzl +++ b/rust/rust.bzl @@ -211,8 +211,8 @@ def _rust_toolchain(ctx): rustc_path = ctx.file._rustc.path, rustc_lib_path = ctx.files._rustc_lib[0].dirname, rustc_lib_short_path = _get_dirname(ctx.files._rustc_lib[0].short_path), - rustlib_path = ctx.files._rustlib[0].dirname, - rustlib_short_path = _get_dirname(ctx.files._rustlib[0].short_path), + rust_lib_path = ctx.files._rust_lib[0].dirname, + rust_lib_short_path = _get_dirname(ctx.files._rust_lib[0].short_path), rustdoc_path = ctx.file._rustdoc.path, rustdoc_short_path = ctx.file._rustdoc.short_path) @@ -266,7 +266,7 @@ def _build_rustc_command(ctx, crate_name, crate_type, src, output_dir, "--codegen ar=%s" % ar, "--codegen linker=%s" % cc, "--codegen link-args='%s'" % ' '.join(cpp_fragment.link_options), - "-L all=%s" % toolchain.rustlib_path, + "-L all=%s" % toolchain.rust_lib_path, "--out-dir %s" % output_dir, "--emit=dep-info,link", ] + @@ -336,7 +336,7 @@ def _rust_library_impl(ctx): depinfo.transitive_libs + [ctx.file._rustc] + ctx.files._rustc_lib + - ctx.files._rustlib + + ctx.files._rust_lib + ctx.files._crosstool) ctx.action( @@ -389,7 +389,7 @@ def _rust_binary_impl(ctx): depinfo.transitive_libs + [ctx.file._rustc] + ctx.files._rustc_lib + - ctx.files._rustlib + + ctx.files._rust_lib + ctx.files._crosstool) ctx.action( @@ -451,7 +451,7 @@ def _rust_test_common(ctx, test_binary): depinfo.transitive_libs + [ctx.file._rustc] + ctx.files._rustc_lib + - ctx.files._rustlib + + ctx.files._rust_lib + ctx.files._crosstool) ctx.action( @@ -538,7 +538,7 @@ def _rust_doc_impl(ctx): toolchain.rustdoc_path, lib_rs.path, "--crate-name %s" % target.name, - "-L all=%s" % toolchain.rustlib_path, + "-L all=%s" % toolchain.rust_lib_path, "-o %s" % docs_dir, ] + doc_flags + @@ -560,7 +560,7 @@ def _rust_doc_impl(ctx): depinfo.libs + [ctx.file._rustdoc] + ctx.files._rustc_lib + - ctx.files._rustlib) + ctx.files._rust_lib) ctx.action( inputs = rustdoc_inputs, @@ -604,7 +604,7 @@ def _rust_doc_test_impl(ctx): "LD_LIBRARY_PATH=%s" % toolchain.rustc_lib_short_path, "DYLD_LIBRARY_PATH=%s" % toolchain.rustc_lib_short_path, toolchain.rustdoc_short_path, - "-L all=%s" % toolchain.rustlib_short_path, + "-L all=%s" % toolchain.rust_lib_short_path, lib_rs.path, ] + depinfo.search_flags + @@ -619,7 +619,7 @@ def _rust_doc_test_impl(ctx): depinfo.transitive_libs + [ctx.file._rustdoc] + ctx.files._rustc_lib + - ctx.files._rustlib) + ctx.files._rust_lib) runfiles = ctx.runfiles(files = doc_test_inputs, collect_data = True) return struct(runfiles = runfiles) @@ -649,8 +649,8 @@ _rust_toolchain_attrs = { "_rustc_lib": attr.label( default = Label("//rust:rustc_lib"), ), - "_rustlib": attr.label( - default = Label("//rust:rustlib"), + "_rust_lib": attr.label( + default = Label("//rust:rust_lib"), ), "_rustdoc": attr.label( default = Label("//rust:rustdoc"), @@ -1303,83 +1303,3 @@ Example: Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation tests for the `hello_lib` library crate. """ - -RUST_BUILD_FILE = """ -config_setting( - name = "darwin", - values = {"host_cpu": "darwin"}, -) - -config_setting( - name = "k8", - values = {"host_cpu": "k8"}, -) - -filegroup( - name = "rustc", - srcs = select({ - ":darwin": ["rustc/bin/rustc"], - ":k8": ["rustc/bin/rustc"], - }), - visibility = ["//visibility:public"], -) - -filegroup( - name = "rustc_lib", - srcs = select({ - ":darwin": glob(["rustc/lib/*.dylib"]), - ":k8": glob(["rustc/lib/*.so"]), - }), - visibility = ["//visibility:public"], -) - -filegroup( - name = "rustdoc", - srcs = select({ - ":darwin": ["rustc/bin/rustdoc"], - ":k8": ["rustc/bin/rustdoc"], - }), - visibility = ["//visibility:public"], -) - -filegroup( - name = "rustlib", - srcs = select({ - ":darwin": glob([ - "rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/*.rlib", - "rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/*.dylib", - "rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/*.a", - "rustc/lib/rustlib/x86_64-apple-darwin/lib/*.rlib", - "rustc/lib/rustlib/x86_64-apple-darwin/lib/*.dylib", - "rustc/lib/rustlib/x86_64-apple-darwin/lib/*.a", - ]), - ":k8": glob([ - "rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.rlib", - "rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.so", - "rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.a", - "rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.rlib", - "rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.so", - "rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.a", - ]), - }), - visibility = ["//visibility:public"], -) -""" - -def rust_repositories(): - """Adds the external dependencies needed for the Rust rules.""" - native.new_http_archive( - name = "rust_linux_x86_64", - url = "http://bazel-mirror.storage.googleapis.com/static.rust-lang.org/dist/rust-1.15.1-x86_64-unknown-linux-gnu.tar.gz", - strip_prefix = "rust-1.15.1-x86_64-unknown-linux-gnu", - sha256 = "b1e7c818a3cc8b010932f0efc1cf0ede7471958310f808d543b6e32d2ec748e7", - build_file_content = RUST_BUILD_FILE, - ) - - native.new_http_archive( - name = "rust_darwin_x86_64", - url = "http://bazel-mirror.storage.googleapis.com/static.rust-lang.org/dist/rust-1.15.1-x86_64-apple-darwin.tar.gz", - strip_prefix = "rust-1.15.1-x86_64-apple-darwin", - sha256 = "38606e464b31a778ffa7d25d490a9ac53b472102bad8445b52e125f63726ac64", - build_file_content = RUST_BUILD_FILE, - )