GoogleCloudPlatform / functions-framework-cpp

Functions Framework for C++
Apache License 2.0
48 stars 23 forks source link

vcpkg related build errors with example application #412

Open instw opened 1 month ago

instw commented 1 month ago

When following the instructions on https://github.com/GoogleCloudPlatform/functions-framework-cpp/blob/main/examples/site/howto_deploy_to_cloud_run/README.md , I consistently get errors-

[builder]   * vcpkg-cmake[core]:x64-linux -> 2022-09-26
[builder]   * vcpkg-cmake-config[core]:x64-linux -> 2022-02-06#1
[builder]   * vcpkg-cmake-get-vars[core]:x64-linux -> 2022-09-04
[builder] Additional packages (*) will be modified to complete this operation.
[builder] Detecting compiler hash for triplet x64-linux...
[builder] Installing 1/73 vcpkg-cmake:x64-linux...
[builder] Building vcpkg-cmake[core]:x64-linux...
[builder] -- Installing: /layers/google.cpp.functions-framework/vcpkg/packages/vcpkg-cmake_x64-linux/share/vcpkg-cmake/vcpkg_cmake_configure.cmake
[builder] -- Installing: /layers/google.cpp.functions-framework/vcpkg/packages/vcpkg-cmake_x64-linux/share/vcpkg-cmake/vcpkg_cmake_build.cmake
[builder] -- Installing: /layers/google.cpp.functions-framework/vcpkg/packages/vcpkg-cmake_x64-linux/share/vcpkg-cmake/vcpkg_cmake_install.cmake
[builder] -- Installing: /layers/google.cpp.functions-framework/vcpkg/packages/vcpkg-cmake_x64-linux/share/vcpkg-cmake/vcpkg-port-config.cmake
[builder] -- Installing: /layers/google.cpp.functions-framework/vcpkg/packages/vcpkg-cmake_x64-linux/share/vcpkg-cmake/copyright
[builder] Downloaded sources for vcpkg-cmake[core]:x64-linux
[builder] Elapsed time to handle vcpkg-cmake:x64-linux: 76.32 ms
[builder] Installing 2/73 vcpkg-cmake-config:x64-linux...
[builder] Building vcpkg-cmake-config[core]:x64-linux...
[builder] -- Installing: /layers/google.cpp.functions-framework/vcpkg/packages/vcpkg-cmake-config_x64-linux/share/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake
[builder] -- Installing: /layers/google.cpp.functions-framework/vcpkg/packages/vcpkg-cmake-config_x64-linux/share/vcpkg-cmake-config/vcpkg-port-config.cmake
[builder] -- Installing: /layers/google.cpp.functions-framework/vcpkg/packages/vcpkg-cmake-config_x64-linux/share/vcpkg-cmake-config/copyright
[builder] Downloaded sources for vcpkg-cmake-config[core]:x64-linux
[builder] Elapsed time to handle vcpkg-cmake-config:x64-linux: 72.74 ms
[builder] Installing 3/73 abseil:x64-linux...
[builder] Building abseil[core]:x64-linux...
[builder] -- Downloading https://github.com/abseil/abseil-cpp/archive/8c0b94e793a66495e0b1f34a5eb26bd7dc672db0.tar.gz -> abseil-abseil-cpp-8c0b94e793a66495e0b1f34a5eb26bd7dc672db0.tar.gz...
[builder] -- Extracting source /layers/google.cpp.functions-framework/vcpkg/downloads/abseil-abseil-cpp-8c0b94e793a66495e0b1f34a5eb26bd7dc672db0.tar.gz
[builder] -- Applying patch fix-cxx-standard.patch
[builder] -- Using source at /layers/google.cpp.functions-framework/vcpkg/buildtrees/abseil/src/d7dc672db0-d57dd8b3f8.clean
[builder] CMake Error at ports/abseil/portfile.cmake:25 (vcpkg_cmake_configure):
[builder]   Unknown CMake command "vcpkg_cmake_configure".
[builder] Call Stack (most recent call first):
[builder]   scripts/ports.cmake:147 (include)
...

The errors prevent vcpkg from download the dependencies correctly, causing the build to fail.

dbolduc commented 1 month ago

Hey, thanks for the bug report. I can reproduce the bug locally. Something went stale, but I am not sure what.

I am not an expert here. I also do not have a lot of time to spend on this, but maybe I can help unblock you.

Unblock

This will use a custom builder (the one we use to run our CI) to build the example.

Update Buildpack API

I saved this as update-api.patch:

diff --git a/ci/pack/buildpack/bin/build b/ci/pack/buildpack/bin/build
index dce67dd..2b78319 100755
--- a/ci/pack/buildpack/bin/build
+++ b/ci/pack/buildpack/bin/build
@@ -42,6 +42,7 @@ set(VCPKG_TARGET_ARCHITECTURE x64)
 _EOF_
   cp -r /usr/local/bin/vcpkg "${VCPKG_ROOT}"
 cat >"${layers}/vcpkg.toml" <<_EOF_
+[types]
 build = true
 cache = true
 launch = false
@@ -52,6 +53,7 @@ if [[ ! -d "${layers}/vcpkg-cache" ]]; then
   echo "-----> Restore cache from build image"
   cp -r /var/cache/vcpkg-cache "${layers}/vcpkg-cache"
 cat >"${layers}/vcpkg-cache.toml" <<_EOF_
+[types]
 build = true
 cache = true
 launch = false
@@ -60,6 +62,7 @@ fi

 echo "-----> Setup build directory"
 cat >"${layers}/source.toml" <<_EOF_
+[types]
 build = true
 cache = false
 launch = false
@@ -261,6 +264,7 @@ generate_main \

 echo "-----> Configure Function"
 cat >"${layers}/binary.toml" <<_EOF_
+[types]
 build = true
 cache = true
 launch = false
@@ -275,6 +279,7 @@ _EOF_
 /usr/local/bin/cmake --build "${layers}/binary" --target install

 cat >"${layers}/local.toml" <<_EOF_
+[types]
 launch = true
 cache = false
 build = false
@@ -283,5 +288,5 @@ _EOF_
 cat >"${layers}/launch.toml" <<_EOF_
 [[processes]]
 type = "web"
-command = "${layers}/local/bin/function"
+command = ["${layers}/local/bin/function"]
 _EOF_
diff --git a/ci/pack/buildpack/buildpack.toml b/ci/pack/buildpack/buildpack.toml
index 8dee294..5a74931 100644
--- a/ci/pack/buildpack/buildpack.toml
+++ b/ci/pack/buildpack/buildpack.toml
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.

-api = "0.2"
+api = "0.10"

 [buildpack]
 id = "com.google.buildpack.cpp"

then ran the following from the root of the repo, on the main branch:

git apply update-api.patch

Update the builder

Create the build images

docker build -t ci-build-image --target gcf-cpp-ci -f build_scripts/Dockerfile .
docker build -t ci-run-image --target gcf-cpp-runtime -f build_scripts/Dockerfile build_scripts

Create the builder

pack builder create gcf-cpp-builder:bionic --config ci/pack/builder.toml
pack config trusted-builders add gcf-cpp-builder:bionic

Run the original command, but with the new builder

GOOGLE_CLOUD_PROJECT=... # put the right value here
pack build \
    --builder gcf-cpp-builder:bionic \
    --env GOOGLE_FUNCTION_TARGET=hello_world_http \
    --path examples/site/hello_world_http \
   "gcr.io/${GOOGLE_CLOUD_PROJECT}/gcf-cpp-hello-world-http"

If you were looking for a real fix, let me know, and I can try to prioritize the work.