Skip to content

Commit 6c0cd08

Browse files
committed
Minimum edits to not use the worker for the worker but use the worker for other things.
1 parent ba40f07 commit 6c0cd08

File tree

9 files changed

+83
-44
lines changed

9 files changed

+83
-44
lines changed

proto/raze/remote/byteorder-1.3.4.BUILD

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ licenses([
1717

1818
load(
1919
"@io_bazel_rules_rust//rust:rust.bzl",
20-
"rust_library",
20+
"rust_no_worker_library",
2121
"rust_binary",
2222
"rust_test",
2323
)
@@ -26,7 +26,7 @@ load(
2626
# Unsupported target "bench" with type "bench" omitted
2727
# Unsupported target "build-script-build" with type "custom-build" omitted
2828

29-
rust_library(
29+
rust_no_worker_library(
3030
name = "byteorder",
3131
crate_root = "src/lib.rs",
3232
crate_type = "lib",

proto/raze/remote/bytes-0.4.12.BUILD

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ licenses([
1717

1818
load(
1919
"@io_bazel_rules_rust//rust:rust.bzl",
20-
"rust_library",
20+
"rust_no_worker_library",
2121
"rust_binary",
2222
"rust_test",
2323
)
2424

2525

2626
# Unsupported target "bytes" with type "bench" omitted
2727

28-
rust_library(
28+
rust_no_worker_library(
2929
name = "bytes",
3030
crate_root = "src/lib.rs",
3131
crate_type = "lib",

proto/raze/remote/iovec-0.1.4.BUILD

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ licenses([
1717

1818
load(
1919
"@io_bazel_rules_rust//rust:rust.bzl",
20-
"rust_library",
20+
"rust_no_worker_library",
2121
"rust_binary",
2222
"rust_test",
2323
)
2424

2525

2626

27-
rust_library(
27+
rust_no_worker_library(
2828
name = "iovec",
2929
crate_root = "src/lib.rs",
3030
crate_type = "lib",

proto/raze/remote/libc-0.2.69.BUILD

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ licenses([
1717

1818
load(
1919
"@io_bazel_rules_rust//rust:rust.bzl",
20-
"rust_library",
20+
"rust_no_worker_library",
2121
"rust_binary",
2222
"rust_test",
2323
)
@@ -26,7 +26,7 @@ load(
2626
# Unsupported target "build-script-build" with type "custom-build" omitted
2727
# Unsupported target "const_fn" with type "test" omitted
2828

29-
rust_library(
29+
rust_no_worker_library(
3030
name = "libc",
3131
crate_root = "src/lib.rs",
3232
crate_type = "lib",

proto/raze/remote/protobuf-2.8.2.BUILD

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ licenses([
1717

1818
load(
1919
"@io_bazel_rules_rust//rust:rust.bzl",
20-
"rust_library",
20+
"rust_no_worker_library",
2121
"rust_binary",
2222
"rust_test",
2323
)
@@ -27,7 +27,7 @@ load(
2727
# Unsupported target "coded_input_stream" with type "bench" omitted
2828
# Unsupported target "coded_output_stream" with type "bench" omitted
2929

30-
rust_library(
30+
rust_no_worker_library(
3131
name = "protobuf",
3232
crate_root = "src/lib.rs",
3333
crate_type = "lib",

rust/private/rust.bzl

+20-6
Original file line numberDiff line numberDiff line change
@@ -364,17 +364,15 @@ _rust_common_attrs = {
364364
],
365365
),
366366
"_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"),
367+
"_use_worker": attr.bool(default = False),
367368
"_process_wrapper": attr.label(
368369
default = "@io_bazel_rules_rust//util/process_wrapper",
369370
executable = True,
370371
allow_single_file = True,
371372
cfg = "exec",
372373
),
373-
"_process_wrapper_worker": attr.label(
374-
default = "@rustc_worker//file",
375-
# Actually we may want the persistent worker to be built by the rust rules themselves, but right now we are just going to use a binary.
374+
"process_wrapper_worker": attr.label(
376375
executable = True,
377-
allow_single_file = True,
378376
cfg = "exec",
379377
),
380378
}
@@ -403,7 +401,7 @@ _rust_test_attrs = {
403401
),
404402
}
405403

406-
rust_library = rule(
404+
rust_no_worker_library = rule(
407405
_rust_library_impl,
408406
attrs = dict(_rust_common_attrs.items() +
409407
_rust_library_attrs.items()),
@@ -479,6 +477,14 @@ INFO: Elapsed time: 1.245s, Critical Path: 1.01s
479477
""",
480478
)
481479

480+
def rust_library(**kwargs):
481+
# Discard
482+
_ = kwargs.pop("process_wrapper_worker", None)
483+
rust_no_worker_library(
484+
process_wrapper_worker = Label("//worker:rustc-worker"),
485+
**kwargs,
486+
)
487+
482488
_rust_binary_attrs = {
483489
"linker_script": attr.label(
484490
doc = _tidy("""
@@ -493,7 +499,7 @@ _rust_binary_attrs = {
493499
"out_binary": attr.bool(),
494500
}
495501

496-
rust_binary = rule(
502+
rust_no_worker_binary = rule(
497503
_rust_binary_impl,
498504
attrs = dict(_rust_common_attrs.items() + _rust_binary_attrs.items()),
499505
executable = True,
@@ -589,6 +595,14 @@ Hello world
589595
""",
590596
)
591597

598+
def rust_binary(**kwargs):
599+
# Discard
600+
_ = kwargs.pop("process_wrapper_worker", None)
601+
rust_no_worker_binary(
602+
process_wrapper_worker = Label("//worker:rustc-worker"),
603+
**kwargs,
604+
)
605+
592606
rust_test = rule(
593607
_rust_test_impl,
594608
attrs = dict(_rust_common_attrs.items() +

rust/private/rustc.bzl

+21-6
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,12 @@ def construct_arguments(
313313

314314
env = _get_rustc_env(ctx, toolchain)
315315

316+
using_worker = ctx.executable.process_wrapper_worker != None
316317
# Wrapper args first
317318
args = ctx.actions.args()
318-
args.set_param_file_format("multiline")
319-
args.use_param_file("@%s", use_always=True)
319+
if using_worker:
320+
args.set_param_file_format("multiline")
321+
args.use_param_file("@%s", use_always=True)
320322

321323
if build_env_file != None:
322324
args.add("--env-file", build_env_file)
@@ -485,15 +487,28 @@ def rustc_compile_action(
485487
else:
486488
formatted_version = ""
487489

490+
worker_exe = ctx.executable.process_wrapper_worker
491+
492+
if worker_exe != None:
493+
run_exe = worker_exe
494+
execution_requirements = { "supports-workers": "1" }
495+
run_args = [ctx.executable._process_wrapper.path, toolchain.rustc.path, ctx.var["COMPILATION_MODE"], args]
496+
tools = [ctx.executable._process_wrapper]
497+
else:
498+
run_exe = ctx.executable._process_wrapper
499+
run_args = [args]
500+
execution_requirements = {}
501+
tools = []
502+
488503
ctx.actions.run(
489-
executable = ctx.executable._process_wrapper_worker,
504+
executable = run_exe,
490505
inputs = compile_inputs,
491506
outputs = [crate_info.output],
492-
tools = [ctx.executable._process_wrapper],
507+
tools = tools,
493508
env = env,
494-
arguments = [ctx.executable._process_wrapper.path, toolchain.rustc.path, ctx.var["COMPILATION_MODE"], args],
509+
arguments = run_args,
495510
mnemonic = "Rustc",
496-
execution_requirements = { "supports-workers": "1" },
511+
execution_requirements = execution_requirements,
497512
progress_message = "Compiling Rust {} {}{} ({} files)".format(
498513
crate_info.type,
499514
ctx.label.name,

rust/rust.bzl

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ load(
1919
_rust_library = "rust_library",
2020
_rust_test = "rust_test",
2121
_rust_test_binary = "rust_test_binary",
22+
_rust_no_worker_library = "rust_no_worker_library",
23+
_rust_no_worker_binary = "rust_no_worker_binary",
2224
)
2325
load(
2426
"@io_bazel_rules_rust//rust:private/rustdoc.bzl",
@@ -60,3 +62,6 @@ rust_clippy_aspect = _rust_clippy_aspect
6062

6163
rust_clippy = _rust_clippy
6264
""" See @io_bazel_rules_rust//rust:private/clippy.bzl for a complete description. """
65+
66+
rust_no_worker_library = _rust_no_worker_library
67+
rust_no_worker_binary = _rust_no_worker_binary

worker/BUILD

+27-22
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,47 @@
11
# load("@rules_proto//proto:defs.bzl", "proto_library")
22
# load("@io_bazel_rules_rust//proto:proto.bzl", "rust_proto_library")
33
# load("@io_bazel_rules_rust//proto:toolchain.bzl", "PROTO_COMPILE_DEPS", "rust_proto_toolchain")
4-
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_library", "rust_binary")
4+
load("//rust:rust.bzl", "rust_no_worker_library", "rust_no_worker_binary")
55

6-
rust_library(
6+
rust_no_worker_library(
77
name = "rustc_worker",
8+
edition = "2018",
89
srcs = [
910
"src/lib.rs",
1011
"src/worker_protocol.rs",
1112
],
1213
deps = [
13-
"@io_bazel_rules_rust//proto/raze:protobuf",
14+
"//proto/raze:protobuf",
1415
],
1516
)
1617

17-
rust_binary(
18+
rust_no_worker_binary(
1819
name = "rustc-worker",
20+
edition = "2018",
1921
srcs = ["src/main.rs"],
2022
deps = [
2123
":rustc_worker",
22-
"@io_bazel_rules_rust//proto/raze:protobuf",
24+
"//proto/raze:protobuf",
2325
],
26+
visibility = ["//visibility:public"],
2427
)
2528

26-
# rust_proto_toolchain(name = "default-proto-toolchain-impl")
27-
#
28-
# toolchain(
29-
# name = "default-proto-toolchain",
30-
# toolchain = ":default-proto-toolchain-impl",
31-
# toolchain_type = "@io_bazel_rules_rust//proto:toolchain",
32-
# )
33-
#
34-
# proto_library(
35-
# name = "worker_protocol_proto",
36-
# srcs = ["src/worker_protocol.proto"],
37-
# )
38-
#
39-
# rust_proto_library(
40-
# name = "worker_protocol",
41-
# deps = [":worker_protocol_proto"],
42-
# )
29+
# The rust_* rules are required to build the worker
30+
# They shouldn't _use_ the worker when building the worker OR any of its dependencies
31+
# Ideally we want some transitive switch applier (like a custom transition?) that will enforce this across the entire dependency graph.
32+
# What does that look like?
33+
# Can we use transitions? Is that supported in Bazel 0.27?
34+
# Alternatively can we use a config-setting?
35+
# In that case, how do we enforce the config setting when building the worker?
36+
# Alternatively, we would need to make raze emit customizable rule names, then have it run in the custom mode to generate the BUILD files for the protobuf bits.
37+
38+
# On the C++ side, the protobuf repo does provide a "protobuf" and "protobuf-lite" target to link the worker against, that will allow us to use protobufs easily.
39+
40+
# we would need to write code to repeatedly execute the child process and capture stdout.
41+
# similarly, we would need to write code to parse args (actually that exists).
42+
# we would need some equivalent of canonicalize (realpath on unix, GetFinalPathNameByHandle on windows),
43+
# response file handling and reading
44+
# hashing the inputs
45+
# mkdir_all
46+
47+
# otherwise edit the raze files...

0 commit comments

Comments
 (0)