-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
autodocs: recognize lib.zig as a library root source file #22827
Conversation
80b9726
to
06fa431
Compare
I'm fairly neutral to whether lib.zig becomes the default name, but just to throw out more data points: One fairly common pattern I've used in certain projects makes use of root.zig, lib.zig, and main.zig.
This naming also lines up nicely with build.zig functions, where lib.zig is passed to addLibrary and root.zig is passed to addModule. |
Arguably, |
Perhaps, although I lean towards viewing it as quite clear in its meaning when existing alongside root.zig.
I don't view that as better at all. "c" is quite overloaded; used commonly with cImport (sometimes gathering common cImports in one file), and "c.zig" also sometimes used when writing extern stubs to a C dependency. I find that having a file named "c.zig" is strictly more ambiguous. And, as an aside, any library that both consumes and exports C libraries would make "bindings.zig" an ambiguous name. The project would not make it clear whether bindings refers to bindings for the project proper, or bindings to its C dependencies. At the very least, no less ambiguous (and arguably more ambiguous) than lib.zig. Whatever the case may be, this should probably be written as a proper proposal issue rather than in a PR. |
Building C/C++ libraries with Zig for consumption (with or without bindings) is better done as a separate repo, properly utilizing the package manager (see @allyourcodebase for examples). So consuming C libraries by Zig projects won't be happening under |
Ok, it seems we are talking circles around each other so let me be very explicit. It doesn't matter what you or I believe is/isn't a good naming choice; I didn't make my original point to bikeshed recommendations on what to name a library root source file. Irregardless of our personal tastes/opinions, there are Zig users and projects existing in the wild that use the name Moreover, the use of I've stated that such naming patterns using With the above said, I hope you can now acknowledge that your proposed changes are indeed breaking; I am not asking for advice on what I should be doing. Now, with that out of the way, here are more reasons why your proposal is not as cut-and-dry as you initially suggested:
Finally, I'd like to reiterate that you are proposing a breaking change in a PR. It's not really the
to agree with your proposal here, for the multitude of reasons listed above, and it would be really great if users actually have a chance to discover this proposal and contribute their opinions through the proper channels; e.g., making a proposal issue. |
Hi, I'd like to plead the case for
lib.zig
as a valid library root source file, and moreover, to challenge the current convention ofroot.zig
being the library root source file.Here're some points to consider:
Since library code can sometimes resort to inspecting users' root source files with
@import("root")
, havingroot.zig
as the library root source file can be confusing, whereaslib.zig
would avoid this confusion.The word root (either a noun or an adjective) is objectively more likely to be encountered in other contexts across potential Zig codebases (tree-like data structures, file system hierarchies, privileged access permissions) and conflict with these other uses, compared to the word lib which, being a common alias for library (a noun), is much less likely to emerge beyond the compiler-related projects.
A
lib.zig
file succeeds at being perceived as exclusively a library root source file, similarly to how amain.zig
file is seen as an executable root source file, whereasroot.zig
only communicates that it's a root source file, without making it immediately apparent that it's a library root source file.FWIW, querying GitHub Search with
root.zig language:Zig
gives 4.8k source code results whilelib.zig language:Zig
produces 5.1k results, which may suggest that Zig users are already slightly more biased towardslib.zig
.In the
unlikelyexpected case that you become convinced thatlib.zig
is a better library root source file, I'd be happy to change thezig init
template and its generation logic (the only other places whereroot.zig
convention is enforced) in a follow-up PR.