I’m trying to deploy a C++ service on Google Cloud Run which uses some JUCE modules (e.g. juce_core, juce_cryptography, etc). I’m following this guide very closely: Quickstart: Deploy a C++ service to Cloud Run | Cloud Run Documentation | Google Cloud
So far, I setup the project as per the guide and got things running. Then, I added JUCE as a submodule inside the project folder, and tried adding JUCE to CMakeLists.txt using target_link_libraries (shown below). However, I am getting errors while building the juceaide:
"ft2build.h: No such file or directory"
"X11/Xlib.h: No such file or directory"
Also, this error happens in a few places:
/v/source/Modules/juce/modules/juce_core/native/juce_linux_SystemStats.cpp:216:28:
#12 415.2 error: '_NL_IDENTIFICATION_TERRITORY' was not declared in this scope
To solve this issue, I’m wondering if I need to use juce_add_console_app
in CMakeLists.txt, or make any other changes there?
Another thought: some Linux dependencies may be missing, so I’ve tried adding a few libraries mentioned in the JUCE docs Linux dependencies (see under Dockerfile line RUN apk update
what I added). Google Cloud Run Linux distro is Alpine, not Ubuntu, so seem to be some differences in package names.
Finally, I could also try disabling some dependencies I don’t need in CMakeLists.txt using
target_compile_definitions (...
PUBLIC
JUCE_WEB_BROWSER=0
JUCE_USE_CURL=0
etc
Anyway, any ideas or suggestions appreciated! Below are the referenced source files:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.20)
project(cpp-samples-cloud-run-hello-world CXX)
add_subdirectory(Modules/juce)
# I added this:
set(JUCE_DEPENDENCIES
juce::juce_core
juce::juce_cryptography
juce::juce_data_structures
juce::juce_events
juce::product_unlocking
)
find_package(functions_framework_cpp REQUIRED)
find_package(Threads)
add_executable(cloud_run_hello cloud_run_hello.cc)
target_compile_features(cloud_run_hello PRIVATE cxx_std_17)
target_link_libraries(cloud_run_hello
functions-framework-cpp::framework
# I added this:
PRIVATE
${JUCE_DEPENDENCIES}
PUBLIC
juce::juce_recommended_config_flags
juce::juce_recommended_lto_flags
juce::juce_recommended_warning_flags
)
include(GNUInstallDirs)
install(TARGETS cloud_run_hello RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
Dockerfile:
# We chose Alpine to build the image because it has good support for creating
# statically-linked, small programs.
FROM alpine:3.16 AS base
# Create separate targets for each phase, this allows us to cache intermediate
# stages when using Google Cloud Build, and makes the final deployment stage
# small as it contains only what is needed.
FROM base AS devtools
# Install the typical development tools for C++, and
# the base OS headers and libraries.
RUN apk update && \
apk add \
build-base \
cmake \
curl \
git \
gcc \
g++ \
libc-dev \
linux-headers \
ninja \
pkgconfig \
tar \
unzip \
zip \
# I added these so far:
libexecinfo-dev \
libexecinfo \
freetype
# Use `vcpkg`, a package manager for C++, to install
WORKDIR /usr/local/vcpkg
ENV VCPKG_FORCE_SYSTEM_BINARIES=1
RUN curl -sSL "https://github.com/Microsoft/vcpkg/archive/2022.07.25.tar.gz" | \
tar --strip-components=1 -zxf - \
&& ./bootstrap-vcpkg.sh -disableMetrics
# Copy the source code to /v/source and compile it.
FROM devtools AS build
COPY . /v/source
WORKDIR /v/source
# Run the CMake configuration step, setting the options to create
# a statically linked C++ program
RUN cmake -S/v/source -B/v/binary -GNinja \
-DCMAKE_TOOLCHAIN_FILE=/usr/local/vcpkg/scripts/buildsystems/vcpkg.cmake \
-DCMAKE_BUILD_TYPE=Release
# Compile the binary and strip it to reduce its size.
RUN cmake --build /v/binary
RUN strip /v/binary/cloud_run_hello
# Create the final deployment image, using `scratch` (the empty Docker image)
# as the starting point. Effectively we create an image that only contains
# our program.
FROM scratch AS cloud-run-hello
WORKDIR /r
# Copy the program from the previously created stage and the shared libraries it
# depends on.
COPY --from=build /v/binary/cloud_run_hello /r
COPY --from=build /lib/ld-musl-x86_64.so.1 /lib/ld-musl-x86_64.so.1
COPY --from=build /usr/lib/libstdc++.so.6 /usr/lib/libstdc++.so.6
COPY --from=build /usr/lib/libgcc_s.so.1 /usr/lib/libgcc_s.so.1
# Make the program the entry point.
ENTRYPOINT [ "/r/cloud_run_hello" ]