Skip to content

Commit

Permalink
Merge branch 'main' into revert
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre authored Feb 5, 2025
2 parents 27198f9 + 53c3469 commit bfdf76f
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 340 deletions.
12 changes: 5 additions & 7 deletions crate_universe/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ mod splice;
mod vendor;

use clap::Parser;
use tracing::{Level, Subscriber};
use tracing::Subscriber;
use tracing_subscriber::fmt::format::{Format, Full};
use tracing_subscriber::fmt::time::SystemTime;
use tracing_subscriber::fmt::{FormatEvent, FormatFields};
use tracing_subscriber::registry::LookupSpan;
use tracing_subscriber::FmtSubscriber;

pub use tracing::Level as LogLevel;

pub use self::generate::GenerateOptions;
pub use self::query::QueryOptions;
pub use self::render::RenderOptions;
Expand Down Expand Up @@ -92,21 +94,17 @@ impl LoggingFormatEvent {
}

/// Initialize logging for one of the cli options.
pub fn init_logging(name: &str, verbose: bool) {
pub fn init_logging(name: &str, level: LogLevel) {
if !EXPECTED_LOGGER_NAMES.contains(&name) {
panic!(
"Unexpected logger name {}, use of one of {:?}",
name, EXPECTED_LOGGER_NAMES
);
}

// a builder for `FmtSubscriber`.
let subscriber = FmtSubscriber::builder()
// all spans/events with a level higher than TRACE (e.g, debug, info, warn, etc.)
// will be written to stdout.
.with_max_level(if verbose { Level::DEBUG } else { Level::INFO })
.with_max_level(level)
.event_format(LoggingFormatEvent::new(name))
// completes the builder.
.finish();

tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
Expand Down
21 changes: 15 additions & 6 deletions crate_universe/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,36 @@ fn main() -> cli::Result<()> {
// Parse arguments
let opt = cli::parse_args();

let verbose_logging = std::env::var("CARGO_BAZEL_DEBUG").is_ok();
let level = match std::env::var("CARGO_BAZEL_DEBUG") {
Ok(var) => {
if var == "TRACE" {
crate::cli::LogLevel::TRACE
} else {
crate::cli::LogLevel::DEBUG
}
}
Err(_) => crate::cli::LogLevel::INFO,
};

match opt {
cli::Options::Generate(opt) => {
cli::init_logging("Generate", verbose_logging);
cli::init_logging("Generate", level);
cli::generate(opt)
}
cli::Options::Splice(opt) => {
cli::init_logging("Splice", verbose_logging);
cli::init_logging("Splice", level);
cli::splice(opt)
}
cli::Options::Query(opt) => {
cli::init_logging("Query", verbose_logging);
cli::init_logging("Query", level);
cli::query(opt)
}
cli::Options::Vendor(opt) => {
cli::init_logging("Vendor", verbose_logging);
cli::init_logging("Vendor", level);
cli::vendor(opt)
}
cli::Options::Render(opt) => {
cli::init_logging("Render", verbose_logging);
cli::init_logging("Render", level);
cli::render(opt)
}
}
Expand Down
22 changes: 12 additions & 10 deletions crate_universe/src/metadata/cargo_tree_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use anyhow::{anyhow, bail, Context, Result};
use camino::Utf8Path;
use semver::Version;
use serde::{Deserialize, Serialize};
use tracing::debug;
use tracing::{debug, trace};
use url::Url;

use crate::config::CrateId;
Expand Down Expand Up @@ -137,6 +137,12 @@ impl TreeResolver {
// number of processes (which can be +400 and hit operating system limitations).
let mut target_triple_to_child = BTreeMap::<String, Child>::new();

debug!(
"Spawning `cargo tree` processes for host `{}`: {}",
host_triple,
cargo_target_triples.keys().len(),
);

for target_triple in cargo_target_triples.keys() {
// We use `cargo tree` here because `cargo metadata` doesn't report
// back target-specific features (enabled with `resolver = "2"`).
Expand Down Expand Up @@ -178,12 +184,6 @@ impl TreeResolver {
target_triple_to_child.insert(target_triple.clone(), child);
}

debug!(
"Spawned `cargo tree` processes for host `{}`: {}",
host_triple,
target_triple_to_child.len(),
);

for (target_triple, child) in target_triple_to_child.into_iter() {
let output = child.wait_with_output().with_context(|| {
format!(
Expand All @@ -194,11 +194,13 @@ impl TreeResolver {
)
})?;
if !output.status.success() {
eprintln!("{}", String::from_utf8_lossy(&output.stdout));
eprintln!("{}", String::from_utf8_lossy(&output.stderr));
tracing::error!("{}", String::from_utf8_lossy(&output.stdout));
tracing::error!("{}", String::from_utf8_lossy(&output.stderr));
bail!(format!("Failed to run cargo tree: {}", output.status))
}

tracing::trace!("`cargo tree --target={}` completed.", target_triple);

// Replicate outputs for any de-duplicated platforms
for host_plat in cargo_host_triples[host_triple].iter() {
for target_plat in cargo_target_triples[&target_triple].iter() {
Expand Down Expand Up @@ -348,7 +350,7 @@ impl TreeResolver {

for (host_triple, target_streams) in deps_tree_streams.into_iter() {
for (target_triple, stdout) in target_streams.into_iter() {
debug!(
trace!(
"Parsing (host={}) `cargo tree --target {}` output:\n```\n{}\n```",
host_triple,
target_triple,
Expand Down
6 changes: 5 additions & 1 deletion examples/nix_cross_compiling/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ local_path_override(

bazel_dep(
name = "rules_nixpkgs_core",
version = "0.12.0",
version = "0.13.0",
)
bazel_dep(
name = "bazel_skylib",
Expand All @@ -26,6 +26,10 @@ bazel_dep(
name = "rules_cc",
version = "0.0.17",
)
bazel_dep(
name = "platforms",
version = "0.0.11",
)

internal = use_extension("//bazel:nix_repositories.bzl", "internal_ext")
use_repo(
Expand Down
59 changes: 0 additions & 59 deletions extensions/bindgen/WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -1,60 +1 @@
workspace(name = "rules_rust_bindgen")

# Users of `rules_rust` will commonly be unable to load it
# using a `local_repository`. Instead, to setup the rules,
# please see https://bazelbuild.github.io/rules_rust/#setup
local_repository(
name = "rules_rust",
path = "../..",
)

load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")

rules_rust_dependencies()

rust_register_toolchains()

load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies")

crate_universe_dependencies(bootstrap = True)

load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies")

rust_analyzer_dependencies()

load("//:repositories.bzl", "rust_bindgen_dependencies", "rust_bindgen_register_toolchains")

rust_bindgen_dependencies()

rust_bindgen_register_toolchains()

load("//:transitive_repositories.bzl", "rust_bindgen_transitive_dependencies")

rust_bindgen_transitive_dependencies()

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

# --- end stardoc

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazel_ci_rules",
sha256 = "eca21884e6f66a88c358e580fd67a6b148d30ab57b1680f62a96c00f9bc6a07e",
strip_prefix = "bazelci_rules-1.0.0",
url = "https://github.com/bazelbuild/continuous-integration/releases/download/rules-1.0.0/bazelci_rules-1.0.0.tar.gz",
)

# To run with RBE on Bazel CI, uncomment the following lines.
#
# load("@bazel_ci_rules//:rbe_repo.bzl", "rbe_preconfig")
# rbe_preconfig(name = "buildkite_config", toolchain = "ubuntu2004-bazel-java11")

http_archive(
name = "rules_testing",
sha256 = "02c62574631876a4e3b02a1820cb51167bb9cdcdea2381b2fa9d9b8b11c407c4",
strip_prefix = "rules_testing-0.6.0",
url = "https://github.com/bazelbuild/rules_testing/releases/download/v0.6.0/rules_testing-v0.6.0.tar.gz",
)
53 changes: 0 additions & 53 deletions extensions/mdbook/WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -1,54 +1 @@
workspace(name = "rules_rust_mdbook")

load("//mdbook:repositories.bzl", "mdbook_register_toolchains", "rules_mdbook_dependencies")

rules_mdbook_dependencies()

mdbook_register_toolchains()

load("//mdbook:repositories_transitive.bzl", "rules_mdbook_transitive_deps")

rules_mdbook_transitive_deps()

# =============================================================================
# Internal dependencies only
# =============================================================================

load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies")

crate_universe_dependencies()

load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies")

rust_analyzer_dependencies()

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "io_bazel_stardoc",
sha256 = "62bd2e60216b7a6fec3ac79341aa201e0956477e7c8f6ccc286f279ad1d96432",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.6.2/stardoc-0.6.2.tar.gz",
"https://github.com/bazelbuild/stardoc/releases/download/0.6.2/stardoc-0.6.2.tar.gz",
],
)

load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")

stardoc_repositories()

load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")

rules_jvm_external_deps()

load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")

rules_jvm_external_setup()

load("@io_bazel_stardoc//:deps.bzl", "stardoc_external_deps")

stardoc_external_deps()

load("@stardoc_maven//:defs.bzl", stardoc_pinned_maven_install = "pinned_maven_install")

stardoc_pinned_maven_install()
75 changes: 0 additions & 75 deletions extensions/prost/WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -1,76 +1 @@
workspace(name = "rules_rust_prost")

# Users of `rules_rust` will commonly be unable to load it
# using a `local_repository`. Instead, to setup the rules,
# please see https://bazelbuild.github.io/rules_rust/#setup
local_repository(
name = "rules_rust",
path = "../..",
)

load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")

rules_rust_dependencies()

rust_register_toolchains()

load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies")

crate_universe_dependencies(bootstrap = True)

load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies")

rust_analyzer_dependencies()

# buildifier: disable=bzl-visibility
load("//private:repositories.bzl", "rust_prost_dependencies", "rust_prost_register_toolchains")

rust_prost_dependencies()

rust_prost_register_toolchains()

load("//:transitive_repositories.bzl", "rust_prost_transitive_repositories")

rust_prost_transitive_repositories()

# Needed by protobuf
load("@rules_python//python:repositories.bzl", "py_repositories")

py_repositories()

# buildifier: disable=bzl-visibility
load("//private/tests:deps.bzl", "prost_test_deps")

prost_test_deps()

# buildifier: disable=bzl-visibility
load("//private/tests:deps_transitive.bzl", "prost_test_transitive_deps")

prost_test_transitive_deps()

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

# --- end stardoc

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazel_ci_rules",
sha256 = "eca21884e6f66a88c358e580fd67a6b148d30ab57b1680f62a96c00f9bc6a07e",
strip_prefix = "bazelci_rules-1.0.0",
url = "https://github.com/bazelbuild/continuous-integration/releases/download/rules-1.0.0/bazelci_rules-1.0.0.tar.gz",
)

# To run with RBE on Bazel CI, uncomment the following lines.
#
# load("@bazel_ci_rules//:rbe_repo.bzl", "rbe_preconfig")
# rbe_preconfig(name = "buildkite_config", toolchain = "ubuntu2004-bazel-java11")

http_archive(
name = "rules_testing",
sha256 = "02c62574631876a4e3b02a1820cb51167bb9cdcdea2381b2fa9d9b8b11c407c4",
strip_prefix = "rules_testing-0.6.0",
url = "https://github.com/bazelbuild/rules_testing/releases/download/v0.6.0/rules_testing-v0.6.0.tar.gz",
)
Loading

0 comments on commit bfdf76f

Please sign in to comment.