Skip to content

Cargo build-scripts doc includes very visible anti-example and "hand-wavy" non-working code #888

@kornelski

Description

@kornelski

This page: http://doc.crates.io/build-script.html doesn't answer my question: how can I replace Make with Rust? (I'd rather not replace it—#887—but you insist)

It did not help me write my build script, and left me frustrated.

I skim pages rather than read every single word of them (sorry!), and the first thing I've noticed when looking for simple solution to copy&paste was this example:

  Command::new("gcc").arg("src/hello.c")
                       .arg("-c")
                       .arg("-o")
                       .arg(format!("{}/hello.o", out_dir))
                       .status()
                       .unwrap();
    Command::new("ar").arg("crus")
                      .arg("libhello.a")
                      .arg("hello.o")
                      .cwd(&out_dir)
                      .status()
                      .unwrap();

When Cargo told me not to use bash and I found that as an answer, I was incredibly annoyed. It's replacing 2 lines of simple bash code with 20 lines of Rust, without gaining any portability, functionality or readability. It just shows Rust is a bad tool for the job (I'm not writing my build scripts in C, so I'm not going to write them in Rust).

And regardless of whether using Rust instead of bash is a good idea, this example isn't even the correct answer to the problem.

As far as I understand this document, the solutions for building custom C code are:

  1. Admittedly pointless practice that doesn't solve any problems caused by non-portability of bash invoking GCC
  2. "Hand-wavy" example that requires a library which is entirely hypothetical and can't actually be used, so this leaves only the option no.1.

Instead of an essay that explores only bad options, could you include real working examples that represent the best practice you're advocating for?

(sorry about pissed-off tone of these bugs, I can't help it)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions