Skip to content
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: Porting to C++ #218

Closed
kaniini opened this issue Mar 29, 2021 · 15 comments
Closed

RFC: Porting to C++ #218

kaniini opened this issue Mar 29, 2021 · 15 comments

Comments

@kaniini
Copy link
Member

kaniini commented Mar 29, 2021

The majority of pkgconf is basically data structures and string manipulation code.

By porting pkgconf to C++, we could drop most of the boring code and focus strictly on the pkgconf functionality itself. Although this would likely make the executable heavier, this would in trade make maintenance a lot simpler.

What do people think about this idea?

@a4z
Copy link

a4z commented Mar 29, 2021

From a project observer perspective:
If it becomes heavier depends on which parts of C++ you are using.

With C++ you can for sure focus on relevant parts, since due RAII (constructor, destructor) resource management becomes a no issue, and through using of data types like std::array std::vector, buffer overflows are non existing, basically.

That said, C++ has kind of a learning curve, due to its size it takes some time and experience to find the right subset of the language that works for a project and the involved people. But if you find that, C++ can be superior to C in any aspect.

@orbea
Copy link
Contributor

orbea commented Mar 29, 2021

For a core system dependency I strongly suggest targeting C99.

@ddevault
Copy link

ddevault commented Mar 29, 2021

Strong NACK.

@kaniini
Copy link
Member Author

kaniini commented Mar 29, 2021

Why? You need g++ to build gcc anyway. You need g++ or clang++ to build clang.

@ddevault
Copy link

ddevault commented Mar 29, 2021

There is more than one C compiler out there.

@kaniini
Copy link
Member Author

kaniini commented Mar 29, 2021

Yes, but the ones I mentioned are the system compilers for all of the platforms that pkgconf formally supports. So it does not change the bootstrap angle.

The alternative would be to add even more code to pkgconf to add Pascal-style strings (like apk-tools does), and port over the object system from apk-tools so we can clean up the vtable use that way.

Porting to C++ instead of the framework built into apk-tools would make the codebase more accessible to new contributors, in my opinion. I am tired of PKGCONF_ITEM_SIZE and PKGCONF_BUFSIZE and the lack of proper string handling.

@ddevault
Copy link

ddevault commented Mar 29, 2021

Why do you formally support any platforms or compilers in the first place? Target a C standard and a POSIX standard.

@kaniini
Copy link
Member Author

kaniini commented Mar 29, 2021

We target POSIX 2017 at the moment and ISO C11. However, in practice, pkgconf targets contemporary UNIX distributions, and recently, Windows. All of which have a system C++ compiler that supports C++11 or newer.

Would you like to propose an alternative that gives us memory-safe string operations and allows us to cleanly encapsulate the behavior of the multiple areas of the code where we use vtables and similar?

It does not have to be C++, but I would like to use a language and standard library that cleanly supports these concepts. Perhaps the language you are working on?

@ddevault
Copy link

ddevault commented Mar 29, 2021

The language I am working on would be well suited for pkgconf if it were more mature. However, I see no reason to leave C. You seem to have been doing fine with it thus far, and pkgconf is hardly the fastest moving target - nor ought it be. The work required to port it to something else seems to far outweigh the work required to maintain the status quo.

Ultimately the maintenance burden is yours to bear, and thus it is your decision to decide the shape of that burden, but if you make this change, you'll offload some of it onto downstreams and users instead.

Honestly, if pkgconf were rewritten in C++ that would make a strong argument for returning to pkg-config.

@kaniini
Copy link
Member Author

kaniini commented Mar 29, 2021

Why would it be a strong argument for returning to something that is no longer maintained and embeds a copy of GLib2? I don't understand why switching to C++ over C would add additional burden for a downstream, since they need C++ anyway to build the other components.

Linux, for example, absolutely requires gcc or clang, which require a C++ compiler to build anyway.

I'm fine with importing the framework code we have built to achieve memory-safe stringops in apk (apk_blob), but am not sure if new developers will be thrilled to use that code.

@ddevault
Copy link

ddevault commented Mar 29, 2021

Perhaps not returning to pkg-config (though I'll take Glib over g++ any time), but definitely a strong motivator for a fork.

I thought you targetted POSIX, not Linux. In any case, a C compiler could be written which implements GNU C extensions but does not support C++.

What new developers? As far as I'm concerned, pkgconf is done. Shouldn't you be more concerned with long-term maintenance than with rewrites at this point?

@kaniini
Copy link
Member Author

kaniini commented Mar 29, 2021

Well, I am sure the BSD kernels also depend on GCC or clang.

I agree with you that pkgconf is mostly a done topic, especially with the introduction of C21/C++20 modules and meson subprojects.

But there are still some imperfections that would require substantive refactoring to properly implement, like #213 (which will require the ability to evaluate a struct pkgconf_tuple's value at expansion time).

So the question becomes -- if I am going to do this refactoring -- how far should I go? I don't think #213 for example is really a deal breaker, but it would be nice to fix properly.

@kaniini
Copy link
Member Author

kaniini commented Mar 29, 2021

Another question to think about -- if we all agree pkgconf is largely a done topic -- what should a capstone branch look like?

I think it would be nice to convert the man pages to use scdoc, for example.

@ddevault
Copy link

ddevault commented Mar 29, 2021

Ah, yes, the two kernels: Linux and BSD. Pity no one ever wrote anything else /s

You're also in a position to decree that the ecosystem adapt to your idiosyncrasies in exchange for a simpler product. I don't know if #213 is an example of that, but it's something to keep in mind. You have the leverage to choose to be simpler than you could otherwise be.

@kaniini
Copy link
Member Author

kaniini commented Mar 29, 2021

I think we will stick with C and just port some nice things from apk-tools over. We can talk about other final touches for pkgconf on #220.

@kaniini kaniini closed this as completed Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants