Skip to content

Commit

Permalink
Add initial Bazel configuration
Browse files Browse the repository at this point in the history
Bazel can be used to build CEF-based applications. CEF support for
Bazel is considered experimental. For current development status
see chromiumembedded/cef#3757 . For
updated build and usage instructions see the README.md.
  • Loading branch information
magreenblatt committed Aug 3, 2024
1 parent 987ee7d commit a7a1ce3
Show file tree
Hide file tree
Showing 41 changed files with 2,271 additions and 71 deletions.
54 changes: 54 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright (c) 2024 The Chromium Embedded Framework Authors. All rights
# reserved. Use of this source code is governed by a BSD-style license that
# can be found in the LICENSE file.

# Enable Bzlmod for every Bazel command.
common --enable_bzlmod

# Enable build:{macos,linux,windows}.
build --enable_platform_specific_config

#
# Common configuration.
#

# Build with C++17.
build:linux --cxxopt='-std=c++17'
build:macos --cxxopt='-std=c++17'
build:macos --copt='-std=c++17'
build:windows --cxxopt='/std:c++17'

#
# MacOS configuration.
#

build:macos --copt='-ObjC++'

#
# Windows configuration.
#

# Enable creation of symlinks for runfiles.
build:windows --enable_runfiles

# Use /MT[d].
build:windows --features=static_link_msvcrt

#
# Linux configuration.
#

# The cfi-icall attribute is not supported by the GNU C++ compiler.
# TODO: Move to toolchain or add `--config=[gcc|llvm]` command-line option.
build:linux --cxxopt=-Wno-attributes

# Use hardlinks instead of symlinks in sandboxes on Linux.
# This is required for CEF binaries to run, and for copy_filegroups() to work
# as expected on Linux.
build:linux --experimental_use_hermetic_linux_sandbox
build:linux --sandbox_add_mount_pair=/etc
build:linux --sandbox_add_mount_pair=/usr
## symlinks into /usr
build:linux --sandbox_add_mount_pair=/usr/bin:/bin
build:linux --sandbox_add_mount_pair=/usr/lib:/lib
build:linux --sandbox_add_mount_pair=/usr/lib64:/lib64
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.1.1
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,8 @@ Thumbs.db
/tools/buildtools/linux64/clang-format
/tools/buildtools/mac/clang-format
/tools/buildtools/win/clang-format.exe
# Bazel generated files
bazel/cef/platform.bzl
# Bazel output files/directories
bazel-*
MODULE.bazel.lock
90 changes: 90 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright (c) 2024 The Chromium Embedded Framework Authors. All rights
# reserved. Use of this source code is governed by a BSD-style license that
# can be found in the LICENSE file.

# Allow access from targets in other packages.
package(default_visibility = [
"//visibility:public",
])

load("@bazel_skylib//lib:selects.bzl", "selects")

#
# Define supported configurations.
# See https://bazel.build/docs/configurable-attributes
#
# Normal build (ARM64 host):
# % bazel build //examples/minimal [-c dbg]
#
# Cross-compile build (ARM64 host):
# % bazel build //examples/minimal --cpu=darwin_x86_64 [-c dbg]
#

config_setting(
name = "dbg",
values = {"compilation_mode": "dbg"},
)

config_setting(
name = "fastbuild",
values = {"compilation_mode": "fastbuild"},
)

config_setting(
name = "opt",
values = {"compilation_mode": "opt"},
)

selects.config_setting_group(
name = "windows_32",
match_all = ["@platforms//os:windows", "@platforms//cpu:x86_32"],
)

selects.config_setting_group(
name = "windows_64",
match_all = ["@platforms//os:windows", "@platforms//cpu:x86_64"],
)

selects.config_setting_group(
name = "windows_arm64",
match_all = ["@platforms//os:windows", "@platforms//cpu:arm64"],
)

selects.config_setting_group(
name = "linux_64",
match_all = ["@platforms//os:windows", "@platforms//cpu:x86_64"],
)

selects.config_setting_group(
name = "linux_arm64",
match_all = ["@platforms//os:windows", "@platforms//cpu:arm64"],
)

selects.config_setting_group(
name = "linux_arm",
match_all = ["@platforms//os:windows", "@platforms//cpu:armv7"],
)

config_setting(
name = "darwin_x86_64",
values = {
"cpu": "darwin_x86_64"
}
)

config_setting(
name = "darwin_arm64",
values = {
"cpu": "darwin_arm64"
}
)

selects.config_setting_group(
name = "macos_64",
match_all = ["@platforms//os:macos", ":darwin_x86_64"],
)

selects.config_setting_group(
name = "macos_arm64",
match_all = ["@platforms//os:macos", ":darwin_arm64"],
)
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set_property(GLOBAL PROPERTY OS_FOLDERS ON)
#

# Specify the CEF distribution version.
set(CEF_VERSION "127.1.0+ga1ec504+chromium-127.0.6533.57")
set(CEF_VERSION "127.1.5+g35f74cc+chromium-127.0.6533.89")

# Determine the platform.
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
Expand Down
17 changes: 17 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) 2024 The Chromium Embedded Framework Authors. All rights
# reserved. Use of this source code is governed by a BSD-style license that
# can be found in the LICENSE file.

module(name = "cef-project")

# Configure local MacOS toolchain.
# See https://github.com/bazelbuild/apple_support/releases
bazel_dep(name = "apple_support", version = "1.16.0", repo_name = "build_bazel_apple_support")
# See https://github.com/bazelbuild/rules_apple/releases
bazel_dep(name = "rules_apple", version = "3.6.0", repo_name = "build_bazel_rules_apple")

# Configure local C++ toolchain.
# See https://github.com/bazelbuild/rules_cc/releases
bazel_dep(name = "rules_cc", version = "0.0.9")

# Add other dependencies here.
98 changes: 84 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,38 @@ The [Chromium Embedded Framework](https://bitbucket.org/chromiumembedded/cef/) (

First install some necessary tools and download the cef-project source code.

1\. Install [CMake](https://cmake.org/), a cross-platform open-source build system. Version 3.21 or newer is required.
1\. Install [Python](https://www.python.org/downloads/). Version 3.9 to 3.11 is required.

2\. Install [Python](https://www.python.org/downloads/). Version 2.7.x or 3.9.x is required. If Python is not installed to the default location you can set the `PYTHON_EXECUTABLE` environment variable before running CMake (watch for errors during the CMake generation step below).
2\. Install platform-specific build tools.

3\. Install platform-specific build tools.

* Linux: Currently supported distributions include Debian 10 (Buster), Ubuntu 18 (Bionic Beaver), and related. Ubuntu 18.04 64-bit with GCC 7.5.0+ is recommended. Newer versions will likely also work but may not have been tested. Required packages include: build-essential, libgtk-3-dev.
* Linux: Currently supported distributions include Debian 10 (Buster), Ubuntu 18 (Bionic Beaver), and related, with minimum GCC version 7.5.0. Ubuntu 22.04 64-bit with GCC 11+ is recommended. Newer versions will likely also work but may not have been tested. Required packages include: build-essential, libgtk-3-dev.
* MacOS: Xcode 12.2 to 15.0 building on MacOS 10.15.4 (Catalina) or newer. The Xcode command-line tools must also be installed.
* Windows: Visual Studio 2022 building on Windows 10 or newer. Windows 10/11 64-bit is recommended.

4\. Download the cef-project source code from the [Downloads page](https://bitbucket.org/chromiumembedded/cef-project/downloads) or by using [Git](https://git-scm.com/) command-line tools:
3\. Download the cef-project source code from the [Downloads page](https://bitbucket.org/chromiumembedded/cef-project/downloads) or by using [Git](https://git-scm.com/) command-line tools:

```
git clone https://bitbucket.org/chromiumembedded/cef-project.git
```

# Build

Now run CMake which will download the CEF binary distribution from the [Spotify automated builder](https://cef-builds.spotifycdn.com/index.html) and generate build files for your platform. Then build using platform build tools. For example, using the most recent tool versions on each platform:
The CEF examples included in this project can be built using either [CMake](https://cmake.org/) or [Bazel](https://bazel.build/).
These are both highly regarded cross-platform open-source build systems.

## Using CMake

[CMake](https://cmake.org/) can be used to generate project files in many different formats.

To build the cef-project example applications using CMake:

1\. Install [CMake](https://cmake.org/download/). Version 3.21 or newer is required.

2\. Set the `PYTHON_EXECUTABLE` environment variable if required (watch for errors during the CMake generation step below).

3\. Run CMake to download the CEF binary distribution from the [Spotify automated builder](https://cef-builds.spotifycdn.com/index.html) and generate build files for your platform.

4\. Build using platform build tools. For example, using the most recent tool versions on each platform:

```
cd /path/to/cef-project
Expand Down Expand Up @@ -71,6 +84,56 @@ CMake supports different generators on each platform. Run `cmake --help` to list

Ninja is a cross-platform open-source tool for running fast builds using pre-installed platform toolchains (GNU, clang, Xcode or MSVC). See comments in the "third_party/cef/cef_binary_*/CMakeLists.txt" file for Ninja usage instructions.

## Using Bazel

CEF support for [Bazel](https://bazel.build/) is considered experimental. For current development status see
https://github.com/chromiumembedded/cef/issues/3757.

To build the cef-project example applications using Bazel:

1\. Install [Bazelisk](https://github.com/bazelbuild/bazelisk/blob/master/README.md).

2\. (Linux only) Install the patchelf package:
```
sudo apt install patchelf
```

3\. Configure the CEF platform (see command output for details):
```
cd /path/to/cef-project
python3 ./tools/bazel/platform_updater.py
```
4\. Build using Bazel:
```
bazel build //examples/minimal
```
This will perform the following actions:

* Download/install Bazel at the required [version](.bazelversion) (if necessary).
* Download the CEF binary distribution at the required [version](bazel/cef/version.bzl) from the
[Spotify automated builder](https://cef-builds.spotifycdn.com/index.html) (if necessary).
* Build using the default platform toolchain.

5\. Run using Bazel:
```
# On Linux/MacOS:
bazel run //examples/minimal
# On Windows:
bazel run //examples/minimal/win:minimal.exe
```

To build other cef-project example applications replace `minimal` with the name of
the other application. To build CEF sample applications from the binary distribution
(cefsimple, cefclient, ceftests) use the `@cef//tests/cefsimple` target syntax.

Additional notes:

* To generate a Debug build add `-c dbg` (both `build` and `run`
command-line).
* To pass arguments using the `run` command add `-- [...]` at the end.
* See `platform_updater.py` output for additional instructions when cross-compiling.

# Examples

CEF provides a number of examples that you can use as a starting point or reference for your own CEF-based development.
Expand All @@ -81,7 +144,7 @@ CEF provides a number of examples that you can use as a starting point or refere
* The cefclient application demonstrates a wide range of CEF functionality most of which is documented on the [GeneralUsage](https://bitbucket.org/chromiumembedded/cef/wiki/GeneralUsage.md) Wiki page.
* The [examples directory](examples) contains example targets that demonstrate specific aspects of CEF functionality.
* See the [examples README.md file](examples/README.md) for information about the examples targets.
* Add `-DWITH_EXAMPLES=Off` to the cmake command-line if you do not wish to build the examples targets.
* Using CMake: Add `-DWITH_EXAMPLES=Off` to the CMake command-line if you do not wish to build the examples targets.

# Next Steps

Expand All @@ -90,17 +153,24 @@ Here are some activities you might want to try next to gain a better understandi
1\. Update the CEF version used to build your local copy of cef-project:

* Visit the [Spotify automated builder](https://cef-builds.spotifycdn.com/index.html) page to see what CEF versions are available.
* Change the "CEF_VERSION" value near the top of the [top-level CMakeLists.txt file](https://bitbucket.org/chromiumembedded/cef-project/src/master/CMakeLists.txt?fileviewer=file-view-default).
* Re-run the cmake and build commands. Add `-DWITH_EXAMPLES=Off` to the cmake command-line to disable targets from the [examples directory](examples) because they may not build successfully with the new CEF version.
* Using CMake:
* Change the "CEF_VERSION" value near the top of the [top-level CMakeLists.txt file](https://bitbucket.org/chromiumembedded/cef-project/src/master/CMakeLists.txt?fileviewer=file-view-default).
* Re-run the CMake and build commands. Add `-DWITH_EXAMPLES=Off` to the CMake command-line to disable targets from the [examples directory](examples) because they may not build successfully with the new CEF version.
* Using Bazel:
* Run the `./tools/bazel/version_updater.py` script to update the CEF version (see command output for details).
* Build and run the `@cef//tests/cefsimple` target. See instructions above.

2\. Add your own project source code:

* Create a new "myproject" directory in the root cef-project directory (e.g. "/path/to/cef-project/myproject").
* Copy the contents of the "third_party/cef/cef_binary_*/tests/cefsimple" directory to "myproject" as a starting point.
* Add a new `add_subdirectory(myproject)` command near the end of [top-level CMakeLists.txt file](https://bitbucket.org/chromiumembedded/cef-project/src/master/CMakeLists.txt?fileviewer=file-view-default) after the existing add_subdirectory commands.
* Change the "CEF_TARGET", "CEF_HELPER_TARGET" and "CEF_HELPER_OUTPUT_NAME" values in "myproject/CMakeLists.txt" replacing "cefsimple" with "myproject".
* (Windows only) Rename the "cefclient.exe.manifest" file to "myproject.exe.manifest" in both "myproject/CMakeLists.txt" and the "myproject" directory.
* Re-run the cmake and build commands.
* Replace all instances of "cefsimple" with "myproject" and "tests" with "examples" in file names and file contents.
* Using CMake:
* Add a new `add_subdirectory(myproject)` command near the end of [top-level CMakeLists.txt file](https://bitbucket.org/chromiumembedded/cef-project/src/master/CMakeLists.txt?fileviewer=file-view-default) after the existing add_subdirectory commands.
* Re-run the cmake and build commands.
* Using Bazel:
* In all copied `BUILD.bazel` files change `load("//bazel...` to `load("@cef//bazel...`
* Build and run the `//examples/myproject` target. See instructions above.

3\. Gain a better understanding of the cefsimple application by reading the [Tutorial](https://bitbucket.org/chromiumembedded/cef/wiki/Tutorial.md) Wiki page.

Expand Down
72 changes: 72 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright (c) 2024 The Chromium Embedded Framework Authors. All rights
# reserved. Use of this source code is governed by a BSD-style license that
# can be found in the LICENSE file.

workspace(name = "cef-project")

#
# Load the CEF binary distribution.
#

# Download, extract and load the distribution.
load("//bazel/cef:loader.bzl", "load_cef_repo")
load_cef_repo()

# To load a locally downloaded/extracted distribution use the following
# lines instead:
# load("//bazel/cef:loader.bzl", "load_local_cef_repo")
# load_local_cef_repo(path = "third_party/cef")

#
# Windows configuration.
#

# Configure windows SDK.
load("@cef//bazel/win:setup_sdk.bzl", "setup_sdk")
setup_sdk(name = "winsdk")

#
# Linux configuration.
#

# Configure Linux using pkg-config.
load("//bazel:external_local_repository.bzl", "external_local_repository")
external_local_repository(
name="pkg_config",
path="@cef//bazel/linux/pkg_config"
)
load("@pkg_config//:pkg_config.bzl", "pkg_config")

# Define packages used by @cef//tests/cefclient.

pkg_config(
name = "gmodule2",
pkg_name = "gmodule-2.0",
)

pkg_config(
name = "gtk3",
pkg_name = "gtk+-3.0",
)

pkg_config(
name = "gthread2",
pkg_name = "gthread-2.0",
)

pkg_config(
name = "gtkprint3",
pkg_name = "gtk+-unix-print-3.0",
)

pkg_config(
name = "xi",
)

# Define packages used by @cef//tests/ceftests.

pkg_config(
name = "glib2",
pkg_name = "glib-2.0",
)

Loading

0 comments on commit a7a1ce3

Please sign in to comment.