Skip to content

Commit 442276a

Browse files
katredavidzchen
authored andcommitted
Move rust repository setup to a new Skylark file. (#45)
* Move rust repository setup to a new Skylark file. * Fixed rustlib references to consistently be rust_lib.
1 parent 0f4e196 commit 442276a

File tree

4 files changed

+99
-97
lines changed

4 files changed

+99
-97
lines changed

WORKSPACE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ local_repository(
1111
)
1212

1313
# TODO: Move this to examples/WORKSPACE when recursive repositories are enabled.
14-
load("//rust:rust.bzl", "rust_repositories")
15-
14+
load("//rust:repositories.bzl", "rust_repositories")
1615
rust_repositories()
1716

1817
new_git_repository(

rust/BUILD

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ filegroup(
3737
)
3838

3939
filegroup(
40-
name = "rustlib",
40+
name = "rust_lib",
4141
srcs = select({
42-
":darwin": ["@rust_darwin_x86_64//:rustlib"],
43-
":k8": ["@rust_linux_x86_64//:rustlib"],
42+
":darwin": ["@rust_darwin_x86_64//:rust_lib"],
43+
":k8": ["@rust_linux_x86_64//:rust_lib"],
4444
}),
4545
)

rust/repositories.bzl

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
RUST_DARWIN_BUILD_FILE = """
2+
filegroup(
3+
name = "rustc",
4+
srcs = ["rustc/bin/rustc"],
5+
visibility = ["//visibility:public"],
6+
)
7+
8+
filegroup(
9+
name = "rustc_lib",
10+
srcs = glob(["rustc/lib/*.dylib"]),
11+
visibility = ["//visibility:public"],
12+
)
13+
14+
filegroup(
15+
name = "rustdoc",
16+
srcs = ["rustc/bin/rustdoc"],
17+
visibility = ["//visibility:public"],
18+
)
19+
20+
filegroup(
21+
name = "rust_lib",
22+
srcs = glob([
23+
"rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/*.rlib",
24+
"rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/*.dylib",
25+
"rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/*.a",
26+
"rustc/lib/rustlib/x86_64-apple-darwin/lib/*.rlib",
27+
"rustc/lib/rustlib/x86_64-apple-darwin/lib/*.dylib",
28+
"rustc/lib/rustlib/x86_64-apple-darwin/lib/*.a",
29+
]),
30+
visibility = ["//visibility:public"],
31+
)
32+
"""
33+
34+
RUST_LINUX_BUILD_FILE = """
35+
filegroup(
36+
name = "rustc",
37+
srcs = ["rustc/bin/rustc"],
38+
visibility = ["//visibility:public"],
39+
)
40+
41+
filegroup(
42+
name = "rustc_lib",
43+
srcs = glob(["rustc/lib/*.so"]),
44+
visibility = ["//visibility:public"],
45+
)
46+
47+
filegroup(
48+
name = "rustdoc",
49+
srcs = ["rustc/bin/rustdoc"],
50+
visibility = ["//visibility:public"],
51+
)
52+
53+
filegroup(
54+
name = "rust_lib",
55+
srcs = glob([
56+
"rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.rlib",
57+
"rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.so",
58+
"rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.a",
59+
"rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.rlib",
60+
"rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.so",
61+
"rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.a",
62+
]),
63+
visibility = ["//visibility:public"],
64+
)
65+
"""
66+
67+
# Eventually with better toolchain hosting options we could load only one of these, not both.
68+
def rust_repositories():
69+
native.new_http_archive(
70+
name = "rust_linux_x86_64",
71+
url = "http://bazel-mirror.storage.googleapis.com/static.rust-lang.org/dist/rust-1.15.1-x86_64-unknown-linux-gnu.tar.gz",
72+
strip_prefix = "rust-1.15.1-x86_64-unknown-linux-gnu",
73+
sha256 = "b1e7c818a3cc8b010932f0efc1cf0ede7471958310f808d543b6e32d2ec748e7",
74+
build_file_content = RUST_LINUX_BUILD_FILE,
75+
)
76+
77+
native.new_http_archive(
78+
name = "rust_darwin_x86_64",
79+
url = "http://bazel-mirror.storage.googleapis.com/static.rust-lang.org/dist/rust-1.15.1-x86_64-apple-darwin.tar.gz",
80+
strip_prefix = "rust-1.15.1-x86_64-apple-darwin",
81+
sha256 = "38606e464b31a778ffa7d25d490a9ac53b472102bad8445b52e125f63726ac64",
82+
build_file_content = RUST_DARWIN_BUILD_FILE,
83+
)

rust/rust.bzl

Lines changed: 12 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ def _rust_toolchain(ctx):
211211
rustc_path = ctx.file._rustc.path,
212212
rustc_lib_path = ctx.files._rustc_lib[0].dirname,
213213
rustc_lib_short_path = _get_dirname(ctx.files._rustc_lib[0].short_path),
214-
rustlib_path = ctx.files._rustlib[0].dirname,
215-
rustlib_short_path = _get_dirname(ctx.files._rustlib[0].short_path),
214+
rust_lib_path = ctx.files._rust_lib[0].dirname,
215+
rust_lib_short_path = _get_dirname(ctx.files._rust_lib[0].short_path),
216216
rustdoc_path = ctx.file._rustdoc.path,
217217
rustdoc_short_path = ctx.file._rustdoc.short_path)
218218

@@ -266,7 +266,7 @@ def _build_rustc_command(ctx, crate_name, crate_type, src, output_dir,
266266
"--codegen ar=%s" % ar,
267267
"--codegen linker=%s" % cc,
268268
"--codegen link-args='%s'" % ' '.join(cpp_fragment.link_options),
269-
"-L all=%s" % toolchain.rustlib_path,
269+
"-L all=%s" % toolchain.rust_lib_path,
270270
"--out-dir %s" % output_dir,
271271
"--emit=dep-info,link",
272272
] +
@@ -336,7 +336,7 @@ def _rust_library_impl(ctx):
336336
depinfo.transitive_libs +
337337
[ctx.file._rustc] +
338338
ctx.files._rustc_lib +
339-
ctx.files._rustlib +
339+
ctx.files._rust_lib +
340340
ctx.files._crosstool)
341341

342342
ctx.action(
@@ -389,7 +389,7 @@ def _rust_binary_impl(ctx):
389389
depinfo.transitive_libs +
390390
[ctx.file._rustc] +
391391
ctx.files._rustc_lib +
392-
ctx.files._rustlib +
392+
ctx.files._rust_lib +
393393
ctx.files._crosstool)
394394

395395
ctx.action(
@@ -451,7 +451,7 @@ def _rust_test_common(ctx, test_binary):
451451
depinfo.transitive_libs +
452452
[ctx.file._rustc] +
453453
ctx.files._rustc_lib +
454-
ctx.files._rustlib +
454+
ctx.files._rust_lib +
455455
ctx.files._crosstool)
456456

457457
ctx.action(
@@ -538,7 +538,7 @@ def _rust_doc_impl(ctx):
538538
toolchain.rustdoc_path,
539539
lib_rs.path,
540540
"--crate-name %s" % target.name,
541-
"-L all=%s" % toolchain.rustlib_path,
541+
"-L all=%s" % toolchain.rust_lib_path,
542542
"-o %s" % docs_dir,
543543
] +
544544
doc_flags +
@@ -560,7 +560,7 @@ def _rust_doc_impl(ctx):
560560
depinfo.libs +
561561
[ctx.file._rustdoc] +
562562
ctx.files._rustc_lib +
563-
ctx.files._rustlib)
563+
ctx.files._rust_lib)
564564

565565
ctx.action(
566566
inputs = rustdoc_inputs,
@@ -604,7 +604,7 @@ def _rust_doc_test_impl(ctx):
604604
"LD_LIBRARY_PATH=%s" % toolchain.rustc_lib_short_path,
605605
"DYLD_LIBRARY_PATH=%s" % toolchain.rustc_lib_short_path,
606606
toolchain.rustdoc_short_path,
607-
"-L all=%s" % toolchain.rustlib_short_path,
607+
"-L all=%s" % toolchain.rust_lib_short_path,
608608
lib_rs.path,
609609
] +
610610
depinfo.search_flags +
@@ -619,7 +619,7 @@ def _rust_doc_test_impl(ctx):
619619
depinfo.transitive_libs +
620620
[ctx.file._rustdoc] +
621621
ctx.files._rustc_lib +
622-
ctx.files._rustlib)
622+
ctx.files._rust_lib)
623623

624624
runfiles = ctx.runfiles(files = doc_test_inputs, collect_data = True)
625625
return struct(runfiles = runfiles)
@@ -649,8 +649,8 @@ _rust_toolchain_attrs = {
649649
"_rustc_lib": attr.label(
650650
default = Label("//rust:rustc_lib"),
651651
),
652-
"_rustlib": attr.label(
653-
default = Label("//rust:rustlib"),
652+
"_rust_lib": attr.label(
653+
default = Label("//rust:rust_lib"),
654654
),
655655
"_rustdoc": attr.label(
656656
default = Label("//rust:rustdoc"),
@@ -1303,83 +1303,3 @@ Example:
13031303
Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation
13041304
tests for the `hello_lib` library crate.
13051305
"""
1306-
1307-
RUST_BUILD_FILE = """
1308-
config_setting(
1309-
name = "darwin",
1310-
values = {"host_cpu": "darwin"},
1311-
)
1312-
1313-
config_setting(
1314-
name = "k8",
1315-
values = {"host_cpu": "k8"},
1316-
)
1317-
1318-
filegroup(
1319-
name = "rustc",
1320-
srcs = select({
1321-
":darwin": ["rustc/bin/rustc"],
1322-
":k8": ["rustc/bin/rustc"],
1323-
}),
1324-
visibility = ["//visibility:public"],
1325-
)
1326-
1327-
filegroup(
1328-
name = "rustc_lib",
1329-
srcs = select({
1330-
":darwin": glob(["rustc/lib/*.dylib"]),
1331-
":k8": glob(["rustc/lib/*.so"]),
1332-
}),
1333-
visibility = ["//visibility:public"],
1334-
)
1335-
1336-
filegroup(
1337-
name = "rustdoc",
1338-
srcs = select({
1339-
":darwin": ["rustc/bin/rustdoc"],
1340-
":k8": ["rustc/bin/rustdoc"],
1341-
}),
1342-
visibility = ["//visibility:public"],
1343-
)
1344-
1345-
filegroup(
1346-
name = "rustlib",
1347-
srcs = select({
1348-
":darwin": glob([
1349-
"rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/*.rlib",
1350-
"rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/*.dylib",
1351-
"rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/*.a",
1352-
"rustc/lib/rustlib/x86_64-apple-darwin/lib/*.rlib",
1353-
"rustc/lib/rustlib/x86_64-apple-darwin/lib/*.dylib",
1354-
"rustc/lib/rustlib/x86_64-apple-darwin/lib/*.a",
1355-
]),
1356-
":k8": glob([
1357-
"rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.rlib",
1358-
"rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.so",
1359-
"rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.a",
1360-
"rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.rlib",
1361-
"rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.so",
1362-
"rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.a",
1363-
]),
1364-
}),
1365-
visibility = ["//visibility:public"],
1366-
)
1367-
"""
1368-
1369-
def rust_repositories():
1370-
"""Adds the external dependencies needed for the Rust rules."""
1371-
native.new_http_archive(
1372-
name = "rust_linux_x86_64",
1373-
url = "http://bazel-mirror.storage.googleapis.com/static.rust-lang.org/dist/rust-1.15.1-x86_64-unknown-linux-gnu.tar.gz",
1374-
strip_prefix = "rust-1.15.1-x86_64-unknown-linux-gnu",
1375-
sha256 = "b1e7c818a3cc8b010932f0efc1cf0ede7471958310f808d543b6e32d2ec748e7",
1376-
build_file_content = RUST_BUILD_FILE,
1377-
)
1378-
1379-
native.new_http_archive(
1380-
name = "rust_darwin_x86_64",
1381-
url = "http://bazel-mirror.storage.googleapis.com/static.rust-lang.org/dist/rust-1.15.1-x86_64-apple-darwin.tar.gz",
1382-
strip_prefix = "rust-1.15.1-x86_64-apple-darwin",
1383-
sha256 = "38606e464b31a778ffa7d25d490a9ac53b472102bad8445b52e125f63726ac64",
1384-
build_file_content = RUST_BUILD_FILE,
1385-
)

0 commit comments

Comments
 (0)