-
Notifications
You must be signed in to change notification settings - Fork 8
fix: use label as canonical name for zig_module and use it for module deps #566
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
base: main
Are you sure you want to change the base?
Conversation
This is actually a bugfix since otherwise 2 modules even with a different import_name would still fail to be depended on at the same tim.
|
CI fails are unrelated... |
The failure is related. Looking at the failing test binary and the corresponding shared library So, the issue is that the canonical name finds its way into the "NEEDED" entry of the binary. Since that's not a valid shared library file name, it leads to an unresolved dynamic library dependency at runtime. The reason it ends up in the "NEEDED" entry is that it also ends up in the "SONAME" of the shared library. The reason for that seems to be that this canonical name is used as the root module name for the library target: And IIUC Zig uses that as the soname by default. This brings up two points:
|
|
Thanks a lot for the review. That's a very good find... I'll sanitize this! |
c4c33f5 to
b7f50f4
Compare
aherrmann
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, that looks good!
Only one comment about the translate_c bit.
| canonical_name = "{}/{}".format(str(ctx.label), name), | ||
| canonical_name = "{}_U{}".format(escape_label(label = ctx.label), name), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this carries the risk of further collisions. The following example should trigger one:
zig_c_library(name = "a", import_name = "b_Uc") # --> canonical_name = "_S_S_Ca_Ub_Uc"
zig_c_library(name = "a_b", import_name = "c") # --> canonical_name = "_S_S_Ca_Ub_Uc"
Yes, it's contrived. But, I think a small change can avoid it.
Also, in some cases the name parameter is derived from the target name and these support a surprisingly wide set of characters including !%-@^_"#$&'()*-+,;<=>?[]{|}~/.. So, I think that part should also be escaped.
How about the following?
canonical_name = escape_label(label = "{}:{}".format(ctx.label, name))
Colon (:) is not allowed in label names and since the full string is escaped we should be safe against collisions.
This fixes the scenario where 2 modules have the same name in the graph.
Currently even with an different import_name (which they need to have anyway), the build would fail with:
For this, we use the str(ctx.label) which guarantees true canonical identifier, which we alias to
nameorimport_nameif it exists.