-
Notifications
You must be signed in to change notification settings - Fork 1.3k
update PCRE2 find module to be compatible with upstream CMake config script #3191
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
base: master
Are you sure you want to change the base?
Conversation
…stream
modified: CMakeLists.txt
Provide minimum PCRE2 version + 8BIT component and link against target
modified: Tools/cmake/FindPCRE2.cmake
Update find module to use config search first and fall back to manual
…andard_args to report on success
|
you dont want to use find_package inside the FindPCRE2.cmake module else the internal imported target in the FindPCRE2 module in a manner that matches the exported target is the right way to go note that if pcre2 is compiled using autotools no cmake config file is generated |
Yes, that's what I'm doing by using
Yes, that's why there's heuristic logic for the
|
|
Oops, there was one commit I forgot to push. It basically just adds a |
|
Hm, got a couple failing CI jobs. Not sure how they're related to this PR however. One failure is with linux / r gcc (pull_request) with an R segfault with the I see several warnings like this for each of the Boost Totally unrelated issue with windows / python 3.13 msvc (pull_request) where linking is failing: Seems like this is a known issue with 3.13.4 (fix in 3.13.5 it seems). |
|
I an novice when it comes to CMAKE.
I personally prefer to see an actual change in the testing when we make changes 😄 |
|
Hey, sorry for getting back to this late. I can respond to some of your questions:
For 2., would that mean adding something like |
Seems logic to use |
|
A Relevant docs will need to be updated in the same pull request too, yes. |
|
Oops, totally missed the comment. But ok, this sounds good. I think the relevant doc is |
Yes, "Building swig.exe using CMake" |
…uGet PCRE2 C runtime library selection
|
Hey, I have some time and have come back to this PR. I am tweaking |
…ub Actions links, update CMake SWIG instructions
…ory creation" This reverts commit e8d7dbe.
|
Also unrelated to the actual work in this PR, but is there a way to get the AppVeyor jobs to run concurrently with the GitHub Actions jobs? CI job throughput would of course increase if we didn't have 100+ GitHub Actions jobs waiting for several serialized AppVeyor jobs (which takes like 20+ minutes overall) to finish. |
We reduce AppVeyor jobs to 3 jobs because of the serialising issue. Anyhow the average time of all Linux testing running on GitHub Ubuntu is around 1 hour. |
Hm, I see. I guess compared to before there's already a big improvement, but I'm not sure why GitHub Actions will not let the GitHub Actions jobs run concurrently with the AppVeyor job. That seems a bit strange to me (unless it is by design).
One thing I had considered doing was seeing if the CMake config could be used to replicate the current Makefile example setup. CMake scripting in my opinion is an improvement over autotools because it works natively on Windows. That is, we can build SWIG using native MSVC, without MinGW or MSYS2, and then create native DLL modules for each language. Since CMake handles both configuration + build, we can add the necessary configuration logic the way we want to. I've worked CMake pretty hard in both my personal and work projects. My last job, I was maintaining a C++ library with some SWIG modules I wrote, and had CMake configure C#, Python, and Java SWIG wrapping tests (there were some typemaps I had written in those |
AppVeyor serialize by user, so each user can run a single job.
This is a question to @wsfulton. Another remark. The time today of the configure with autoconf is around ~1 m. Switch to CMake will not change the testing time, as most of the time is on instillation, building and above all the testing under |
Yes I understand that; just find it weird that the AppVeyor run blocks all the 100+ GitHub Actions jobs. Maybe it has something to do with how AppVeyor integrates with GitHub somehow... interesting,
Exactly, even if autotools is not replaced, there is still the question of maintenance. I like CMake since it means a lot of the configuration/probing and build orchestration logic is portable onto Windows vs. autotools, which is definitely a plus, but replicating the existing functionality of how the examples/test suite is configured is not trivial at all :(
It seems like mingw-w64 actually recommends CMake as one build option. CMake itself also provides a way to check if compilation is being done for MinGW. Even MSYS2 seems to have some page for CMake. Honestly, this is quite surprising for me--I have not used MinGW since the original 32-bit one years ago and so have not been following the changes :)
Of course; that's exactly the problem that CMake historically helps address, as you can use CMake for building on several Unix-like systems and for Windows. This avoids needing a separate build solution just for Windows, which I agree is not ideal. I would still say my opinion is that although I would be in favor of moving to CMake, I recognize that replicating the current Makefile test-suite configuration is not simple at all. And definitely agree that it's a big decision to think about. |
|
Anyways, happy to wrap this PR up if the documentation + CI configuration changes are satisfactory. I will consider experimenting with CMake to build some of examples and test suite tests, but I am not interested in getting those changes merged to |
https://docs.github.com/en/actions/concepts/runners/github-hosted-runners
CMake is used for a long time. It does make sense these projects support it.
It is your call. |
The test categories are only in the context of the AppVeyor job; I'm mostly just not sure why the GitHub Actions jobs are all blocking for the AppVeyor job. Maybe it's just how GitHub/AppVeyor are integrated...
Yes, totally understand. It is not a simple thing to do given all the language + compiler + platform combinations.
Sounds good; maybe when I have something to show I will consider starting a new issue. For now, it's just an idea :) |
AppVeyor runner do not block GitHub actions.
I was refer to the size of the task ...
Your call |
There are various pull requests which improve CMake and add testing, some of them quite advanced, but if I recall correctly none of them were ever quite finished off and had problems compared to the autotools test-suite and slow (but that might be different now?). I suggest you search for them in github and the two mailing lists. I think there was one or two that ran the test suite for one of the target languages. I suggest finding one of the tickets and following up or creating a new one and summarise all the previous attempts in it to give a status. Get copilot to do it???
Indeed. An incremental improvement in parallel would be the only feasible approach to adding CMake support and maybe it would replace autools in the long term once proved. It would require someone to commit to doing it and maintaining it. Regarding Appveyor, the goal is to stop using it and fully switch to Github Actions, but it's not the most important thing right now. Am concerned we'll lose the ability to test some older versions as GHA images seem to be focusing more and more on just making the very latest available. Anyway regarding this merge request, could someone else familiar with CMake please give it an approval and I'll then look at merging it. I think that would be you @jschueller given you've mostly recently maintained the CMakeLists.txt file. |
At least initially, I see the AppVeyor job runs first while the GitHub Actions jobs are waiting. It's possible that after some time, while the AppVeyor job is running, that the GitHub Actions jobs start actually running, but I haven't confirmed this because I'm usually doing something else once I see the AppVeyor job going. This behavior actually seems new; I didn't notice before. I could be wrong or it's possible GitHub Actions might have some scheduling policy changes or even just been busy.
Yes, I know... there is a lot of cover and therefore a lot to maintain. |
Yeah, I see at least #2646 which is rather ambitious and also has a lot of proposed CI changes. I'm not sure how well it covers the existing SWIG test suite logic, however. Consider this snippet from add_test(NAME ${name}
COMMAND $<TARGET_FILE:Swig_swig> -${ARGS_LANGUAGE} ${ARGS_EXTRA_ARGS} ${name}.i
)This doesn't do any of the C/C++ module compilation; it just generates the C++/target language wrappers. Definitely the goal is to at least incrementally match some of the rules in
:)
Agree; transitioning a build system isn't doable as a drive-by change.
Yes, I remember there was an |
Not at all.
|
Ok, understood. That makes more sense, but their waiting makes it seem like they are waiting for the AppVeyor job (which usually starts instantly). I'm not trying to "complicate" anything; just my observation of what seemed to be happening. |
You are probably Lucy. |
While autotools are not perfect and SWIG's autotools config is uglier than many, I would not be in favour of switching to cmake. Every time I have to interact with cmake I end up cross, sad and frustrated, so I have no desire to use cmake more than I absolutely have to. I'm certainly not going to work on it in a voluntary capacity - if we did switch, I'd just stop doing any work on SWIG's build system. |
|
I can't see myself switching focus from autotools to CMake either, it'll be too much work. We need a CMake maintainer really, but for now I need someone who is familiar with CMake to validate/check the pull request to approve it and then I'll be happy to merge it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have (unfortunately...) had to become familiar with CMake, so after reading William's comment I've decided to review this but, actually, there are relatively few CMake changes here and the ones that are there are definitely correct, i.e. we should prefer the exported alias to manually using PCRE2_LIBRARIES.
IOW this is good to be merged, from my point of view, but may be improved a bit depending on how much importance you attach to the not-really-CMake-related comments below.
| matrix: | ||
| # note: -arm variants exist for arm64 testing | ||
| os: [ubuntu-22.04, ubuntu-24.04] | ||
| # note: can add Ninja too for ubuntu runners. 'Ninja Multi-Config' can |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if I fully expect it to work, I think it would still be worth testing with Ninja. Personally I always use it rather than the default make generator under Unix and I think I'm not alone.
Maybe have a "matrix" with Ubuntu 22.04/Make and Ubuntu 24.04/Ninja builds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I actually had the CMake generator be part of the matrix, but I got some feedback that the "Unix Makefiles" generator name was a bit confusing. If there's interest I can support this, e.g. with
# ...
name: CMake ${{ matrix.os }} ${{ matrix.backend }}
strategy:
matrix:
# ...
backend: ["Unix Makefiles", "Ninja"]
# ...
# use cmake -S . -B build -G ${{ matrix.backend }} ... in the build step|
|
||
| env: | ||
| BUILD_SYS: Visual Studio ${{ matrix.VER }} | ||
| # CMake generator used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing Ninja under Windows would be useful too (although I'm less sure of it working out of the box there).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try this briefly when I have some time. The Windows runner images seem like they each only have a single Visual Studio installation, so maybe Ninja Multi-Config can pick this up.
Also by using Ninja Multi-Config, I think we won't even need to modify the CMake commands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has this been copied from somewhere or written specifically for SWIG?
If it was copied, it would be nice to preserve the original location somewhere to make updating it easier (maybe in a README in this directory?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the history but judging from the Git history, i.e. 15515f3, and the related GitHub issue, it seems like FindPCRE2.cmake was written specifically for SWIG. Furthermore, it replaced an older FindPCRE.cmake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reference does not have to be the source of the written CMakeLists.txt.
It could also be a reference explaining important aspects of the change, or could assist up in the future in case something need upgrading or something get broke.
Perhaps a proper reference explaining how to use CMake with PCRE properly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean by reference, but I can add a usage example to the comments, e.g.
# Example usage:
#
# find_package(PCRE2 10.39 REQUIRED COMPONENTS 8BIT)
#
# add_executable(myprog myprog.c)
# target_link_libraries(myprog PRIVATE PCRE2::8BIT)The usage is the same as a "typical" find_package call regardless of the PCRE2 version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the history but judging from the Git history, i.e.
15515f3, and the related GitHub issue, it seems likeFindPCRE2.cmakewas written specifically for SWIG. Furthermore, it replaced an olderFindPCRE.cmake.
Surely the question is about the origin of the FindPCRE2.cmake in your patch - it looks like you've discarded the existing file with that name and replaced it with a completely different implementation which you've also named FindPCRE2.cmake. So the question is where did your FindPCRE2.cmake come from? It would be strange to expect you to explain the origin of the existing file with that name which is already in SWIG's git repo.
As well as being polite to identify the original author of code, we need to know how it is licensed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be precise "either version 3 of the License, or (at your option) any later version".
If you want to license it as something that's less restrictive than that, that's OK if it's compatible (and may help promote reuse over proliferation of different FindPCRE2.cmake implementations). There's more than one "MIT licence" in common use, but I know the MIT/X one is compatible with the GPL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, "the" MIT license I was thinking of is this one which has the text of the Expat license. I'd prefer to license this CMake script under that unless there's a strong preference for GPLv3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just bumping this thread since I remembered about this.
Is it ok to license this under the Expat version of the MIT license? Or is there a strong preference for GPLv3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said before, it's OK if it's compatible with GPLv3+.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, I'll make some changes to apply the appropriate licensing.
Sorry for being kind of slow to respond; I haven't been too good at keeping up with notifications recently.
The progress messages bloat the log and make it harder to search for the relevant part. The only case where they're even marginally useful is when checkout fails, as you can at least see how far it gets, but even then they don't really seem useful. Raised as a side issue in #3191
I mostly agree (even though I like/tolerate CMake). There's already been a lot of SWIG investment into autotools. Although it's better to discuss the topic in a different thread, there's only a few benefits with CMake that come to mind:
I'm not sure that these benefits outweigh the upfront conversion cost, however. |
… != 1 modified: .github/workflows/linux-cmake.yml modified: .github/workflows/windows-cmake.yml
I'm sure you can plot a better cons and pros. But I would like to reply to one point. The main focus of the autoconf is building the testing suite with different target languages with different compilers on different OSes. |
|
Let up put the number of tests we do today:
So you propose to potentiality improve 9 tests out of 136 tests, we do today. Hope you get the proportions. Erez |
At the very least, I don't think the MSVC tests have the same test coverage. E.g. the Windows CMake jobs only build SWIG, but don't build and run the large test suite that is available on the other compiler/OS combinations. CMake also supports the other listed systems in addition to native Windows using MSVC. |
The 9 test:
I did not imply CMake is limit in usage. |
|
It doesn't seem useful to continue to discuss cmake vs autotools here - it should already be clear we aren't going to switch the default. Let's focus on the patch here - tangential discussion only works against getting this merged. |
Background
SWIG's CMake build config makes it much simpler to build SWIG on Windows assuming an existing Bison and PCRE2 installation. PCRE2 10.38 and above provides a CMake config script, although only after the 10.45 release did this config script become idiomatic, i.e. using the CMake config helpers. These allow
find_packageto be used in the "standard" way instead of using find-module logic as provided inTools/cmake/FindPCRE2.cmake, e.g. with:We can also link against the PCRE2 8-bit library target as follows when necessary:
The upstream PCRE2 config script will correctly handle defining
PCRE2_STATICduring compilation.Changes
The changes are mostly to the
Tools/cmake/FindPCRE2.cmakefind module, which have the following logic:pcre2-[bitness]-staticPCRE2_USE_STATIC_LIBSis respected and if not defined on Windows, implicitly set toONPCRE2::8BITIMPORTEDlibrary target is defined byFindPCRE2.cmakeif necessarypcre2.h) and components passed tofind_packageare both checkedTesting
Both Linux (WSL1 Ubuntu 22.04 with GCC 11.3) and Windows (64-bit hosted CL.exe 19.36.32535) configurations have been tested with PCRE versions 10.45 and 10.46 built from source with CMake package config scripts. On WSL1 Linux PCRE version 10.39 was tested, which does not have CMake support and so exercises the manual search logic in
FindPCRE2.cmake.SWIG was built on both Linux and Windows with specific PCRE2 installation roots controlled by
PCRE2_ROOTappropriately, as well as using the system-installed PCRE 10.39 on WSL1 Linux. So a broad spectrum of use cases have been covered.Remarks
It would be great to have these patches merged into the mainline branch. I am also happy to update any relevant documentation pages so Windows users can have an easier build-from-source experience.