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

build as an installable package and use vcpkg manifest mode to build standalone #1026

Open
wants to merge 50 commits into
base: main
Choose a base branch
from

Conversation

timoore
Copy link
Contributor

@timoore timoore commented Dec 5, 2024

This PR has several moving parts:

  • Package files for cesium-native created on installation. Any hackery needed to create targets for external targets is moved to CMake Find modules that are installed with the package files.
  • A single vcpkg overlay port for asycplusplus
  • vcpkg.json and vcpkg-configuration.json
  • A CMakePresets.json file demonstrating how to do a manifest mode bulid.

I'm using this branch to build vsgCs using cesium-native as a vcpkg overlay port. That usage needs to be documented here too. Also, while I've tried to preserve the old behavior using exvcpkg, I haven't tested this yet with Cesium for Unreal and other integrations in the classic style of using cesium-native as a CMake subdirectory.

This is basically the addition of the vcpkg.json manifest and
vcpkg-configuration.json, which are both pretty minimal. In practice,
projects will probably copy those and add overlays.
Should be a no-op at this point, but will be required when we make
Cesium Native installable.
The intent is for public target sources to be compiled into consumers
of a target, but that is a no-op for header files. Including the
public headers, which have paths pointing inside the project, causes
an error when generating an export set.
This create the CMake files that create targets in an imported
package.
Add a find module for zlib-ng, which can be installed and included by
a config package. Other find modules may be necessary too.
VCPKG_MANIFEST_MODE isn't available before project() is called, so
define a new variable CESIUM_USE_EZVCPKG to control the early
loading of ezvcpkg.
Individual integrations can add their own overlay if they need it.
Also, try to make sure that vcpkg actually uses the desired triplet.
@azrogers
Copy link
Contributor

azrogers commented Dec 9, 2024

Looks like this causes the following issue in cesium-unreal:

  CMake Error at cesium-native/cmake_install.cmake:940 (file):
    file cannot create directory:
    C:/Dev/prs/cesium-native-1026/Plugins/cesium-unreal/extern/../Source/ThirdParty/lib/Windows-AMD64-$<IF:$<CONFIG:Debug>,Debug,Release>/cmake/cesium-native.
    Maybe need administrative privileges.
  Call Stack (most recent call first):
    cmake_install.cmake:37 (include)

Not sure why this would have broken here - the cesium-unreal/extern CMakeLists.txt is unchanged here and I don't see why the CONFIG generator expression would stop evaluating correctly here.

@timoore
Copy link
Contributor Author

timoore commented Dec 9, 2024

Thanks for being brave enough to test this with Cesium Unreal! What generator was used to build cesium-native?

@timoore
Copy link
Contributor Author

timoore commented Dec 10, 2024

The problem is in the new cesium-native/CMakeLists.txt, which defines exports to install. The install(EXPORT...) command doesn't support generator expressions in its destination argument... which makes a certain amount of sense, even if it's inconsistent. The export files won't be used in the Unreal build, but I'll change the command to use a more suitable variable.

In the Cesium for Unreal build, CMAKE_INSTALL_LIBDIR contains
a generator expression, which the install(EXPORT ...) command doesn't
process correctly. So, install the configuration files such as
"cesium-nativeTargets.cmake" in
${CMAKE_INSTALL_DATADIR}/cesium-native/cmake, which is a perfectly
fine location.

These files aren't used by the Cesium Unreal build anyway.
@timoore
Copy link
Contributor Author

timoore commented Jan 6, 2025

I've started to look at how to use this in cesium-unreal and have hit a bit of a sticking point with specifying the MSVC toolset version to build those parts of cesium-unreal/extern that wouldn't be vcpkg port overlays. Maybe this isn't a real issue, because I think the GitHub build action would work the same. It's really only a problem for developers who have multiple toolsets installed. It is possible to set the toolset version through CMakePresets.json, and on the command line, but otherwise it is really obscure. Do you think this is worth worrying about?

Just to be clear, this isn't a new problem that comes with vcpkg manifest mode.

@2xsaiko
Copy link

2xsaiko commented Jan 11, 2025

I've been trying to package this (Homebrew for now, later Gentoo) so I can use it as a dependency for vsgCs which I want to use in something I'm working on, however right now it seems pretty much impossible to do so without significantly changing the build files. This patchset looks like it could improve that, however with this it fails to even configure in the Homebrew build environment:

error: In manifest mode, vcpkg install does not support individual package arguments.

https://gist.github.com/2xsaiko/9d2bc0691529d2599e2d43d8cf7e8ec5

Strangely enough, this error doesn't occur when running it outside of the Homebrew package. Any ideas?

@timoore
Copy link
Contributor Author

timoore commented Jan 11, 2025

I've been trying to package this (Homebrew for now, later Gentoo) so I can use it as a dependency for vsgCs which I want to use in something I'm working on, however right now it seems pretty much impossible to do so without significantly changing the build files. This patchset looks like it could improve that, however with this it fails to even configure in the Homebrew build environment:

error: In manifest mode, vcpkg install does not support individual package arguments.

https://gist.github.com/2xsaiko/9d2bc0691529d2599e2d43d8cf7e8ec5

Strangely enough, this error doesn't occur when running it outside of the Homebrew package. Any ideas?

The vcpkg-build branch in vsgCs uses a commit to a personal copy of Cesium Native -- sucked in as a vcpkg port overlay -- that was the basis of this PR and is very close to it. I encourage you to give that a try.

In your build that is crashing, it looks like the ezvcpkg code is getting confused by the vcpkg.json mainifest file and is then going into manifset mode. This is interesting as I would like to keep ezvcpkg working for a while, but for experimenting with this PR you probably want to specify CESIUM_USE_EZVCPKG=OFF.

@timoore
Copy link
Contributor Author

timoore commented Feb 28, 2025

Sorry @timoore I'm not really comfortable merging this before next week's release. I haven't reviewed it in depth, but one problem I see is that the CI build times are drastically increased. I think the caching isn't working anymore. Let's aim to get it in as soon after next week's release as we can, and we can even tag a mid-cycle native release if it's helpful.

The cache management page for cesium-native says:
Approaching total cache storage limit (16.74 GB of 10 GB Used)

This PR creates new caches for the VCPKG builds that are probably no smaller than the caches for ezvcpkg. I don't think that the caches for this PR are being kept around (or are even being created), and I wouldn't be surprised if caching for all the builds is being affected.

@timoore
Copy link
Contributor Author

timoore commented Feb 28, 2025

I've tried to set up vcpkg caching with S3, but I'm getting a spew of errors like:

warning: error: aws failed with exit code: (254).

An error occurred (AccessDenied) when calling the ListObjectsV2 operation: Access Denied

so I clearly don't know what I'm doing.

@kring kring added this to the April 2025 Release milestone Mar 26, 2025
@kring
Copy link
Member

kring commented Mar 26, 2025

@timoore I checked out a clean copy of this branch and ran this on my Windows machine:

cmake -B build -S .

And it seems to run ezvcpkg as normal and then also run some other vcpkg process with a different triplet.

PS C:\cesium\cesium-native> cmake -B build -S .
-- Building for: Visual Studio 17 2022
-- VCPKG_TRIPLET x64-windows-static-md
-- VCPKG_TARGET_TRIPLET
-- VCPKG_OVERLAY_PORTS C:/cesium/cesium-native/extern/vcpkg/ports
-- VCPKG_OVERLAY_TRIPLETS
-- EZVCPKG v0.1 starting up
        Website: https://github.com/jherico/ezvcpkg
-- EZVCPKG initializing
        commit:     2024.11.16
        repository: https://github.com/microsoft/vcpkg.git
        local dir:  f:/.ezvcpkg/2024.11.16
-- EZVCPKG Building/Verifying package asyncplusplus using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package expected-lite using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package fmt using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package glm using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package rapidjson using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package spdlog using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package stb using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package ada-url using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package abseil using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package draco using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package ktx using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package modp-base64 using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package meshoptimizer using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package openssl using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package s2geometry using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package libjpeg-turbo using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package sqlite3 using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package tinyxml2 using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package libwebp using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package zlib-ng using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package picosha2 using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package earcut-hpp using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package cpp-httplib[core] using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package libmorton using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package zstd using triplet x64-windows-static-md
-- EZVCPKG Building/Verifying package doctest using triplet x64-windows-static-md
-- EZVCPKG done
-- CMAKE_TOOLCHAIN_FILE f:/.ezvcpkg/2024.11.16/scripts/buildsystems/vcpkg.cmake
CMake Deprecation Warning at F:/.ezvcpkg/2024.11.16/scripts/buildsystems/vcpkg.cmake:40 (cmake_policy):
  Compatibility with CMake < 3.10 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.31/Modules/CMakeDetermineSystem.cmake:146 (include)
  CMakeLists.txt:119 (project)


-- Running vcpkg install
Fetching registry information from https://github.com/microsoft/vcpkg (HEAD)...
Detecting compiler hash for triplet x64-windows...
Compiler found: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.42.34433/bin/Hostx64/x64/cl.exe
The following packages will be built and installed:
  * abseil:[email protected] -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\95ed5fee53b8698ac2cc6687f470e6fa76474a3a
    ada-url:[email protected] -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\ca729da9e664e3a59d88115c9e8a8d59b775801c
    asyncplusplus:[email protected]#2 -- C:\cesium\cesium-native\./vcpkg-overlays\asyncplusplus
  * brotli:[email protected]#1 -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\4e5b5ae1ad26c80535c893cc0307121f0398549e
    cpp-httplib[brotli,core]:[email protected] -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\22ef6ccb262c5a3a835b39278d4800035a967a94
    doctest:[email protected] -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\619b544477f70ef777fcc294e0b31650e2bd4c05
    draco:[email protected] -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\06799add74da6e9e4634e4c7f27b82b1149a8bb6
    earcut-hpp:[email protected] -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\f4f99272400624124150cb485899cdc3efb24313
    expected-lite:[email protected] -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\ffed518a0067b94d369307cc869b46263bbcd976
  * fmt:[email protected]#1 -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\07a73a7565e5de9eb42e90c16c133bdfdfebbcda
    glm:[email protected]#3 -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\f8b09027afe97c717e95bd81d1d4f37c057d1c78
    ktx:[email protected] -- C:/cesium/cesium-native/extern/vcpkg/ports\ktx
    libjpeg-turbo:[email protected] -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\fbedc8ef954f9951c7d169c9bac3f9534b4b2c77
    libmorton:[email protected] -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\6f00ce462ab2d581aa3d0bb33c2ff37ff745377c
    libwebp[core,libwebpmux,nearlossless,simd,unicode]:[email protected]#1 -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\9d0c00119dd6ec04488b4e0c926aa3ae73b95847
    meshoptimizer:[email protected] -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\9ff504432cfa14706fac154ca9c490a3df9922f8
    modp-base64:x64-windows@2020-09-26#2 -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\85f2a557b0fdca31efb6e9e6c769309d583ea2a3
    ms-gsl:[email protected] -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\d71696a526519c3f680b1b77e87d39f8eb94e650
    openssl:[email protected] -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\ce504a83eb9627d54f1cffdb497a6bf5bd970d18
    picosha2:x64-windows@2018-07-30#2 -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\c873a8748f3e35ae1be390b0de9cc3754191c987
    rapidjson:x64-windows@2023-07-17#1 -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\a3dfe7dca3a1a27564b1fc5a9aea657cd9dae01c
    s2geometry:[email protected] -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\3fd94490409a17aef62732c674d5e12b4804fdd8
    spdlog:[email protected] -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\545d0306db761411e23623ae6f44fc196cb571f7
    sqlite3[core,json1]:[email protected]#2 -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\543d6067a10a7ab97a4893997afaee4d34230a27
    stb:x64-windows@2024-07-29#1 -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\c362152d1d02973e7b1ce777960f8a6876656560
    tinyxml2:[email protected] -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\e7763e8defdfa46b8d2e399756511f0c7ff00448
  * vcpkg-cmake:x64-windows@2024-04-23 -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\e74aa1e8f93278a8e71372f1fa08c3df420eb840
  * vcpkg-cmake-config:x64-windows@2024-05-23 -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\97a63e4bc1a17422ffe4eff71da53b4b561a7841
  * vcpkg-cmake-get-vars:x64-windows@2024-09-22 -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\f23148add155147f3d95ae622d3b0031beb25acf
    zlib-ng:[email protected]#1 -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\3f7c39c070cb4f55a281ebe3a178b4f7e896dea8
    zstd:[email protected] -- C:\Users\kevin\AppData\Local\vcpkg\registries\git-trees\796171d4d359b6786b8e1380fb6da8e677a9087b
Additional packages (*) will be modified to complete this operation.
Restored 11 package(s) from C:\Users\kevin\AppData\Local\vcpkg\archives in 568 ms. Use --debug to see more details.
Installing 1/31 vcpkg-cmake-config:x64-windows@2024-05-23...
Elapsed time to handle vcpkg-cmake-config:x64-windows: 19.2 ms
vcpkg-cmake-config:x64-windows package ABI: eb83882cb50f9ebd78ad85880e437c0acbc0e7110d9ae1741b7663cf22f187af
Installing 2/31 vcpkg-cmake:x64-windows@2024-04-23...
Elapsed time to handle vcpkg-cmake:x64-windows: 9.81 ms
vcpkg-cmake:x64-windows package ABI: c9a09eb622adac56e4988734885488bd1ae3c275dca9df8c825038943ff9e0b2
Installing 3/31 ada-url:[email protected]...

(log continues after that, installing more packages)

I guess my mistake is that I'm not using the cmake preset that disables ezvcpkg. But ezvcpkg should still be a valid option at this point, right?

@kring
Copy link
Member

kring commented Mar 26, 2025

The same happens on macOS, but at least there the triplets are the same (arm64-osx in both cases). But it's still spending a bunch of time compiling packages for unclear reasons.

@timoore
Copy link
Contributor Author

timoore commented Mar 27, 2025

ezvcpkg should be the default if you don't use any of the presets that invoke vcpkg in manifest mode i.e., that load vcpkg.cmake as a toolchain file; I will investigate.

I've tried to keep vcpkg manifest mode stuff out of cesium-native's own cmake machinery as much as possible, which means that using it involves passing a bunch of options to cmake or using my handy presets. I would really like cesium-native's build to be agnostic (not care?) about how its dependencies are satisfied.

@timoore
Copy link
Contributor Author

timoore commented Mar 27, 2025

After looking at this for "a while," I believe that it's normal that vcpkg.cmake is running again (several times in my experiments). vcpkg abuses the CMake toolchain file, which can be run multiple times during configuration as CMake configures different things. This PR includes new CMake targets etc., which I believe is the cause of more configuration "runs" than in the old code.

It is concerning that the triplet used for the subsequent runs of vcpkg is different from the first; I think I know what's up with that and will amend the PR.

@timoore
Copy link
Contributor Author

timoore commented Mar 28, 2025

@kring The behavior you were seeing was caused by vcpkg getting invoked in manfest mode even when managed by ezvcpkg. Once vcpkg.cmake is established as the toolchain file, which ezvcpkg does, it will run in manifest mode if it finds vcpkg.json, which is now a part of the source tree... unless told otherwise, which I have now done, politely but firmly.

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

Successfully merging this pull request may close these issues.

5 participants