Compare user input for multiple dependency build variants#16600
Compare user input for multiple dependency build variants#16600andrewrk merged 5 commits intoziglang:masterfrom mattnite:compare-dependency-args
Conversation
lib/std/Build.zig
Outdated
| }) catch @panic("OOM"); | ||
| } | ||
|
|
||
| std.sort.insertion(Pair, ordered.items, {}, Pair.lessThan); |
There was a problem hiding this comment.
why insertion sort rather than sortUnstable?
There was a problem hiding this comment.
Tbh it was the first one that came up in code completion. I didn't give this choice much thought because I doubt we'll see N approach even 1000.
There was a problem hiding this comment.
OK please do change it to std.mem.sortUnstable. If you require stable sort, std.mem.sort is the way to go, and the time to use std.sort.insertion is pretty much never.
lib/std/Build.zig
Outdated
| hash.add(@as(u32, 0xd8cb0055)); | ||
| hash.addBytes(b.dep_prefix); | ||
|
|
||
| hashUserInputOptionsMap(b.allocator, b.user_input_options, &hash); |
There was a problem hiding this comment.
looks like you solved that TODO below :)
lib/std/Build.zig
Outdated
| if (userInputOptionsMapsAreSame(user_input_options, dep.builder.user_input_options)) { | ||
| return dep; | ||
| } |
There was a problem hiding this comment.
hmm I think I see a big problem here. This is correctly checking if a value in a hash map can be re-used, but then at the end of the function it will put the new value into the hash map, overwriting the old one. In other words, it does not successfully deduplicate with more complicated set of inputs. If we passed ABA, for example, it would create two A's instead of one A and one B.
I think you already created all the glue code that is needed to solve this; the initialized_deps hash map needs to key on not only the build_root_string but on the user input options as well. That hash map is exclusively used in this function, so you are free to change it to this function's needs.
There was a problem hiding this comment.
Thanks for pointing that out, I completely missed it. I’ve added user input to the key of initialized_deps.
|
Just noting this is blocking my terminal (Ghostty) from adopting the package manager. We build a universal macOS binary as part of the Mac build and this issue means that we build two of the same arches in a row rather than two distinct ones! 😄 Thanks so much @mattnite for fixing this. :) |
|
Another use case: The os isnt using the package manager yet, so i didnt encounter that problem |
If I try to build a dependency with different arguments today, only one version of that dependency is built, when it should build every variant. Here's a simplified example, I've imported the
echodependency twice, but in each scenario I've specified the dependency with different optimization modes.I'll now write a program to print the value returned by
get_optimization()in theechostatic library of theechodependency, and compile it twice, each using one of the dependency variants:However when I run both programs:
:(
Alright Andrew, I'll bite
walking down the
b.dependency()call stack there's a shiny lil todo:To fill in this TODO, the
argsof differentBuilds of the same dependency need to be compared. This patch generates aBuild'suser_input_optionshere for comparison with existing dependencies. If it's unique then the options are passed down to the newly createdBuild.The other piece of work, and related TODO, was generating the hash for the install prefix. Which now looks like this:
AFAIK, it's possible for entries in a
UserInputOptionsMapto have different orders depending on order of insertion.hashUserInputOptionsmaporders all values recursively -- TIL there could be maps in the user input option -- and then hashes everything.Note anyone reviewing please take a look at the hashing of different user values like
flag, it seems to me that just hashing the name would be good enough? I'm also not sure ifusedshould be included in hashing as well.I hope you're happy
Now my programs print:
The repos to reproduce this are dependency-variants and echo.