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

POC: use Rust for css color parsing #2647

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/actions/qt5-build/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ set -x
export CCACHE_DIR="$GITHUB_WORKSPACE/.ccache"
export PATH="$QT_ROOT_DIR/bin:$PATH"

echo "Downloading and installing Rust..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
# this script is being ran under sudo, so $HOME is incorrect and this won't work : . "$HOME/.cargo/env"
. "/home/runner/.cargo/env"

mkdir build && cd build
cmake ../source/ \
-G Ninja \
Expand Down
5 changes: 5 additions & 0 deletions .github/actions/qt6-build/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ set -x
export CCACHE_DIR="$GITHUB_WORKSPACE/.ccache"
export PATH="$QT_ROOT_DIR/bin:$PATH"

echo "Downloading and installing Rust..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
# this script is being ran under sudo, so $HOME is incorrect and this won't work : . "$HOME/.cargo/env"
. "/home/runner/.cargo/env"

mkdir build && cd build
qt-cmake ../source/ \
-G Ninja \
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/android-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ jobs:
distribution: "temurin"
java-version: "17"

- name: Add aarch64-linux-android for Rust toolchian
run: rustup target add --toolchain stable-x86_64-unknown-linux-gnu aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android

- name: Cache node modules
uses: actions/cache@v4
env:
Expand Down Expand Up @@ -174,6 +177,9 @@ jobs:
distribution: "temurin"
java-version: "17"

- name: Add aarch64-linux-android for Rust toolchian
run: rustup target add --toolchain stable-x86_64-unknown-linux-gnu aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android

- name: Get CMake and Ninja
uses: lukka/get-cmake@latest
with:
Expand Down Expand Up @@ -223,6 +229,9 @@ jobs:
distribution: "temurin"
java-version: "17"

- name: Add aarch64-linux-android for Rust toolchian
run: rustup target add --toolchain stable-x86_64-unknown-linux-gnu aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android

- name: Build Render Test App
run: |
./gradlew assemble assembleAndroidTest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/linux-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ jobs:
xvfb \
x11-xserver-utils

- name: Install cxxbridge-cmd (compile)
run: cargo install cxxbridge-cmd

- name: Cache Bazel
uses: actions/cache@v4
with:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/node-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ jobs:
run: |
cmake --version

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable

- name: Cache Rust build artifacts
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
uses: Swatinem/rust-cache@v2
# TODO: ensure right directories are being cached

- name: Set up ccache (MacOS/Linux)
if: runner.os == 'MacOS' || runner.os == 'Linux'
uses: hendrikmuhs/ccache-action@v1
Expand Down
21 changes: 17 additions & 4 deletions .github/workflows/qt-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,19 @@ on:
- ".gitmodules"
- "!**/*.md"

concurrency:
# cancel jobs on PRs only
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
#
#
# FIXME: reenable this
#
#concurrency:
# # cancel jobs on PRs only
# group: ${{ github.workflow }}-${{ github.ref }}
# cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
build:
strategy:
fail-fast: false # FIXME: delete!
matrix:
include:
- name: Linux
Expand Down Expand Up @@ -206,6 +211,14 @@ jobs:
arch: ${{ matrix.compiler_type }}
toolset: ${{ matrix.compiler_version }}

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable

- name: Cache Rust build artifacts
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
uses: Swatinem/rust-cache@v2
# TODO: ensure right directories are being cached

- name: Setup ninja
uses: seanmiddleditch/gha-setup-ninja@v5

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@
[submodule "vendor/glslang"]
path = vendor/glslang
url = https://github.com/KhronosGroup/glslang.git
[submodule "vendor/corrosion"]
path = vendor/corrosion
url = https://github.com/corrosion-rs/corrosion.git
3 changes: 2 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ cc_library(
deps = [
":mbgl-core-generated-private-artifacts",
":mbgl-core-generated-public-artifacts",
"//rustutils:bridge",
"//rustutils:rustutils",
"//vendor:boost",
"//vendor:csscolorparser",
"//vendor:earcut.hpp",
"//vendor:eternal",
"//vendor:mapbox-base",
Expand Down
24 changes: 19 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,6 @@ target_include_directories(
)

include(${PROJECT_SOURCE_DIR}/vendor/boost.cmake)
include(${PROJECT_SOURCE_DIR}/vendor/csscolorparser.cmake)
include(${PROJECT_SOURCE_DIR}/vendor/earcut.hpp.cmake)
include(${PROJECT_SOURCE_DIR}/vendor/eternal.cmake)
include(${PROJECT_SOURCE_DIR}/vendor/mapbox-base.cmake)
Expand All @@ -1440,6 +1439,20 @@ set_target_properties(
INTERFACE_MAPBOX_LICENSE ${PROJECT_SOURCE_DIR}/vendor/unordered_dense/LICENSE
)

add_subdirectory(${PROJECT_SOURCE_DIR}/vendor/corrosion)

corrosion_import_crate(MANIFEST_PATH rustutils/Cargo.toml)
# rustutils_bridge is a set of .h headers generated from rustutils crate
corrosion_add_cxxbridge(rustutils_bridge CRATE rustutils FILES lib.rs)
set_target_properties(
rustutils
rustutils_bridge
PROPERTIES
INTERFACE_MAPBOX_NAME "Rust Utils"
INTERFACE_MAPBOX_AUTHOR "Yuri Astrakhan"
INTERFACE_MAPBOX_LICENSE ${CMAKE_CURRENT_LIST_DIR}/rustutils/LICENSE-MIT
)

target_link_libraries(
mbgl-core
PRIVATE
Expand All @@ -1450,7 +1463,6 @@ target_link_libraries(
Mapbox::Base::cheap-ruler-cpp
mbgl-compiler-options
mbgl-vendor-boost
mbgl-vendor-csscolorparser
mbgl-vendor-earcut.hpp
mbgl-vendor-eternal
mbgl-vendor-parsedate
Expand All @@ -1459,6 +1471,7 @@ target_link_libraries(
mbgl-vendor-unique_resource
mbgl-vendor-vector-tile
mbgl-vendor-wagyu
rustutils_bridge
PUBLIC
Mapbox::Base
Mapbox::Base::Extras::expected-lite
Expand All @@ -1468,11 +1481,13 @@ target_link_libraries(
Mapbox::Base::variant
$<$<BOOL:${MLN_USE_TRACY}>:TracyClient>
unordered_dense
rustutils
)

export(TARGETS
rustutils_bridge
mbgl-core

rustutils
mapbox-base
mapbox-base-cheap-ruler-cpp
mapbox-base-extras-expected-lite
Expand All @@ -1488,7 +1503,6 @@ export(TARGETS
mapbox-base-variant
mbgl-compiler-options
mbgl-vendor-boost
mbgl-vendor-csscolorparser
mbgl-vendor-earcut.hpp
mbgl-vendor-eternal
mbgl-vendor-parsedate
Expand Down Expand Up @@ -1551,4 +1565,4 @@ endif()

add_subdirectory(${PROJECT_SOURCE_DIR}/test)
add_subdirectory(${PROJECT_SOURCE_DIR}/benchmark)
add_subdirectory(${PROJECT_SOURCE_DIR}/render-test)
add_subdirectory(${PROJECT_SOURCE_DIR}/render-test)
29 changes: 0 additions & 29 deletions LICENSES.core.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,34 +178,6 @@ DEALINGS IN THE SOFTWARE.

---

### [csscolorparser](https://github.com/mapbox/css-color-parser-cpp) by Dean McNamee and Konstantin Käfer

```
(c) Dean McNamee <[email protected]>, 2012.
(c) Konstantin Käfer <[email protected]>, 2014.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

```

---

### [earcut.hpp](https://github.com/mapbox/earcut.hpp) by Mapbox

```
Expand Down Expand Up @@ -633,4 +605,3 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```

---

11 changes: 11 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,14 @@ darwin_config = use_repo_rule("//platform/darwin:bazel/darwin_config_repository_
darwin_config(
name = "darwin_config",
)

bazel_dep(name = "rules_rust", version = "0.49.1")

rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(versions = ["1.80.0"])
use_repo(rust, "rust_toolchains")

register_toolchains("@rust_toolchains//:all")

crate_repositories = use_extension("//bazel:extension.bzl", "crate_repositories")
use_repo(crate_repositories, "crates.io")
19 changes: 19 additions & 0 deletions bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
#
#bzl_library(
# name = "bzl_srcs",
# srcs = glob(["**/*.bzl"]),
# visibility = ["//visibility:public"],
#)
#
#xcode_version(
# name = "github_actions_xcode_14_2_0",
# default_macos_sdk_version = "13.1",
# version = "14.2",
#)
#
#xcode_config(
# name = "github_actions_xcodes",
# default = ":github_actions_xcode_14_2_0",
# versions = [":github_actions_xcode_14_2_0"],
#)
22 changes: 22 additions & 0 deletions bazel/extension.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#load("//third-party/bazel:defs.bzl", _crate_repositories = "crate_repositories")
#
#def _crates_vendor_remote_repository_impl(repository_ctx):
# repository_ctx.symlink(repository_ctx.attr.build_file, "BUILD.bazel")
#
#_crates_vendor_remote_repository = repository_rule(
# implementation = _crates_vendor_remote_repository_impl,
# attrs = {
# "build_file": attr.label(mandatory = True),
# },
#)
#
#def _crate_repositories_impl(module_ctx):
# _crate_repositories()
# _crates_vendor_remote_repository(
# name = "crates.io",
# build_file = "//third-party/bazel:BUILD.bazel",
# )
#
#crate_repositories = module_extension(
# implementation = _crate_repositories_impl,
#)
49 changes: 49 additions & 0 deletions bazel/rust_cxx_bridge.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# buildifier: disable=module-docstring
load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
load("@rules_cc//cc:defs.bzl", "cc_library")

def rust_cxx_bridge(name, src, deps = []):
"""A macro defining a cxx bridge library

Args:
name (string): The name of the new target
src (string): The rust source file to generate a bridge for
deps (list, optional): A list of dependencies for the underlying cc_library. Defaults to [].
"""
native.alias(
name = "%s/header" % name,
actual = src + ".h",
)

native.alias(
name = "%s/source" % name,
actual = src + ".cc",
)

run_binary(
name = "%s/generated" % name,
srcs = [src],
outs = [
src + ".h",
src + ".cc",
],
args = [
"$(location %s)" % src,
"-o",
"$(location %s.h)" % src,
"-o",
"$(location %s.cc)" % src,
],
tool = "cxxbridge", # FIXME!!! how do i call an app that's already installed locally? Or perhaps set up some pipeline to download/build it?
)

cc_library(
name = name,
srcs = [src + ".cc"],
deps = deps + [":%s/include" % name],
)

cc_library(
name = "%s/include" % name,
hdrs = [src + ".h"],
)
Loading
Loading