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

Split rust_library into smaller rules #591

Closed
7 tasks done
hlopko opened this issue Feb 17, 2021 · 4 comments · Fixed by #1002
Closed
7 tasks done

Split rust_library into smaller rules #591

hlopko opened this issue Feb 17, 2021 · 4 comments · Fixed by #1002
Assignees

Comments

@hlopko
Copy link
Member

hlopko commented Feb 17, 2021

As socialized on https://groups.google.com/g/rules_rust/c/kGMg6haEF44, we're going to split rust_library into smaller rules. This is the tracking issue for the effort.

Steps:

  • Submit defs.bzl with rules in the desired end state
  • Regenerate docs
  • Provide buildozer migration script
  • Migrate all uses of @rules_rust//rust:rust.bzl in the repository to @rules_rust//rust:defs.bzl
  • Update raze and other closely related projects
  • Wait for the community to migrate
  • Remove the deprecated rust.bzl file. Currently planned for 2021-10-26.
@hlopko
Copy link
Member Author

hlopko commented Feb 23, 2021

Migration script I used to migrate rules_rust, kythe, and internal codebase. I apologize for poor engineering:

#!/usr/bin/env rust-script
//! ```cargo
//! [dependencies]
//! duct = "0.13.5"
//! anyhow = "1.0.44"
//! ```

use duct::cmd;
use std::collections::BTreeSet;
fn main() -> anyhow::Result<()> {
    let all_targets = cmd!("buildozer", "print label", "//...:*")
        .read()?
        .lines()
        .map(|l| l.trim().to_owned())
        .collect::<Vec<_>>();
    let all_packages = all_targets
        .iter()
        .map(|lbl| format!("{}:__pkg__", lbl.split(':').next().unwrap()))
        .collect::<BTreeSet<_>>();
    let all_targets_with_crate_type = cmd!("buildozer", "print label crate_type", "//...:*")
        .read()?
        .lines()
        .filter(|l| !l.contains("(missing)"))
        .map(|l| l.split_once(' ').unwrap())
        .map(|(a, b)| (a.to_string(), b.to_string()))
        .collect::<Vec<_>>();

    for (crate_type, rule) in [
        ("staticlib", "rust_static_library"),
        ("cdylib", "rust_shared_library"),
        ("proc-macro", "rust_proc_macro"),
    ] {
        let targets_of_type = all_targets_with_crate_type
            .iter()
            .filter(|(label, ctype)| ctype == crate_type)
            .map(|(label, _)| label)
            .collect::<Vec<_>>();
        cmd(
            "buildozer",
            vec![
                "-k".to_string(),
                format!("new_load @rules_rust//rust:defs.bzl {}", rule),
            ]
            .iter()
            .chain(targets_of_type.iter().cloned()),
        )
        .run()
        .ok();
        cmd(
            "buildozer",
            vec!["-k".to_string(), format!("set kind {}", rule)]
                .iter()
                .chain(targets_of_type),
        )
        .run()
        .ok();
    }
    cmd(
        "buildozer",
        vec!["-k".to_string(), "remove crate_type".to_string()]
            .iter()
            .chain(all_targets_with_crate_type.iter().map(|(label, _)| label)),
    )
    .run()
    .ok();
    println!("########################### Moving package to top");
    cmd(
        "buildozer",
        vec!["-k".to_string(), "fix movePackageToTop".to_string()]
            .into_iter()
            .chain(all_packages.iter().cloned()),
    )
    .run()
    .ok();

    println!("########################### Migrating from rust.bzl to defs.bzl");
    for rule in [
        "rust_library",
        "rust_binary",
        "rustfmt_test",
        "rust_clippy",
        "rust_test",
        "rust_doc",
        "rust_doc_test",
        "rust_analyzer",
    ] {
        cmd(
            "buildozer",
            vec![
                "-k".to_string(),
                format!("replace_load @rules_rust//rust:defs.bzl {}", rule),
            ]
            .into_iter()
            .chain(all_packages.iter().cloned()),
        )
        .run()
        .ok();
    }

    println!("########################### Removing unused loads");
    cmd(
        "buildozer",
        vec!["-k", "fix unusedLoads"]
            .into_iter()
            .chain(all_packages.iter().map(|a| a.as_str())),
    )
    .run()
    .ok();
    Ok(())
}

@hlopko hlopko mentioned this issue May 14, 2021
hlopko added a commit to hlopko/rules_rust that referenced this issue Oct 22, 2021
hlopko added a commit to hlopko/rules_rust that referenced this issue Oct 22, 2021
hlopko added a commit to hlopko/rules_rust that referenced this issue Oct 22, 2021
hlopko added a commit to hlopko/rules_rust that referenced this issue Oct 22, 2021
hlopko added a commit that referenced this issue Oct 23, 2021
hlopko added a commit that referenced this issue Oct 23, 2021
hlopko added a commit to hlopko/rules_rust that referenced this issue Oct 25, 2021
hlopko added a commit to hlopko/kythe that referenced this issue Oct 25, 2021
hlopko added a commit to hlopko/kythe that referenced this issue Oct 25, 2021
hlopko added a commit to hlopko/kythe that referenced this issue Oct 25, 2021
@hlopko
Copy link
Member Author

hlopko commented Oct 25, 2021

FYI: Cargo-raze v0.13 is released and it produces BUILD files that are compatible with this breaking change.

@hlopko
Copy link
Member Author

hlopko commented Oct 25, 2021

Status update: I believe this change was in the baking for long enough. I plan to flip the flag in the next couple of days, unless I'm told to wait :)

hlopko added a commit that referenced this issue Oct 25, 2021
shahms pushed a commit to kythe/kythe that referenced this issue Oct 25, 2021
shahms added a commit to kythe/kythe that referenced this issue Oct 25, 2021
hlopko added a commit to hlopko/cxx that referenced this issue Oct 26, 2021
dtolnay added a commit to dtolnay/cxx that referenced this issue Oct 27, 2021
hlopko added a commit to hlopko/tensorboard that referenced this issue Oct 28, 2021
stephanwlee pushed a commit to tensorflow/tensorboard that referenced this issue Oct 28, 2021
dfreese pushed a commit to dfreese/rules_docker that referenced this issue Nov 5, 2021
Rules rust has made some changes upstream that remove the rust.bzl file.
It had previously been left in there for compatibility purposes.  This
has been ongoing since February 16th.  See this issue for additional
context: bazelbuild/rules_rust#591.
dfreese pushed a commit to dfreese/rules_docker that referenced this issue Nov 8, 2021
Rules rust has made some changes upstream that remove the rust.bzl file.
It had previously been left in there for compatibility purposes.  This
has been ongoing since February 16th.  See this issue for additional
context: bazelbuild/rules_rust#591.
gravypod pushed a commit to bazelbuild/rules_docker that referenced this issue Nov 9, 2021
Rules rust has made some changes upstream that remove the rust.bzl file.
It had previously been left in there for compatibility purposes.  This
has been ongoing since February 16th.  See this issue for additional
context: bazelbuild/rules_rust#591.
@dae
Copy link
Contributor

dae commented Nov 14, 2021

FYI: Cargo-raze v0.13 is released and it produces BUILD files that are compatible with this breaking change.

Are you sure? I'm still seeing rust_library() in output build files, and can't find references to things like 'rust_static_library' in the cargo-raze sources. I see no associated PR, and only an open issue: google/cargo-raze#398

yatbear pushed a commit to yatbear/tensorboard that referenced this issue Mar 27, 2023
dna2github pushed a commit to dna2fork/tensorboard that referenced this issue May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants