diff --git a/.github/workflows/cpp-packaging.yml b/.github/workflows/cpp-packaging.yml index f77cdd13cc..a4278b74d1 100644 --- a/.github/workflows/cpp-packaging.yml +++ b/.github/workflows/cpp-packaging.yml @@ -351,7 +351,7 @@ jobs: # Run the build in the host OS default shell since Windows can't handle long path names in bash. - name: Build desktop SDK run: | - python scripts/gha/build_desktop.py --arch "${{ matrix.architecture }}" --config "${{ matrix.build_type }}" --msvc_runtime_library "${{ matrix.msvc_runtime }}" --linux_abi "${{ matrix.linux_abi }}" --build_dir out-sdk ${VERBOSE_FLAG} ${{ matrix.additional_build_flags }} + python scripts/gha/build_desktop.py --arch "${{ matrix.architecture }}" --config "${{ matrix.build_type }}" --msvc_runtime_library "${{ matrix.msvc_runtime }}" --linux_abi "${{ matrix.linux_abi }}" --build_dir out-sdk ${VERBOSE_FLAG} ${{ matrix.additional_build_flags }} --gha_build - name: Archive SDK shell: bash diff --git a/.github/workflows/desktop.yml b/.github/workflows/desktop.yml index 103ab7066a..5ff5df0911 100644 --- a/.github/workflows/desktop.yml +++ b/.github/workflows/desktop.yml @@ -151,7 +151,7 @@ jobs: - name: Build SDK shell: bash run: | - python scripts/gha/build_desktop.py --build_tests --arch "${{ matrix.architecture }}" --config "${{ matrix.build_type }}" --msvc_runtime_library "${{ matrix.msvc_runtime }}" + python scripts/gha/build_desktop.py --build_tests --arch "${{ matrix.architecture }}" --config "${{ matrix.build_type }}" --msvc_runtime_library "${{ matrix.msvc_runtime }}" --gha_build - name: Stats for ccache (mac and linux) if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos') diff --git a/CMakeLists.txt b/CMakeLists.txt index 7795d9a946..a33df70e74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,11 +66,15 @@ option(FIREBASE_FORCE_FAKE_SECURE_STORAGE option(FIREBASE_CPP_BUILD_PACKAGE "Bundle the Firebase C++ libraries into a zip file." OFF) option(FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD - "When building with Gradle, use the previously built libraries." OFF) + "When building with Gradle, use the previously built libraries." OFF) option(FIREBASE_USE_BORINGSSL - "Build against BoringSSL instead of using your system's OpenSSL." OFF) + "Build against BoringSSL instead of using your system's OpenSSL." OFF) option(FIREBASE_USE_LINUX_CXX11_ABI - "Build Linux SDK using the C++11 ABI instead of the legacy ABI." OFF) + "Build Linux SDK using the C++11 ABI instead of the legacy ABI." OFF) + +# This should only be enabled by the GitHub Action build script. +option(FIREBASE_GITHUB_ACTION_BUILD + "Indicates that this build was created from a GitHub Action" OFF) set(FIREBASE_ANDROID_STL "" CACHE STRING "STL implementation to use.") if (NOT FIREBASE_ANDROID_STL STREQUAL "") @@ -139,6 +143,12 @@ if(DESKTOP AND NOT MSVC AND NOT APPLE) endif() endif() +if(FIREBASE_GITHUB_ACTION_BUILD) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFIREBASE_GITHUB_ACTION_BUILD=1") +else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFIREBASE_GITHUB_ACTION_BUILD=0") +endif() + # Set directories needed by the Firebase subprojects # Directory to store generated files. set(FIREBASE_GEN_FILE_DIR ${CMAKE_BINARY_DIR}/generated) diff --git a/app/src/app_common.cc b/app/src/app_common.cc index 99425b7e54..a931b23db3 100644 --- a/app/src/app_common.cc +++ b/app/src/app_common.cc @@ -164,6 +164,12 @@ const char* kCpuArchitecture = "x86"; #else #error Unknown operating system. #endif // Operating system + +#if FIREBASE_GITHUB_ACTION_BUILD +const char* kBuildSource = "github_action_built"; +#else +const char* kBuildSource = "custom_built"; +#endif // clang-format=on const char* kApiClientHeader = "x-firebase-client"; @@ -303,6 +309,8 @@ App* AddApp(App* app, std::map* results) { kCpuArchitecture); App::RegisterLibrary(FIREBASE_CPP_USER_AGENT_PREFIX "-stl", kCppRuntimeOrStl); + App::RegisterLibrary(FIREBASE_CPP_USER_AGENT_PREFIX "-buildsrc", + kBuildSource); } callback::Initialize(); AppCallback::NotifyAllAppCreated(app, results); diff --git a/app/src/app_common.h b/app/src/app_common.h index 2f585acab2..1769da3674 100644 --- a/app/src/app_common.h +++ b/app/src/app_common.h @@ -45,6 +45,7 @@ namespace app_common { extern const char* kOperatingSystem; extern const char* kCppRuntimeOrStl; extern const char* kCpuArchitecture; +extern const char* kBuildSource; // Extended API client header for Google user agent strings. extern const char* kApiClientHeader; diff --git a/scripts/gha/build_desktop.py b/scripts/gha/build_desktop.py index 186abe3ac4..3542a27713 100644 --- a/scripts/gha/build_desktop.py +++ b/scripts/gha/build_desktop.py @@ -150,7 +150,7 @@ def install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library, cleanup=True def cmake_configure(build_dir, arch, msvc_runtime_library='static', linux_abi='legacy', build_tests=True, config=None, target_format=None, - use_openssl=False, disable_vcpkg=False, verbose=False): + use_openssl=False, disable_vcpkg=False, gha_build=False, verbose=False): """ CMake configure. If you are seeing problems when running this multiple times, @@ -168,6 +168,8 @@ def cmake_configure(build_dir, arch, msvc_runtime_library='static', linux_abi='l use_openssl (bool) : Use prebuilt OpenSSL library instead of using boringssl downloaded and built during the cmake configure step. disable_vcpkg (bool): If True, skip vcpkg and just use CMake for deps. + gha_build (bool): If True, this build will be marked as having been built + from GitHub, which is useful for metrics tracking. verbose (bool): If True, enable verbose mode in the CMake file. """ cmd = ['cmake', '-S', '.', '-B', build_dir] @@ -216,6 +218,10 @@ def cmake_configure(build_dir, arch, msvc_runtime_library='static', linux_abi='l if not use_openssl: cmd.append('-DFIREBASE_USE_BORINGSSL=ON') + # When building from GitHub Actions, this should always be set. + if gha_build: + cmd.append('-DFIREBASE_GITHUB_ACTION_BUILD=ON') + # Print out every command while building. if verbose: cmd.append('-DCMAKE_VERBOSE_MAKEFILE=1') @@ -248,7 +254,7 @@ def main(): # CMake configure cmake_configure(args.build_dir, args.arch, args.msvc_runtime_library, args.linux_abi, args.build_tests, args.config, args.target_format, - args.use_openssl, args.disable_vcpkg, args.verbose) + args.use_openssl, args.disable_vcpkg, args.gha_build, args.verbose) # CMake build # cmake --build build -j 8 @@ -278,6 +284,7 @@ def parse_cmdline_args(): parser.add_argument('--target', nargs='+', help='A list of CMake build targets (eg: firebase_app firebase_auth)') parser.add_argument('--target_format', default=None, help='(Mac only) whether to output frameworks (default) or libraries.') parser.add_argument('--use_openssl', action='store_true', default=None, help='Use openssl for build instead of boringssl') + parser.add_argument('--gha_build', action='store_true', default=None, help='Set to true when building on GitHub, for metric tracking purposes') args = parser.parse_args() return args