wlav / cppyy

Other
404 stars 42 forks source link

Manually specifying the `-march` compiler flag #217

Closed befelix closed 7 months ago

befelix commented 7 months ago

Thanks for providing and maintaining this excellent library. I'm facing an issue where I am installing cppyy inside a docker image, which can later run on different CPU architectures. This naturally leads to errors, since cppyy is compiled with the -march=native flag and uses instructions sets specific to the CPU architecture at installation/build time.

I tried changing the EXTRA_CLING_ARGS, but since the setup.py in cppyy uses set_cling_compile_options(True), the default of -O2 -march=native is always appended to any extra flags provided by EXTRA_CLING_ARGS.

Is there any way to overwrite the default settings or is there a better solution for the problem at hand?

wlav commented 7 months ago

The reason for the choice in setup.py is that during install, that may be the only time that the installation directory is writable and not having the default options seems to be more confusing. (The naming in the envar of EXTRA is a Cling thing that I shouldn't have adopted, but true, EXTRA means in addition of the defaults, not instead of, so the confusion is legit).

However, this behavior is different at runtime (historic reasons). There, only EXTRA_CLING_ARGS is used and no further default flags are added. Furthermore, the PCH file that was created with the native flag has that as part of the file name. Meaning, there will be a new PCH created, alongside the installed one, when -march=native is dropped from the flags.

Now, if you only want one PCH (with no native) for disk size reasons and/or need the PCH prior to deployment, then what I would do is set CLING_STANDARD_PCH=none during installation into the docker image and then set EXTRA_CLING_ARGS in the run-time as desired. Run python -c "import cppyy" once to create the PCH as part of the image.

Perhaps also of use is CLING_REBUILD_PCH which forces rebuild at run-time for each run, not just the first. That one is really meant for debugging, hence not documented, but it's not going away.

befelix commented 7 months ago

Thanks a lot for your support - worked like a charm!