dart-lang / native

Dart packages related to FFI and native assets bundling.
BSD 3-Clause "New" or "Revised" License
115 stars 40 forks source link

Support pkg-config #413

Open jpnurmi opened 4 years ago

jpnurmi commented 4 years ago

It would be nice to be able to simply specify the desired package(s) instead of fiddling with compiler-opts. For example:

pkg-config: 'gtk+-3.0'

ffigen can use pkg-config on systems where available, and populate compuler-opts by itself:

$ pkg-config --cflags gtk+-3.0 
-pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/harfbuzz -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
hacker1024 commented 2 years ago

What's the current status on this? It would be very useful for cross-platform generation.

dcharkes commented 2 years ago

How would you envision that this would work? Would this have to use a C package manager? Or is there some predictable transformation from an input string such as "gtk+-3.0" to compiler options?

jpnurmi commented 2 years ago
final res = await Process.run('pkg-config', ['--cflags', 'gtk+-3.0']);
print(res.stdout); // "-pthread -I/usr/include/gtk-3.0 ..."
jpnurmi commented 2 years ago

For reference, some places where it's used in Flutter:

dcharkes commented 2 years ago

Ah cool! (I was interpreting pkg-config as the Dart package config rather than a C tool. Which had me confused there.)

It should be relatively easy to integrate this.

  1. Add it to the config
  2. Check if pkg-config is available on path, otherwise error if used in config
  3. Concat(?) the result with the compiler flags option. (Which one should come first?)
  4. Add a unit test, that is only run on Linux/MacOS hosts.

As I understand this doesn't work for Windows, correct?

Feel free to contribute a PR. 🙂

@mannprerak2 any ideas or concerns?

mannprerak2 commented 2 years ago

I guess it's fine by me.

Also, can one not simply write a script which takes pkg-config output and supplies compiler opts to dart run ffigen --compiler-opts="......"

P.S I haven't worked with pkg-config.