scikit-build-core icon indicating copy to clipboard operation
scikit-build-core copied to clipboard

Support cmake presets

Open henryiii opened this issue 1 year ago • 12 comments
trafficstars

Example: https://github.com/1yefuwang1/vectorlite/blob/main/setup.py

We should add a preset option, maybe cmake.preset, and then we can try to read the values from here that affect us, like binaryDir.

henryiii avatar Jul 01 '24 12:07 henryiii

It just occurred to me that you can just overwrite binaryDir, e.g.:

$ cmake --preset default -B /path/to/scikit-build-build

Heck, you can even do this:

$ cmake -S .. --preset=default -B other-build

It would not work for build/test/workflow presets though, but should those even be supported right now?

What about for first pass to add cmake.preset and just have the -D, -C take care of the overwrite initially?

LecrisUT avatar Jul 01 '24 12:07 LecrisUT

I think overriding the binaryDir probably makes sense; in which case, is there anything that we could provide that would be better than doing cmake.args = ["--preset=default"] now? Build presents do require a build.preset setting since we don't provide arbitrary args to build, but IMO that's fine.

I think we should make a new configure / config section instead of continuing to put everything in cmake.

henryiii avatar Jul 01 '24 15:07 henryiii

I think we should make a new configure /config section instead of continuing to put everything in cmake.

Agree, that would make more sense. Maybe even install, but that might clash with wheel-* stuff which would be better to have on top level so that it follows hatchling configuration?

I think overriding the binaryDir probably makes sense; in which case, is there anything that we could provide that would be better than doing cmake.args = ["--preset=default"] now?

Effectively it should be cmake.args = ["--preset=default"] , but having a dedicated option would make it more intuitive and easy to expand later on. Also good to fix the config API for the eventual 1.0.

Build presents do require a build.preset setting since we don't provide arbitrary args to build, but IMO that's fine.

I mean we can't override the binaryDir like we do for the configurePreset (not sure why it doesn't allow the override TBH, maybe it needs a PR to fix that).

LecrisUT avatar Jul 01 '24 15:07 LecrisUT

Duplicate of #515?

starball5 avatar Jul 02 '24 02:07 starball5

Yes, there are actually 3+ such issues :). But occasionally inspiration strikes

LecrisUT avatar Jul 02 '24 03:07 LecrisUT

Another thing that would be nice if we supported presets explicitly: https://github.com/orgs/scikit-build/discussions/1115#discussioncomment-10488748

henryiii avatar Aug 29 '24 15:08 henryiii

You mean reading the generator from the preset? Well that's an equally difficult issue to the binary-dir if we don't parse the Presets.json. Maybe we could just add a parser, but it's annoying that many variables like include supports macro expansions

LecrisUT avatar Aug 29 '24 15:08 LecrisUT

Why is parsing needed? Can you not just generate the buildsystem and then use the file API or something?

starball5 avatar Aug 30 '24 16:08 starball5

We need to know what build system is expected before we declare cmake is required because we need to declare ninja at the same time if it's required. We also need to know if we need to pass build-type Release/Debug, etc. flags when generating the build system. So basically we have to be able to parse quite a bit of this to support it (in a more integrated manner, that is - you can do it today by just manually overriding with the correct generator and build-type).

henryiii avatar Aug 30 '24 16:08 henryiii

I just found https://github.com/scikit-build/scikit-build-core/issues/515#issuecomment-2314986831... would be nice if this wasn't scattered across multiple issue tickets.

starball5 avatar Aug 30 '24 16:08 starball5

@henryiii You should really have this. Also, environment variables don't seem to work in cmake.args

thebest132 avatar Mar 21 '25 06:03 thebest132

Have what? Work for presets is started in #994.

Also, environment variables don't seem to work in cmake.args

Because they aren't environment variables, they are arguments to CMake? You can use environment variables in cmake.define, there's an option to take an environment variable and convert it into a define. You can also use environment variables with overrides, which allows pretty much anything.

henryiii avatar Mar 21 '25 16:03 henryiii