git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 13/18] build-helper: link against libgit.a and any other required C libraries

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Sep 17, 2025, 08:51 UTC
Message-ID
<CAPig+cTZch_pvfurtjBTNphMeRQL6jSBSjNY-4mffjoXZ4eqcw@mail.gmail.com>
In-Reply-To
<6a27e07e6310b6cad0e3feae817269b9b8eaed69.1758071798.git.gitgitgadget@gmail.com>

On Tue, Sep 16, 2025 at 9:18 PM Ezekiel Newren via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 8 quoted lines
> build-helper: link against libgit.a and any other required C libraries
>
> Don't link against the C libraries when building with Make or Meson.
> Run cargo tests like this:
> cd rust && cargo clean && USE_LINKING=true cargo test
>
> Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com>
> ---

Perhaps it's because I haven't been following the discussion closely enough, but the above commit message leaves me entirely in the dark. After reading and rereading it several times, I suppose it is trying to address some difference between building with `cargo` vs. building with Make or Meson, but it gives no explanation of what the differences are or what problem it is trying to solve. So, please enhance the commit message to begin with the "why" and then proceed to the "what" or "how".

Show 6 quoted lines
> diff --git a/rust/build-helper/Cargo.toml b/rust/build-helper/Cargo.toml
> @@ -4,4 +4,3 @@ version = "0.1.0"
>  edition = "2021"
>
>  [dependencies]
> -

This seems merely to be deleting a blank line which probably shouldn't have been present in the first place. Rather than fixing the "problem" here, it would make more sense to eliminate the blank line in the patch which introduced it in the first place.

Show 6 quoted lines
> diff --git a/rust/build-helper/src/lib.rs b/rust/build-helper/src/lib.rs
> @@ -0,0 +1,84 @@
> +use std::collections::HashMap;
> +use std::path::PathBuf;
> +
> +

If I'm not mistaken, it is uncommon to have two blank lines like this in Rust code.

Show 7 quoted lines
> +fn parse_bool_from_str(value: &str) -> bool {
> +    match value {
> +        "1" | "true"  | "yes" | "on"  => true,
> +        "0" | "false" | "no"  | "off" => false,
> +        _ => false
> +    }
> +}
Or, more simply:
    fn parse_bool_from_str(value: &str) -> bool {
        match value {
            "1" | "true"  | "yes" | "on"  => true,
            _ => false
        }
    }

(Though, admittedly, I'd probably lean toward writing the function the same way you did.)

Show 7 quoted lines
> +/// To build without linking against C libraries run `USE_LINKING=false cargo build`
> +/// To run tests set GIT_BUILD_DIR and run `USE_LINKING=true cargo test`
> +pub struct BuildHelper {
> +    crate_env: HashMap<String, String>,
> +}
> +
> +
Nit: unnecessary extra blank line
Show 5 quoted lines
> +impl BuildHelper {
> +    pub fn build(self) {
> +        let use_linking = parse_bool_from_option(self.crate_env.get("USE_LINKING"), self.crate_env.get("CARGO_TARGET_DIR").is_none());
> +        ...
> +            println!("cargo:warning={} is not linking against C objects, `USE_LINKING=true cargo test`", self.crate_env["CARGO_PKG_NAME"]);

There are more than a few developers on this project (including myself) who still use 80-column editors and terminals. As a general style guideline, this project does recommend wrapping code to fit within 80 columns (except in cases when doing so would severely hurt readability). I imagine that the same sort of guideline would be appreciated in Rust code, as well, by those who still stick with 80 columns.

I bring this up because, although it hasn't been such a big deal with the existing C code, assuming that developers run `rustfmt` on the code before sending a patch series, then this may become an issue if different developers have `rustfmt` configured to enforce different maximum column width, especially since `rustfmt` is likely to reformat the entire file rather than just the region that has just been edited. So, if this code gets checked in as-is with these very wide lines, and then someone else, who has `rustfmt` configured for 80-columns edits the file, then it becomes a problem.

As such, can we also add a project-wide `rustfmt.toml` which, at minimum, sets the maximum line width to 80? For instance:

    max_width = 80
Previous: Ezekiel Newren via GitGitGadgetNext: D. Ben Knoble
Message 62 of 100 in “Introduce rust: In xdiff”
  1. 00/15 Introduce rust: In xdiffEzekiel Newren via GitGitGadget, Aug 29, 2025
  2. 01/15 doc: add a policy for using Rustbrian m. carlson via GitGitGadget, Aug 29, 2025
  3. brian m. carlsonAug 29, 2025
  4. Ezekiel NewrenAug 29, 2025
  5. brian m. carlsonSep 2, 2025
  6. Ezekiel NewrenSep 2, 2025
  7. Ezekiel NewrenSep 4, 2025
  8. 02/15 xdiff: introduce rustEzekiel Newren via GitGitGadget, Aug 29, 2025
  9. 03/15 github workflows: install rustEzekiel Newren via GitGitGadget, Aug 29, 2025
  10. 04/15 win+Meson: do allow linking with the Rust-built xdiffJohannes Schindelin via GitGitGadget, Aug 29, 2025
  11. 05/15 github workflows: upload Cargo.lockEzekiel Newren via GitGitGadget, Aug 29, 2025
  12. 06/15 ivec: create a vector type that is interoperable between C and RustEzekiel Newren via GitGitGadget, Aug 29, 2025
  13. 07/15 xdiff/xprepare: remove superfluous forward declarationsEzekiel Newren via GitGitGadget, Aug 29, 2025
  14. 08/15 xdiff: delete unnecessary fields from xrecord_t and xdfile_tEzekiel Newren via GitGitGadget, Aug 29, 2025
  15. 09/15 xdiff: make fields of xrecord_t Rust friendlyEzekiel Newren via GitGitGadget, Aug 29, 2025
  16. 10/15 xdiff: use one definition for freeing xdfile_tEzekiel Newren via GitGitGadget, Aug 29, 2025
  17. 11/15 xdiff: replace chastore with an ivec in xdfile_tEzekiel Newren via GitGitGadget, Aug 29, 2025
  18. 12/15 xdiff: delete nrec field from xdfile_tEzekiel Newren via GitGitGadget, Aug 29, 2025
  19. 13/15 xdiff: delete recs field from xdfile_tEzekiel Newren via GitGitGadget, Aug 29, 2025
  20. 14/15 xdiff: make xdfile_t more rust friendlyEzekiel Newren via GitGitGadget, Aug 29, 2025
  21. 15/15 xdiff: implement xdl_trim_ends() in RustEzekiel Newren via GitGitGadget, Aug 29, 2025
  22. 00/18 Introduce rust: In xdiffEzekiel Newren via GitGitGadget, Sep 17, 2025
  23. 01/18 cleanup: rename variables that collide with Rust primitive type namesEzekiel Newren via GitGitGadget, Sep 17, 2025
  24. Eric SunshineSep 17, 2025
  25. Junio C HamanoSep 17, 2025
  26. Ezekiel NewrenSep 19, 2025
  27. 02/18 make: add -fPIE flagEzekiel Newren via GitGitGadget, Sep 17, 2025
  28. Eric SunshineSep 17, 2025
  29. Ezekiel NewrenSep 19, 2025
  30. Junio C HamanoSep 19, 2025
  31. Ezekiel NewrenSep 19, 2025
  32. Junio C HamanoSep 19, 2025
  33. Collin FunkSep 19, 2025
  34. Junio C HamanoSep 20, 2025
  35. Ramsay JonesSep 21, 2025
  36. 03/18 make: merge xdiff lib into libgit.aEzekiel Newren via GitGitGadget, Sep 17, 2025
  37. Eric SunshineSep 17, 2025
  38. Ezekiel NewrenSep 19, 2025
  39. 04/18 make: merge reftable lib into libgit.aEzekiel Newren via GitGitGadget, Sep 17, 2025
  40. Eric SunshineSep 17, 2025
  41. Junio C HamanoSep 19, 2025
  42. Ezekiel NewrenSep 19, 2025
  43. Junio C HamanoSep 19, 2025
  44. Ezekiel NewrenSep 19, 2025
  45. 05/18 doc: add a policy for using Rustbrian m. carlson via GitGitGadget, Sep 17, 2025
  46. 06/18 BreakingChanges: announce Rust becoming mandatoryPatrick Steinhardt via GitGitGadget, Sep 17, 2025
  47. 07/18 build: introduce rustEzekiel Newren via GitGitGadget, Sep 17, 2025
  48. Eric SunshineSep 17, 2025
  49. Junio C HamanoSep 17, 2025
  50. Eric SunshineSep 18, 2025
  51. Ezekiel NewrenSep 19, 2025
  52. Eric SunshineSep 19, 2025
  53. Ezekiel NewrenSep 19, 2025
  54. 08/18 help: report on whether or not Rust is enabledPatrick Steinhardt via GitGitGadget, Sep 17, 2025
  55. 09/18 github workflows: install rustEzekiel Newren via GitGitGadget, Sep 17, 2025
  56. Eric SunshineSep 17, 2025
  57. 10/18 win+Meson: do allow linking with the Rust-built xdiffJohannes Schindelin via GitGitGadget, Sep 17, 2025
  58. 11/18 github workflows: upload Cargo.lockEzekiel Newren via GitGitGadget, Sep 17, 2025
  59. 12/18 build: new crate, build-helperEzekiel Newren via GitGitGadget, Sep 17, 2025
  60. Eric SunshineSep 17, 2025
  61. 13/18 build-helper: link against libgit.a and any other required C librariesEzekiel Newren via GitGitGadget, Sep 17, 2025
  62. Eric SunshineSep 17, 2025
  63. D. Ben KnobleSep 17, 2025
  64. Eric SunshineSep 17, 2025
  65. Ezekiel NewrenSep 19, 2025
  66. 14/18 build-helper: cbindgen, let crates generate a header fileEzekiel Newren via GitGitGadget, Sep 17, 2025
  67. Eric SunshineSep 17, 2025
  68. Ezekiel NewrenSep 19, 2025
  69. 15/18 varint: use explicit width for integersPatrick Steinhardt via GitGitGadget, Sep 17, 2025
  70. 16/18 build: new crate, miscEzekiel Newren via GitGitGadget, Sep 17, 2025
  71. Eric SunshineSep 17, 2025
  72. Ezekiel NewrenSep 19, 2025
  73. Eric SunshineSep 19, 2025
  74. Ezekiel NewrenSep 19, 2025
  75. 17/18 misc: use BuildHelperEzekiel Newren via GitGitGadget, Sep 17, 2025
  76. 18/18 misc::varint: reimplement as test balloon for RustPatrick Steinhardt via GitGitGadget, Sep 17, 2025
  77. Patrick SteinhardtSep 17, 2025
  78. Ezekiel NewrenSep 19, 2025
  79. Patrick SteinhardtSep 22, 2025
  80. Ezekiel NewrenSep 22, 2025
  81. Patrick SteinhardtSep 22, 2025
  82. Junio C HamanoSep 22, 2025
  83. Ezekiel NewrenSep 22, 2025
  84. Ezekiel NewrenSep 22, 2025
  85. Junio C HamanoSep 22, 2025
  86. Ezekiel NewrenSep 22, 2025
  87. Junio C HamanoSep 22, 2025
  88. Junio C HamanoSep 22, 2025
  89. Junio C HamanoSep 17, 2025
  90. Junio C HamanoSep 17, 2025
  91. Elijah NewrenSep 17, 2025
  92. Junio C HamanoSep 17, 2025
  93. Patrick SteinhardtSep 22, 2025
  94. Ezekiel NewrenSep 22, 2025
  95. Patrick SteinhardtSep 22, 2025
  96. Ezekiel NewrenSep 22, 2025
  97. Patrick SteinhardtSep 23, 2025
  98. Ezekiel NewrenSep 23, 2025
  99. Ezekiel NewrenSep 23, 2025
  100. Junio C HamanoSep 23, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.