Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move rust repository setup to a new Skylark file. #45

Merged
merged 2 commits into from
Apr 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions rust/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
}),
)
83 changes: 83 additions & 0 deletions rust/repositories.bzl
Original file line number Diff line number Diff line change
@@ -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,
)
104 changes: 12 additions & 92 deletions rust/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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",
] +
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 +
Expand All @@ -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,
Expand Down Expand Up @@ -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 +
Expand All @@ -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)
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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,
)