-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Cmake: use ENV{VCPKG_ROOT}, fix msgfmt + minor. #3685
base: main
Are you sure you want to change the base?
Conversation
156fa9a
to
d550c77
Compare
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.
Thank you for your contribution, it's a lot of changes!
Also, those changes that are logically separate from each other should be packed into their own commit, each with a commit message that motivates the change. In other words, this commit should be split into multiple commits.
May I ask you to do that, and then force-push?
No problem, I will do that. |
It looks like the commit could be split by
The commit messages themselves should include a statement of the problem that is being solved, e.g. that devs cannot use their your own VCPKG tree... (borrowed from the cmake comment). Looks good. |
ebd1ae9
to
2abf6a4
Compare
Hmm. I don't see that the force-pushed versions separate the individual concerns properly. Instead, I see even more concerns crammed into that poor single commit. That's kind of the diametrical opposite of what I would like to see. |
Sorry, I am trying to do some cleanups before I separate the commits. Then I will do a bisect and make sure they all work individually. |
I see that you added two non-trivial CMake files, and cannot help but wonder why we would need those. It does not strike me as a clean-up to add them when the code before that seemed to work all right. And before any clean-ups, I would have hoped that the relatively consistent (and therefore probably not flaky) test failures would be addressed. See e.g. https://github.com/git-for-windows/git/runs/5085425240?check_suite_focus=true#step:6:862 |
There are no changes to the source code or any of the libraries used, I don't see how any git test failures could be related to this. But I will compare to master to make sure. |
2abf6a4
to
b8d2ed4
Compare
Any way, please give me a few more days. |
Sure, but why trigger new builds by these frequent force-pushes, unless you want people to see what you pushed? |
You might also want to convert the PR to a draft, to indicate that it's not ready for review. |
No problem, I have converted to draft and I will push to a different branch until it's ready. |
b8d2ed4
to
d7901d9
Compare
I've split the commits and I ran this script with this data file to check that they all work with a standard build.
$erroractionpreference = 'stop'
foreach($commit in (gc commits.txt)) {
$build_dir = "build-$commit"
git reset --hard $commit
ri -r $build_dir -ea ignore
mkdir $build_dir | out-null
pushd $build_dir
cmake ../contrib/buildsystems -G Ninja
ninja
if (-not (test-path git.exe)) {
write-error "Building $commit failed." -ea stop
}
popd
}
"ALL COMMITS BUILT SUCCESSFULLY"
007ec82335
7609d16562
5fc1f867a1
038021aa79
f86b59bfaf
f012bee432
d86a13b871
9a1520e870
ce892f8f0b
0c5cb9f661
ab80c468f9
fc219be592
6abf886de4
580397f0a2
2f4c48c77b
a21b05fbcc
319740f140
d7901d9651 |
Hi Rafael, I fetched your changes via
A few specifics
When I tried to open the checked out Have you seen the same issue? A bit of searching found some MS Visual Studio Articles, Partial Acivation and the Open Folder support. I.e. the I think it implies that the current use of a Aside: does the |
Hi @PhilipOakley, thank you for the detailed response. I should be able to take care of most of this over the next few days. This is also great practice for me, I need to learn how to do things like this for more serious projects and your feedback is very helpful. I used to have better commit discipline. I will respond to some things you brought up below.
I can do that, but I see no practical purpose for this other than someone having a philosophical objection to NuGet. The whole operation of downloading
I do not use the VS IDE much, I use PowerShell with the build tools mostly, but I did in fact try to play with this because having a root If I make a root A symlink may work, with some code adjustments, this would require the developer to have developer mode enabled to get a real symlink in a clone, I think this is a reasonable assumption to make. There are probably other ways to make opening the project in VS automatically work, like Let me know what you would like to do, and if you have any other ideas, and I will address this in a separate PR.
I haven't even tried opening this in the IDE and/or running any of the tests, because my changes do not affect any of the tests, but I'll try to take a look. |
I don't know actually, I think it failed for me once, but I'll just reword this to "improve." |
I am using 2022 as of recently, before I used 2019, which is pretty much the same as far as these things go, and Ninja (on Windows the other generators are useless anyway.) This doesn't affect anything anyway, it simply allows the dev to use |
d7901d9
to
2ae6d98
Compare
If you mean the status message, I removed it and amended the "installing libraries" status message in the cmd script. |
I fixed all the titles according to the guidelines and proofread and reworded all the messages, and made a couple minor code changes.
Here are the new shas: 2ae6d985a6 build: use NuGet Gettext.Tools for msgfmt on WIN32
e68ce8a972 build: add nuget_install() in cmake/NuGet.cmake
b4238e47ee build: alias VCPKG_ROOT env variable to VCPKG_DIR
5830df7273 build: alias VCPKG_TARGET_TRIPLET to VCPKG_ARCH
1b27531077 build: add build_option() to cmake/Utilities.cmake
1e78440a7e build: always call vcpkg_install.bat from cmake
eff19a789f build: fix check for VCPKG_ARCH
257bee85c5 build: use VCPKG_DIR instead of constant
84535ba93a build: remove msgs for uninitialized cmake vars.
1fc9635af8 build: add workdir to CreateLinks.cmake call
c6f543a665 build: add vim modeline to CMakeLists.txt
59e02a0327 doc: correct NO_VCPKG to USE_VCPKG
099888bf7d build: support VCPKG_ROOT env in vcpkg_install.bat
a180f08de9 build: error/usage to stderr in vcpkg_install.bat
91c80f5889 build: reformat git check in vcpkg_install.bat
9f2ea77890 build: improve check for built vcpkg.exe
db74125d99 build: add -static triplets in vcpkg_install usage
08fc0814ba build: ignore build*/ for out-of-source 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.
This was a really pleasant read!
My only objection is that we do not need to go back to NuGet to get the gettext
package, we can use vcpkg
for that (see the comments below).
Also, really, really crucial: please do not require msgfmt.exe
if the user specifically asked for NO_GETTEXT
.
Once those two things are addressed, I am happy to merge this PR!
contrib/buildsystems/CMakeLists.txt
Outdated
if(NOT MSGFMT_EXE) | ||
if(WIN32) | ||
include(NuGet) | ||
nuget_install(Gettext.Tools) |
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 wonder whether we can get a similar effect, albeit without having to use NuGet (which works very well for .NET projects but not well at all for C/C++ projects), if we used vcpkg
for that? It does have the gettext
package, after all.
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.
NuGet is also used for build tools and utilities for various purposes.
I thought about using vcpkg for this, and you can build gettext[tools]
to get msgfmt
. However, gettext is a very long compile, and in this case we just want a utility not a link library, so I thought this would be a better way to go. I use this method in another project.
However, if you want to support one or the other or both I can do that.
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'd rather not mix and match vcpkg
and NuGet.
If you are really, really concerned, we can teach this Azure Pipeline to build gettext[tools]
(or just gettext
?) and offer it together with the other build artifacts.
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.
FWIW this Pipeline simply runs:
& compat/vcbuild/vcpkg_install.bat
if (!$?) { exit(1); }
& compat/vcbuild/vcpkg_install.bat arm64-windows
if (!$?) { exit(1); }
git init vcbuild-artifacts\compat\vcbuild\vcpkg
if (!$?) { exit(1); }
Copy-Item compat\vcbuild\vcpkg\vcpkg.exe vcbuild-artifacts\compat\vcbuild\vcpkg -Force
if (!$?) { exit(1); }
Copy-Item compat\vcbuild\vcpkg\installed vcbuild-artifacts\compat\vcbuild\vcpkg -Force -Recurse
if (!$?) { exit(1); }
Copy-Item compat\vcbuild\vcpkg\packages vcbuild-artifacts\compat\vcbuild\vcpkg -Force -Recurse
if (!$?) { exit(1); }
# Copy-Item compat\vcbuild\vcpkg\scripts vcbuild-artifacts\compat\vcbuild\vcpkg -Force -Recurse
# if (!$?) { exit(1); }
# Remove manual pages (they are not used, and only bloat the artifact)
Get-ChildItem vcbuild-artifacts\compat\vcbuild\vcpkg html -recurse -directory | ForEach-Object {Remove-Item $_.FullName -Recurse -Force}
if (!$?) { exit(1); }
Therefore we would probably need to handle NO_GETTEXT
in vcpkg_install.bat
, too: if it is set, do what we do right now. If it is not set, include gettext
in the build.
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.
My concern is making life less painful for contributors, when I say that gettext is a really long compile, I mean approximately half an hour on a typical system or more.
In my other vcpkg project, some of my contributors refused to use the VS support at all because of the long compile times.
But up to you.
This is a problem with vcpkg in general. Many people use Conan instead which has binary packages. I am planning to add Conan support to the other project I mentioned.
Speaking of compile times in a CI, vcpkg supports a new feature called binary caching: https://vcpkg.readthedocs.io/en/stable/users/binarycaching/
we would probably need to handle NO_GETTEXT in vcpkg_install.bat
For the purposes of this PR, I can just export this as an env var.
But this script needs some enhancements in general, like upgrading vcpkg itself and all dependencies.
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 just verified that locales definitely DO NOT work for MSVC
builds, even though translations are built now.
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 going to work on this possibly a few days more. It seems translations are not working on MSVC
builds and there are a few other minor details to clean up.
Let me know your thoughts on the other points I brought up.
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 meant to post that as a main comment, so include those as well.
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 what GIT-BUILD-OPTIONS is used for
GIT-BUILD-OPTIONS
is used e.g. in the test suite (e.g. to skip the translation-related tests).
I'm going to work on this possibly a few days more. It seems translations are not working on MSVC builds and there are a few other minor details to clean up.
Yes, let's focus on the common case where we simply won't need the translations.
If MSGFMT_EXE is set, then translations are built, nothing else controls this, the NO_GETTEXT variable has no effect on this.
That looks like a bug to me. I would really like to avoid even looking for MSGFMT_EXE
if NO_GETTEXT
is set to TRUE
, and if NO_GETTEXT
is not set and msgfmt
cannot be found, I want NO_GETTEXT
to be set to TRUE
.
In any case, I want the translations not to be built when NO_GETTEXT
is set to TRUE
.
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.
Could you please remove the need for NuGet, by respecting NO_GETTEXT to imply that MSGFMT_EXE is not needed?
@dscho fixing the other two things right now, see my comment above re: NuGet. |
2ae6d98
to
44fe965
Compare
If %VCPKG_ROOT% environment variable is set, check that the parent directory exists and throw an error if it does not. If %VCPKG_ROOT% is not set, set it to %cwd%\vcpkg, which was the previous behavior. Change all references to %cwd%\vcpkg to %VCPKG_ROOT%. Change the documentation in the top comment to refer to %VCPKG_ROOT%. This allows a developer to maintain his or her own vcpkg clone and not have to unnecessarily repeat the very time-consuming process of compiling the dependencies. Set ENV{VCPKG_ROOT} to the VCPKG_DIR default in CMakeLists.txt, because the cmake code does not support this yet, this is introduced in a subsequent commit. Signed-off-by: Rafael Kitover <[email protected]>
USE_VCPKG is the current variable used to disable vcpkg. Signed-off-by: Rafael Kitover <[email protected]>
Signed-off-by: Rafael Kitover <[email protected]>
Add WORKING_DIRECTORY to the add_custom_command() call that launches CreateLinks.cmake, which is a script that creates some hard links to built git executables. This allows the script to not fail for build directories other than the default. Signed-off-by: Rafael Kitover <[email protected]>
Stop displaying the variables MSVC, CMAKE_CXX_COMPILER_ID, CMAKE_GENERATOR_PLATFORM in the vcpkg setup section, as this section runs before project() and they are not yet initialized. Instead display them after the project() call, and use CMAKE_C_COMPILER_ID instead of CMAKE_CXX_COMPILER_ID as this is a C project. Also change all variable log message() calls to message(STATUS ...) calls. Signed-off-by: Rafael Kitover <[email protected]>
Use VCPKG_DIR instead of relative path to the default vcpkg clone for appending the vcpkg bin to PATH when writing GIT-BUILD-OPTIONS in cmake. Signed-off-by: Rafael Kitover <[email protected]>
Use DEFINED instead of EXISTS (EXISTS is for checking if a filesystem path exists, DEFINED is for variables.) Also move the check to above the call to vcpkg_install.bat where it is used from its previous location below. Signed-off-by: Rafael Kitover <[email protected]>
Instead of checking if VCPKG_DIR exists first, always call vcpkg_install.bat, which will create a new vcpkg clone as well as perform any necessary actions on an existing clone, and will do nothing if nothing needs to be done. Remove the "Initializing vcpkg..." message from cmake and change the "installing libraries" message from the cmd script to say that it may take a while. Signed-off-by: Rafael Kitover <[email protected]>
4aeb5bb
to
92cbe2d
Compare
Hi guys I finished some cleanup of all of this, but, I cannot , for the life of me, figure out how to use one of the generated Can I please have some hints about how to test this? |
92cbe2d
to
d45e16c
Compare
Nice! I meant to reply that you can set |
endforeach() | ||
endfunction() | ||
|
||
# vim:set sw=8 ts=8 noet: |
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.
That's quite the addition for but a single user... Is there actually a need for this, apart from a mere preference for a documented option?
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 did this to make aliasing options and env vars cleaner, it otherwise behaves almost the same way as the cmake built-in option(...)
.
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.
Updated the docs and commit message.
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.
It just adds a lot of code, and I am not sure that the benefit justifies that much.
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 can remove it and do this manually if you like, but it would be a big ugly chain of if
blocks, because the functions handles all aliases in order of precedence.
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 honestly do not see enough value in that function to invest some 100 new lines of code in it, not even if I am "only" stuck with maintaining them.
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.
In other words: I would prefer the flags to be specified via explicit command-line arguments to cmake
, and not implicitly via some environment variables.
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 whole point of all of this was to read VCPKG_ROOT
from the environment implicitly. It's a documented variable:
https://vcpkg.readthedocs.io/en/latest/users/config-environment/
cmake uses other environment variables implicitly too, like CC
/CXX
.
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.
@dscho I have a flight to catch tomorrow and need to pack, I will adjust everything as per your preferences over the next few days hopefully, and follow up on the manifest issue.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Add the build_option() function which is similar to the cmake option() command, but allows adding alias variables and alias environment variables. The option and all aliases are set to the first found value by listed sequence in the option and all aliases, followed by the default if provided, or 'OFF' if not provided, with cache variables having precedence over normal variables. In the case of environment variables or aliases, if the type is BOOL and the found/default value is OFF/FALSE unset the environment variable. Signed-off-by: Rafael Kitover <[email protected]>
Include the build_option() function introduced in b0d325d4bd (Add build_option() to cmake/Utilities.cmake., 2022-02-10). Initialize VCPKG_ARCH with an alias to VCPKG_TARGET_TRIPLET with build_option(). Add a note about this to the cmake doc. Signed-off-by: Rafael Kitover <[email protected]>
Use the build_option() function introduced in 3db0658 (build: add build_option() to cmake/Utilities.cmake, 2022-02-10) to alias the VCPKG_ROOT environment variable to VCPKG_DIR. Support for VCPKG_ROOT was added to vcpkg_install.bat in 98c6a0d (build: support VCPKG_ROOT env in vcpkg_install.bat, 2022-02-08). Add a note about VCPKG_DIR and ENV{VCPKG_ROOT} to the cmake doc. Signed-off-by: Rafael Kitover <[email protected]>
Check if NO_<dep> environment variable is defined to skip vcpkg deps, this is needed to implement cmake support for NO_GETTEXT properly in a subsequent commit. Signed-off-by: Rafael Kitover <[email protected]>
Add gettext vcpkg dependency lib with the [tools] feature for the msgfmt utility to build the translations. Can be disabled by setting the NO_GETTEXT environment variable, support for which was added in 2cd6269 (build: support NO_LIB env to disable vcpkg deps, 2022-03-17). Signed-off-by: Rafael Kitover <[email protected]>
d45e16c
to
1baa10b
Compare
Make NO_GETTEXT a build option aliased to ENV{NO_GETTEXT} to pass to vcpkg_install.bat to skip building gettext. Turn it off by default when vcpkg is in-use because it's a very long compile. Do not build translations if NO_GETTEXT is set. Add a note about NO_GETTEXT to the docs at the top of CMakeLists.txt. Signed-off-by: Rafael Kitover <[email protected]>
1baa10b
to
5292199
Compare
I'd like to summarize what this PR contains currently and hopefully finish whatever is necessary to get it merged. Motivations:
Improvements to
Improvements to
I can remove the Please let me know how you'd like to proceed. |
@dscho Awaiting your feedback, see post above. I put a lot of work into this and would like to finish it, as I said I will make any changes you want. |
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.
(invalid, please ignore)
endforeach() | ||
endfunction() | ||
|
||
# vim:set sw=8 ts=8 noet: |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
I have too much on my plate, and will be mostly offline this coming week, so this PR will have to wait at least for another week. |
No problem, thanks! |
@dscho Hi, any chance you could take a look at this? |
Set VCPKG_DIR from ENV{VCPKG_ROOT} if set, otherwise set
ENV{VCPKG_ROOT}.
Set VCPKG_ARCH from VCPKG_TARGET_TRIPLET if set.
Fix check for VCPKG_ARCH being defined.
Describe options in comment at the top of the file.
Add build*/ out-of-source build dirs to toplevel .gitignore.
Change vcpkg_install.bat to use %VCPKG_ROOT% set by cmake or present in
the environment, and update/install only what's necessary.
Use Gettext.Tools from nuget on Windows for msgfmt.
Fix cmake hardlinking script invocation by adding WORKING_DIRECTORY.
Signed-off-by: Rafael Kitover [email protected]