Skip to content

Improve MAKEFLAGS merging#168

Open
orlp wants to merge 1 commit into
tikv:mainfrom
pola-rs:makefile-merge
Open

Improve MAKEFLAGS merging#168
orlp wants to merge 1 commit into
tikv:mainfrom
pola-rs:makefile-merge

Conversation

@orlp

@orlp orlp commented Jun 11, 2026

Copy link
Copy Markdown

Fixes #167.

Summary by CodeRabbit

  • Chores
    • Improved build system handling of parallelization flags during compilation. The build process now more intelligently manages parallelization settings to avoid conflicts and ensure consistent behavior across different build environments.

@ti-chi-bot

ti-chi-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

Welcome @orlp! It looks like this is your first PR to tikv/jemallocator 🎉

@ti-chi-bot

ti-chi-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

Thanks for your pull request. Before we can look at it, you'll need to add a 'DCO signoff' to your commits.

📝 Please follow instructions in the contributing guide to update your commits with the DCO

Full details of the Developer Certificate of Origin can be found at developercertificate.org.

The list of commits missing DCO signoff:

  • 64c4ba5 Improve MAKEFLAGS merging
Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The build script now correctly merges CARGO_MAKEFLAGS and MAKEFLAGS environment variables while preserving the semantics of post-dash arguments (arguments after --). New parsing helpers split both variables, combine their options, and reconstruct a single merged MAKEFLAGS string. The make_command function now checks if -j is already present in the merged result before appending parallelism, preventing duplicate or malformed flags.

Changes

MAKEFLAGS Parsing and Merging

Layer / File(s) Summary
MAKEFLAGS parsing, merging, and conditional parallelism
jemalloc-sys/build.rs
parse_makeflags splits a MAKEFLAGS string into pre-dash options and post-dash arguments; merge_makeflags combines two MAKEFLAGS strings by concatenating options and merging post-dash arguments behind a single --; make_command uses these helpers to correctly merge environment variables and appends -j only when not already present in the result.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit hops through MAKEFLAGS with care,
Parsing dashes left and right with flair,
Options merge but arguments stay true,
No more stray s to confuse the brew! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: improving MAKEFLAGS merging logic in the build script.
Linked Issues check ✅ Passed The changes directly address issue #167 by fixing MAKEFLAGS merging logic and detecting existing -j options to prevent duplication.
Out of Scope Changes check ✅ Passed All changes are focused on fixing MAKEFLAGS parsing and merging in jemalloc-sys/build.rs, directly related to the reported issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@jemalloc-sys/build.rs`:
- Around line 446-451: The current parallelism detection uses f.contains("-j")
on the entire MAKEFLAGS (in the makeflags -> already_parallel logic) which can
false-positive on arguments after the "--" separator; change the check to only
inspect the options portion before the first "--" (split MAKEFLAGS on "--" and
use the first segment) and then search that options segment for "-j" or the long
form like "--jobserver-"; update the condition that sets already_parallel (and
keep cmd.env("MAKEFLAGS", &f) unchanged) to use this filtered segment when
deciding whether to treat make as already parallelized.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d12cd0e9-8735-4c48-bfff-0f27822ebe70

📥 Commits

Reviewing files that changed from the base of the PR and between 0e91291 and 64c4ba5.

📒 Files selected for processing (1)
  • jemalloc-sys/build.rs

Comment thread jemalloc-sys/build.rs
Comment on lines +446 to +451
let already_parallel = if let Some(f) = makeflags {
cmd.env("MAKEFLAGS", &f);
f.contains("-j") // Matches both -j and --jobserver-*.
} else {
false
};

@coderabbitai coderabbitai Bot Jun 11, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚖️ Poor tradeoff

Parallelism detection can produce false positives.

The substring check f.contains("-j") searches the entire MAKEFLAGS string, including post-dash arguments. If a target or file after -- contains the substring -j (e.g., MAKEFLAGS="-- -junk-target"), the check incorrectly returns true, causing the code to skip adding -j when parallelism is not actually configured.

🔍 Proposed fix to check only the options portion
-    let already_parallel = if let Some(f) = makeflags {
+    let already_parallel = if let Some(ref f) = makeflags {
         cmd.env("MAKEFLAGS", &f);
-        f.contains("-j") // Matches both -j and --jobserver-*.
+        let (options, _) = parse_makeflags(f);
+        options.iter().any(|opt| opt.starts_with("-j") || opt.starts_with("--jobserver"))
     } else {
         false
     };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@jemalloc-sys/build.rs` around lines 446 - 451, The current parallelism
detection uses f.contains("-j") on the entire MAKEFLAGS (in the makeflags ->
already_parallel logic) which can false-positive on arguments after the "--"
separator; change the check to only inspect the options portion before the first
"--" (split MAKEFLAGS on "--" and use the first segment) and then search that
options segment for "-j" or the long form like "--jobserver-"; update the
condition that sets already_parallel (and keep cmd.env("MAKEFLAGS", &f)
unchanged) to use this filtered segment when deciding whether to treat make as
already parallelized.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aware but can't be arsed to do something 'proper' - I think this already takes up more resources than is deserved.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orlp Fair enough — the scenario where a post--- argument happens to contain -j is admittedly quite contrived in practice. Happy to leave it as-is.

(ʕ•ᴥ•ʔ)ᵒᵏ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strange Makefile build error on tikv-jemalloc-sys 0.7.1

1 participant