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

New pkgconfig integration #4396

Open
acmorrow opened this issue Aug 16, 2023 · 4 comments
Open

New pkgconfig integration #4396

acmorrow opened this issue Aug 16, 2023 · 4 comments

Comments

@acmorrow
Copy link
Contributor

acmorrow commented Aug 16, 2023

Describe the Feature
The ParseFlags family of functions relies on picking specific flags out of the command line. This is non-portable and hard to maintain. A better approach would be to build a tool that knows how to make better use of the pkg-config command line API to pick out the functional groups of flags and connect them to the analogous SCons flags.

Required information

  • Per discussion on Discord
  • Version of SCons: N/A
  • Version of Python: N/A

Additional context
The idea was to write a new tool that understood how to use pkg-confg args like --libs-only-L to know what arguments should be attached to SCons LIBPATH variable, or --cflags-only-I to tie it to SCons CPPPATH. Something like:

pkgFlagsEnv = myenv.Clone()
pkg_config = pkgFlagsEnv.Tool("pkg-config")
pkgFlagsEnv.AppendUnique(
    PKG_CONFIG="/usr/bin/pkg-config",
    PKG_CONFIG_PATH=["/some/custom/place/to/find/packages", "/another/custom/place"],
    PKG_CONFIG_PACKAGES=[
        "foolib",
        ("barlib", "1.23+"),
    ],
    PKG_CONFIG_ARGS="--static",
    CCFLAGS=pkg_config.with("--cflags-only-other"),
    CPPPATH=pkg_config.with("--cflags-only-I"),
    LIBPATH=pkg_config.with("--libs-only-L"),
    LINKFLAGS=pkg_config.with("--libs-only-other"),
    LIBS=pkg_config.with("--libs-only-l"),
)

It is probably possible to provide a tools scoped dictionary to kwargs in the usual override suspects:

pkgFlagsEnv.AppendUnique(
    PKG_CONFIG...,
    **pkg_config.standard_overrides)
@loonycyborg
Copy link

If it's a Tool then it would make more sense to interact with it via methods instead.
Something like:

if env.CheckPkg("somepackage", min_version="1.0.0"):
    #flags are added at this point
else:
    #this package isn't found and script is expected to activate fallbacks at this point.

of course there should be lower level methods too, those that return dict with CPPPATH etc instead of adding them on their own.

@loonycyborg
Copy link

To put it more clearly, I'm not sure how in your proposed api you can adapt to missing packages, yet it's an important use case.

@acmorrow
Copy link
Contributor Author

I wouldn't consider my thing above to be in any way proposing a specific API. Just outlining an idea, and I'm sure there are many other ways to achieve what I'm suggesting. I guess if I had to summarize that idea in words, it would be to create a SCons tool that knows how to invoke the configuration tool repeatedly in the different modes to extract the relevant flags and apply them to the associated SCons Variables, without any special knowledge of or interest in the flags themselves. I think this is an important thing to do because I think it is basically impossible to make the existing ParseFlags feature robust. The approach it takes will always make it both too specific (hardcoded knowledge of certain flags) and incomplete (lack of awareness of other flags).

@loonycyborg
Copy link

There already exists this api: https://pypi.org/project/pkgconfig/ . Can scons adopt it as a dependency?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants