Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
[fix] CARGO_BAZEL_REPIN flag is used only during sync (#513)
Browse files Browse the repository at this point in the history
If we run it always on build, Bazel will spend additional 30s on any build even if the modules do not contain any Rust at all.

I moved it to BazelBspAspectsManager.
  • Loading branch information
tgodzik committed Jan 25, 2024
1 parent 8230406 commit cac0b01
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ open class BazelRunnerBuilder internal constructor(
return this
}

fun withEnvironment(environmentVariable: Pair<String, String>): BazelRunnerBuilder {
environmentVariables.putAll(listOf(environmentVariable))
fun withEnvironment(environment: List<Pair<String, String>>): BazelRunnerBuilder {
environmentVariables.putAll(environment)
return this
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@ class BazelBspAspectsManager(
buildManualTests(),
curses(false)
),
null
null,
// Setting `CARGO_BAZEL_REPIN=1` updates `cargo_lockfile`
// (`Cargo.lock` file) based on dependencies specified in `manifest`
// (`Cargo.toml` file) and syncs `lockfile` (`Cargo.bazel.lock` file) with `cargo_lockfile`.
// Ensures that both Bazel and Cargo are using the same versions of dependencies.
// Mentioned `cargo_lockfile`, `lockfile` and `manifest` are defined in
// `crates_repository` from `rules_rust`,
// see: https://bazelbuild.github.io/rules_rust/crate_universe.html#crates_repository.
// In our server used only with `bazel build` command.
listOf(Pair("CARGO_BAZEL_REPIN", "1"))
).let {
BazelBspAspectsManagerResult(it.bepOutput, it.processResult.isNotSuccess)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ class BazelBspCompilationManager(
fun buildTargetsWithBep(
cancelChecker: CancelChecker, targetSpecs: TargetsSpec, originId: String,
): BepBuildResult {
return buildTargetsWithBep(cancelChecker, targetSpecs, emptyList(), originId)
return buildTargetsWithBep(cancelChecker, targetSpecs, emptyList(), originId, emptyList())
}

fun buildTargetsWithBep(
cancelChecker: CancelChecker,
targetSpecs: TargetsSpec,
extraFlags: List<String>,
originId: String?,
environment: List<Pair<String, String>>
): BepBuildResult {
val bepServer = BepServer.newBepServer(client, workspaceRoot, hasAnyProblems, Optional.ofNullable(originId))
val bepReader = BepReader(bepServer)
Expand All @@ -36,15 +37,7 @@ class BazelBspCompilationManager(
.build()
.withFlags(extraFlags)
.withTargets(targetSpecs)
// Setting `CARGO_BAZEL_REPIN=1` updates `cargo_lockfile`
// (`Cargo.lock` file) based on dependencies specified in `manifest`
// (`Cargo.toml` file) and syncs `lockfile` (`Cargo.bazel.lock` file) with `cargo_lockfile`.
// Ensures that both Bazel and Cargo are using the same versions of dependencies.
// Mentioned `cargo_lockfile`, `lockfile` and `manifest` are defined in
// `crates_repository` from `rules_rust`,
// see: https://bazelbuild.github.io/rules_rust/crate_universe.html#crates_repository.
// In our server used only with `bazel build` command.
.withEnvironment(Pair("CARGO_BAZEL_REPIN", "1"))
.withEnvironment(environment)
.executeBazelBesCommand(originId, bepReader.eventFile.toPath().toAbsolutePath())
.waitAndGetResult(cancelChecker, true)
bepReader.finishBuild()
Expand Down

0 comments on commit cac0b01

Please sign in to comment.