-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
RFC: provide a build system for Linux distribution integration #581
Comments
From the linked PR, you said:
I would like to respond, that nearly every C build system provides a way to detect "system dependencies" using the standardized pkg-config interface. Certainly,
among others, support this detection. (Implementing it in any other build system is as simple as writing the glue code to execute the I believe that there would be significant interest by downstream projects in using system tree-sitter installations. Furthermore, there are a number of environments (most Linux distributions tend to be very concerned about this) where vendoring source code of one project inside another project is a very big no-no and can cause proposed package uploads to be rejected or delayed. |
Hey, thanks for listing out the requirements clearly. I think it seems reasonable to include something in this repo that helps with this use case.
As we discuss this, I do think it'd be helpful if you understood the reasons why the library is currently consumed the way that it is. I'm not sure whether it's necessary to go into detail, but for the majority of use cases, the fact is that the downstream application needs to:
Does that make sense? Moving on, I totally acknowledge that we should support dynamic linking better, provided that it doesn't complicate the existing use cases. |
Some questions about the requirements that you listed. I'm not super familiar with the differences between the various linux package management systems. So I appreciate you explaining this stuff.
Overall, I'd just really like to minimize 1) the dependencies associated with the project, and 2) the code/config that I take responsible for maintaining and which is not consumed by the existing project structure (e.g. the CLI, the existing language bindings, etc). |
I'm looking at the Arch package sources for some packages seem to have a similar complexity as Tree-sitter. It seems like there's a number of different patterns that exist. In some cases, the project repos themselves just contain a In other cases, project repos themselves contain both a In some cases, projects just contain a It seems like most of the more complex libraries use either autotools or CMake. It seems like we can all agree that Tree-sitter should probably at least have a Makefile, instead of its current 20-line shell script. So I'd like to propose, as a starting point for this discussion, the following initial steps:
If we need futher automated configuration, I think I'd prefer to use CMake as opposed to autotools, or something more obscure like Meson. @eli-schwartz Thoughts? |
I do understand that downstream projects may need to carefully control the version, however, I think pkg-config can serve this purpose too: the downstream project can require a specific version or version range such as Satisfying missing external dependencies can often be solved with a fallback such as meson's Wrap dependencies or cmake's ExternalProject that downloads on demand and builds a static library. (I agree, too, that static libraries can be useful!)
It's a widely accepted standard, and though it isn't universally used by C libraries, projects that depend on C libraries prefer to discover them using pkg-config. It's pretty universally supported by build systems, and some, like https://conan.io/, will actually try to create one for you if the C library dependency doesn't already have one. (This is sometimes not so great, because you can only depend on it if you use conan for everything, and also because you have to guess what the upstream developer intended. Hence, it's preferred to have an upstream one, as opposed to pathologically confusing cases like lua, where many downstream vendors provide their own pkg-config files with different names so you cannot actually rely on them.)
They don't, though it can be convenient, and it become very convenient if your library has multiple dependencies, some of which are optionally enabled via build-time options. I'd generally suggest that if you're going to use a build system which knows how to autogenerate it, why not take advantage... but if not, you don't have to. The alternative is a simple, static template such as the following example:
And you could use sed to replace
A Makefile would be fine, as long as it has an install target and the compiler line uses CFLAGS. POSIX Make has built-in pattern rules for compiling .c -> .o while making use of CFLAGS (Single Suffix Rules), and GNU Make includes a |
This seems like a fine solution to me. How about we add a |
That seems pretty reasonable to me as well. Thanks for the consideration! As a slight matter of personal taste, I would recommend naming it
|
Love it. I too was hoping to avoid that sed-in-place business. |
Is anyone interested in opening a PR with these additions? |
I've finally gotten the time to take a look at this and I created #602 which I believe should cover all the bases. I've attempted to be fairly generic to ensure it's broadly usable. Tell me if there's anything you'd like tweaked. It's inspired by some similar Makefiles e.g. the one mentioned above, but I've taken a few liberties to do things my (hopefully simpler) way. |
Linux distributions would like to provide a system libtree-sitter.so and headers in /usr/include, sufficient to build and link against the tree-sitter software. This would be available as a mutually inclusive alternative to the currently documented way to use tree-sitter, which is to copy the project wholesale as a vendored subdirectory inside another project's git sources, and manually integrate it into that other project's build system.
Requirements for distribution packaging:
$CFLAGS
and$LDFLAGS
pkg-config --libs --cflags tree-sitter
to emit whichever required C compiler flags needed to link to tree-sitter. Typically, that would be-I/usr/include -L/usr/lib -ltree-sitter
.Not in scope:
Preventing people from continuing to copy source files into their project, if they really want to.
Suggestion:
The meson build system is a fairly popular build system that can automatically handle most integration details for building and installing software. You simply define a
library()
, tag it withinstall: true
, and add all source files and headers, everything else is handled automatically. #467 implements meson for this project, and could be used as inspiration for a mutually satisfactory solution. One bonus of meson is that it can automatically generate pkg-config files via its Pkgconfig module.The text was updated successfully, but these errors were encountered: