From 4ebc2d69411023022ce8b49372922b36c3faba06 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 24 Jul 2024 17:13:28 -0400 Subject: [PATCH 01/56] Squashed Rust impl --- BUILD.bazel | 1 - CMakeLists.txt | 30 +- LICENSES.core.md | 29 -- docker/Dockerfile | 4 + docker/startup.sh | 15 + platform/android/LICENSE.md | 29 -- platform/android/android.cmake | 1 - platform/ios/LICENSE.md | 30 +- platform/linux/README.md | 3 + platform/qt/qt.cmake | 2 - rustutils/.gitignore | 1 + rustutils/Cargo.lock | 162 ++++++++++ rustutils/Cargo.toml | 19 ++ .../LICENSE => rustutils/LICENSE-MIT | 23 +- rustutils/src/lib.rs | 36 +++ src/mbgl/util/color.cpp | 13 +- vendor/BUILD.bazel | 14 - vendor/csscolorparser.cmake | 37 --- vendor/csscolorparser/csscolorparser.cpp | 288 ------------------ .../csscolorparser/csscolorparser.hpp | 56 ---- 20 files changed, 284 insertions(+), 509 deletions(-) create mode 100644 rustutils/.gitignore create mode 100644 rustutils/Cargo.lock create mode 100644 rustutils/Cargo.toml rename vendor/csscolorparser/LICENSE => rustutils/LICENSE-MIT (56%) create mode 100644 rustutils/src/lib.rs delete mode 100644 vendor/csscolorparser.cmake delete mode 100644 vendor/csscolorparser/csscolorparser.cpp delete mode 100644 vendor/csscolorparser/csscolorparser/csscolorparser.hpp diff --git a/BUILD.bazel b/BUILD.bazel index ec5888a557b..0692289a0c2 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -124,7 +124,6 @@ cc_library( ":mbgl-core-generated-private-artifacts", ":mbgl-core-generated-public-artifacts", "//vendor:boost", - "//vendor:csscolorparser", "//vendor:earcut.hpp", "//vendor:eternal", "//vendor:mapbox-base", diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a79cfcb1d0..900e722f296 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -1440,6 +1439,26 @@ set_target_properties( INTERFACE_MAPBOX_LICENSE ${PROJECT_SOURCE_DIR}/vendor/unordered_dense/LICENSE ) +include(FetchContent) +FetchContent_Declare( + Corrosion + GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git + GIT_TAG v0.5 +) +FetchContent_MakeAvailable(Corrosion) + +corrosion_import_crate(MANIFEST_PATH rustutils/Cargo.toml) +# rustutils_headers is a set of .h headers generated from rustutils crate +corrosion_add_cxxbridge(rustutils_headers CRATE rustutils FILES lib.rs) +set_target_properties( + rustutils + rustutils_headers + 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 @@ -1450,7 +1469,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 @@ -1459,6 +1477,7 @@ target_link_libraries( mbgl-vendor-unique_resource mbgl-vendor-vector-tile mbgl-vendor-wagyu + rustutils_headers PUBLIC Mapbox::Base Mapbox::Base::Extras::expected-lite @@ -1468,11 +1487,13 @@ target_link_libraries( Mapbox::Base::variant $<$:TracyClient> unordered_dense + rustutils ) export(TARGETS + rustutils_headers mbgl-core - + rustutils mapbox-base mapbox-base-cheap-ruler-cpp mapbox-base-extras-expected-lite @@ -1488,7 +1509,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 @@ -1551,4 +1571,4 @@ endif() add_subdirectory(${PROJECT_SOURCE_DIR}/test) add_subdirectory(${PROJECT_SOURCE_DIR}/benchmark) -add_subdirectory(${PROJECT_SOURCE_DIR}/render-test) \ No newline at end of file +add_subdirectory(${PROJECT_SOURCE_DIR}/render-test) diff --git a/LICENSES.core.md b/LICENSES.core.md index 558d0e48945..86a5dd3fa4e 100644 --- a/LICENSES.core.md +++ b/LICENSES.core.md @@ -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 , 2012. -(c) Konstantin Käfer , 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 ``` @@ -633,4 +605,3 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ``` --- - diff --git a/docker/Dockerfile b/docker/Dockerfile index 9f545066cfe..2549642fa9e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -55,5 +55,9 @@ RUN chmod +x /usr/local/bin/startup.sh # This allows users to `docker run` without specifying -u and -g USER $USERNAME +ENV RUSTUP_HOME=/home/$USERNAME/.cache/.rustup \ + CARGO_HOME=/home/$USERNAME/.cache/.cargo \ + PATH=/home/$USERNAME/.cache/.cargo/bin:$PATH + ENTRYPOINT ["/usr/local/bin/startup.sh"] CMD ["bash"] diff --git a/docker/startup.sh b/docker/startup.sh index 6bb1f9a17e6..81530303dc7 100644 --- a/docker/startup.sh +++ b/docker/startup.sh @@ -10,4 +10,19 @@ if [ ! -d /app/.github ] || [ ! -d /home/user/.cache ]; then exit 1 fi + +if [ ! -f "$CARGO_HOME/env" ]; then + echo "Downloading and installing Rust..." + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal +fi +. "$CARGO_HOME/env" + + + +if ! command -v cxxbridge > /dev/null; then + echo "Installing cxxbridge..." + cargo install cxxbridge-cmd +fi + + exec "$@" diff --git a/platform/android/LICENSE.md b/platform/android/LICENSE.md index 72b908825de..bf720b2ae78 100644 --- a/platform/android/LICENSE.md +++ b/platform/android/LICENSE.md @@ -456,34 +456,6 @@ DEALINGS IN THE SOFTWARE. --- -### [csscolorparser](https://github.com/mapbox/css-color-parser-cpp) by Dean McNamee and Konstantin Käfer - -``` -(c) Dean McNamee , 2012. -(c) Konstantin Käfer , 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 ``` @@ -942,4 +914,3 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ``` --- - diff --git a/platform/android/android.cmake b/platform/android/android.cmake index b28104d3a86..608cddb12cc 100644 --- a/platform/android/android.cmake +++ b/platform/android/android.cmake @@ -11,7 +11,6 @@ include(${PROJECT_SOURCE_DIR}/vendor/icu.cmake) include(${PROJECT_SOURCE_DIR}/vendor/sqlite.cmake) # cmake-format: off -target_compile_options(mbgl-vendor-csscolorparser PRIVATE $<$:-Oz> $<$:-Qunused-arguments> $<$:-flto>) target_compile_options(mbgl-vendor-icu PRIVATE $<$:-Oz> $<$:-Qunused-arguments> $<$:-flto>) target_compile_options(mbgl-vendor-parsedate PRIVATE $<$:-Oz> $<$:-Qunused-arguments> $<$:-flto>) target_compile_options(mbgl-vendor-sqlite PRIVATE $<$:-Oz> $<$:-Qunused-arguments> $<$:-flto>) diff --git a/platform/ios/LICENSE.md b/platform/ios/LICENSE.md index 5a9143de0ce..5378fb1fbf3 100644 --- a/platform/ios/LICENSE.md +++ b/platform/ios/LICENSE.md @@ -1026,34 +1026,6 @@ DEALINGS IN THE SOFTWARE. --- -### [csscolorparser](https://github.com/mapbox/css-color-parser-cpp) by Dean McNamee and Konstantin Käfer - -``` -(c) Dean McNamee , 2012. -(c) Konstantin Käfer , 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 ``` @@ -1687,4 +1659,4 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -``` \ No newline at end of file +``` diff --git a/platform/linux/README.md b/platform/linux/README.md index 371d4ae1358..b0a07646fa5 100644 --- a/platform/linux/README.md +++ b/platform/linux/README.md @@ -19,6 +19,9 @@ cd maplibre-native # Install build tools apt install build-essential clang cmake ccache ninja-build pkg-config +# Install rust toolchain (default options should be sufficient) +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh + # Install system dependencies apt install libcurl4-openssl-dev libglfw3-dev libuv1-dev libpng-dev libicu-dev libjpeg-turbo8-dev libwebp-dev xvfb ``` diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake index 71957dff527..8c1547819a4 100644 --- a/platform/qt/qt.cmake +++ b/platform/qt/qt.cmake @@ -138,7 +138,6 @@ target_link_libraries( PUBLIC $ $ - $ $<$,$>>:z> $,$,Qt${QT_VERSION_MAJOR}::Sql> PRIVATE @@ -162,7 +161,6 @@ if(MLN_QT_HAS_PARENT) set(MLN_QT_VENDOR_LIBRARIES mbgl-vendor-parsedate mbgl-vendor-nunicode - mbgl-vendor-csscolorparser $<$:$> $<$,$>:$> PARENT_SCOPE diff --git a/rustutils/.gitignore b/rustutils/.gitignore new file mode 100644 index 00000000000..ea8c4bf7f35 --- /dev/null +++ b/rustutils/.gitignore @@ -0,0 +1 @@ +/target diff --git a/rustutils/Cargo.lock b/rustutils/Cargo.lock new file mode 100644 index 00000000000..16003c0398f --- /dev/null +++ b/rustutils/Cargo.lock @@ -0,0 +1,162 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cc" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f" + +[[package]] +name = "csscolorparser" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb2a7d3066da2de787b7f032c736763eb7ae5d355f81a68bab2675a96008b0bf" +dependencies = [ + "phf", +] + +[[package]] +name = "cxx" +version = "1.0.124" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "273dcfd3acd4e1e276af13ed2a43eea7001318823e7a726a6b3ed39b4acc0b82" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.124" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "839fcd5e43464614ffaa989eaf1c139ef1f0c51672a1ed08023307fa1b909ccd" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.124" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b2c1c1776b986979be68bb2285da855f8d8a35851a769fca8740df7c3d07877" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "link-cplusplus" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d240c6f7e1ba3a28b0249f774e6a9dd0175054b52dfbb61b16eb8505c3785c9" +dependencies = [ + "cc", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "rustutils" +version = "0.1.0" +dependencies = [ + "csscolorparser", + "cxx", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "syn" +version = "2.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/rustutils/Cargo.toml b/rustutils/Cargo.toml new file mode 100644 index 00000000000..cea6240b2d6 --- /dev/null +++ b/rustutils/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "rustutils" +version = "0.1.0" +authors = ["Yuri Astrakhan ", "MapLibre contributors"] +description = "Core Rust utilities for MapLibre Native" +edition = "2021" +license = "MIT OR Apache-2.0" +repository = "https://github.com/maplibre/maplibre-native" + +[lib] +crate-type = ["staticlib"] + +[dependencies] +csscolorparser = "0.6.2" +cxx = "1" + +[profile.release] +lto = true +codegen-units = 1 diff --git a/vendor/csscolorparser/LICENSE b/rustutils/LICENSE-MIT similarity index 56% rename from vendor/csscolorparser/LICENSE rename to rustutils/LICENSE-MIT index 2408b4a02e1..8591dea8f51 100644 --- a/vendor/csscolorparser/LICENSE +++ b/rustutils/LICENSE-MIT @@ -1,20 +1,21 @@ -(c) Dean McNamee , 2012. -(c) Konstantin Käfer , 2014. +MIT License + +Copyright (c) 2024 Yuri Astrakhan 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 +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 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. +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. diff --git a/rustutils/src/lib.rs b/rustutils/src/lib.rs new file mode 100644 index 00000000000..5841c4daab3 --- /dev/null +++ b/rustutils/src/lib.rs @@ -0,0 +1,36 @@ +use crate::ffi::ParsedColor; +use csscolorparser::Color; + +#[cxx::bridge(namespace = "rustutils")] +mod ffi { + struct ParsedColor { + pub success: bool, + pub r: f32, + pub g: f32, + pub b: f32, + pub a: f32, + } + + extern "Rust" { + fn parse_css_color(css_str: &str) -> ParsedColor; + } +} + +fn parse_css_color(css_str: &str) -> ParsedColor { + css_str + .parse::() + .map(|color| ParsedColor { + success: true, + r: color.r as f32, + g: color.g as f32, + b: color.b as f32, + a: color.a as f32, + }) + .unwrap_or_else(|_| ParsedColor { + success: false, + r: 0.0, + g: 0.0, + b: 0.0, + a: 0.0, + }) +} diff --git a/src/mbgl/util/color.cpp b/src/mbgl/util/color.cpp index 44fb65f732a..433e8b8ee96 100644 --- a/src/mbgl/util/color.cpp +++ b/src/mbgl/util/color.cpp @@ -1,17 +1,16 @@ +#include + #include #include -#include +#include namespace mbgl { std::optional Color::parse(const std::string& s) { - auto css_color = CSSColorParser::parse(s); - - // Premultiply the color. - if (css_color) { - const float factor = css_color->a / 255; - return {{css_color->r * factor, css_color->g * factor, css_color->b * factor, css_color->a}}; + auto css_color = rustutils::parse_css_color(s); + if (css_color.success) { + return {{css_color.r, css_color.g, css_color.b, css_color.a}}; } else { return {}; } diff --git a/vendor/BUILD.bazel b/vendor/BUILD.bazel index 66815d83b44..27441081bbc 100644 --- a/vendor/BUILD.bazel +++ b/vendor/BUILD.bazel @@ -56,20 +56,6 @@ cc_library( visibility = ["//visibility:public"], ) -# vendor/csscolorparser -cc_library( - name = "csscolorparser", - srcs = glob( - [ - "csscolorparser/**/*.hpp", - "csscolorparser/**/*.cpp", - ], - ), - copts = CPP_FLAGS, - includes = ["csscolorparser"], - visibility = ["//visibility:public"], -) - # vendor/wagyu-files.json cc_library( name = "wagyu", diff --git a/vendor/csscolorparser.cmake b/vendor/csscolorparser.cmake deleted file mode 100644 index 1a45f97af3f..00000000000 --- a/vendor/csscolorparser.cmake +++ /dev/null @@ -1,37 +0,0 @@ -if(TARGET mbgl-vendor-csscolorparser) - return() -endif() - -if(MLN_WITH_QT) - add_library(mbgl-vendor-csscolorparser OBJECT) -else() - add_library(mbgl-vendor-csscolorparser STATIC) -endif() - -target_sources( - mbgl-vendor-csscolorparser PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/csscolorparser/csscolorparser.cpp -) - -target_link_libraries( - mbgl-vendor-csscolorparser - PRIVATE mbgl-compiler-options -) - -target_include_directories( - mbgl-vendor-csscolorparser SYSTEM - PUBLIC ${CMAKE_CURRENT_LIST_DIR}/csscolorparser -) - -if(MSVC) - target_compile_options(mbgl-vendor-csscolorparser PRIVATE /wd4244) -endif() - -set_target_properties( - mbgl-vendor-csscolorparser - PROPERTIES - INTERFACE_MAPBOX_NAME "csscolorparser" - INTERFACE_MAPBOX_URL "https://github.com/mapbox/css-color-parser-cpp" - INTERFACE_MAPBOX_AUTHOR "Dean McNamee and Konstantin Käfer" - INTERFACE_MAPBOX_LICENSE ${CMAKE_CURRENT_LIST_DIR}/csscolorparser/LICENSE -) diff --git a/vendor/csscolorparser/csscolorparser.cpp b/vendor/csscolorparser/csscolorparser.cpp deleted file mode 100644 index 74764a22e24..00000000000 --- a/vendor/csscolorparser/csscolorparser.cpp +++ /dev/null @@ -1,288 +0,0 @@ -// (c) Dean McNamee , 2012. -// C++ port by Mapbox, Konstantin Käfer , 2014-2017. -// -// https://github.com/deanm/css-color-parser-js -// https://github.com/kkaefer/css-color-parser-cpp -// -// 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. - -#include "csscolorparser/csscolorparser.hpp" - -#include -#include -#include -#include - -namespace CSSColorParser { - -// http://www.w3.org/TR/css3-color/ -struct NamedColor { const char *const name; const Color color; }; -const NamedColor namedColors[] = { - { "transparent", { 0, 0, 0, 0 } }, { "aliceblue", { 240, 248, 255, 1 } }, - { "antiquewhite", { 250, 235, 215, 1 } }, { "aqua", { 0, 255, 255, 1 } }, - { "aquamarine", { 127, 255, 212, 1 } }, { "azure", { 240, 255, 255, 1 } }, - { "beige", { 245, 245, 220, 1 } }, { "bisque", { 255, 228, 196, 1 } }, - { "black", { 0, 0, 0, 1 } }, { "blanchedalmond", { 255, 235, 205, 1 } }, - { "blue", { 0, 0, 255, 1 } }, { "blueviolet", { 138, 43, 226, 1 } }, - { "brown", { 165, 42, 42, 1 } }, { "burlywood", { 222, 184, 135, 1 } }, - { "cadetblue", { 95, 158, 160, 1 } }, { "chartreuse", { 127, 255, 0, 1 } }, - { "chocolate", { 210, 105, 30, 1 } }, { "coral", { 255, 127, 80, 1 } }, - { "cornflowerblue", { 100, 149, 237, 1 } }, { "cornsilk", { 255, 248, 220, 1 } }, - { "crimson", { 220, 20, 60, 1 } }, { "cyan", { 0, 255, 255, 1 } }, - { "darkblue", { 0, 0, 139, 1 } }, { "darkcyan", { 0, 139, 139, 1 } }, - { "darkgoldenrod", { 184, 134, 11, 1 } }, { "darkgray", { 169, 169, 169, 1 } }, - { "darkgreen", { 0, 100, 0, 1 } }, { "darkgrey", { 169, 169, 169, 1 } }, - { "darkkhaki", { 189, 183, 107, 1 } }, { "darkmagenta", { 139, 0, 139, 1 } }, - { "darkolivegreen", { 85, 107, 47, 1 } }, { "darkorange", { 255, 140, 0, 1 } }, - { "darkorchid", { 153, 50, 204, 1 } }, { "darkred", { 139, 0, 0, 1 } }, - { "darksalmon", { 233, 150, 122, 1 } }, { "darkseagreen", { 143, 188, 143, 1 } }, - { "darkslateblue", { 72, 61, 139, 1 } }, { "darkslategray", { 47, 79, 79, 1 } }, - { "darkslategrey", { 47, 79, 79, 1 } }, { "darkturquoise", { 0, 206, 209, 1 } }, - { "darkviolet", { 148, 0, 211, 1 } }, { "deeppink", { 255, 20, 147, 1 } }, - { "deepskyblue", { 0, 191, 255, 1 } }, { "dimgray", { 105, 105, 105, 1 } }, - { "dimgrey", { 105, 105, 105, 1 } }, { "dodgerblue", { 30, 144, 255, 1 } }, - { "firebrick", { 178, 34, 34, 1 } }, { "floralwhite", { 255, 250, 240, 1 } }, - { "forestgreen", { 34, 139, 34, 1 } }, { "fuchsia", { 255, 0, 255, 1 } }, - { "gainsboro", { 220, 220, 220, 1 } }, { "ghostwhite", { 248, 248, 255, 1 } }, - { "gold", { 255, 215, 0, 1 } }, { "goldenrod", { 218, 165, 32, 1 } }, - { "gray", { 128, 128, 128, 1 } }, { "green", { 0, 128, 0, 1 } }, - { "greenyellow", { 173, 255, 47, 1 } }, { "grey", { 128, 128, 128, 1 } }, - { "honeydew", { 240, 255, 240, 1 } }, { "hotpink", { 255, 105, 180, 1 } }, - { "indianred", { 205, 92, 92, 1 } }, { "indigo", { 75, 0, 130, 1 } }, - { "ivory", { 255, 255, 240, 1 } }, { "khaki", { 240, 230, 140, 1 } }, - { "lavender", { 230, 230, 250, 1 } }, { "lavenderblush", { 255, 240, 245, 1 } }, - { "lawngreen", { 124, 252, 0, 1 } }, { "lemonchiffon", { 255, 250, 205, 1 } }, - { "lightblue", { 173, 216, 230, 1 } }, { "lightcoral", { 240, 128, 128, 1 } }, - { "lightcyan", { 224, 255, 255, 1 } }, { "lightgoldenrodyellow", { 250, 250, 210, 1 } }, - { "lightgray", { 211, 211, 211, 1 } }, { "lightgreen", { 144, 238, 144, 1 } }, - { "lightgrey", { 211, 211, 211, 1 } }, { "lightpink", { 255, 182, 193, 1 } }, - { "lightsalmon", { 255, 160, 122, 1 } }, { "lightseagreen", { 32, 178, 170, 1 } }, - { "lightskyblue", { 135, 206, 250, 1 } }, { "lightslategray", { 119, 136, 153, 1 } }, - { "lightslategrey", { 119, 136, 153, 1 } }, { "lightsteelblue", { 176, 196, 222, 1 } }, - { "lightyellow", { 255, 255, 224, 1 } }, { "lime", { 0, 255, 0, 1 } }, - { "limegreen", { 50, 205, 50, 1 } }, { "linen", { 250, 240, 230, 1 } }, - { "magenta", { 255, 0, 255, 1 } }, { "maroon", { 128, 0, 0, 1 } }, - { "mediumaquamarine", { 102, 205, 170, 1 } }, { "mediumblue", { 0, 0, 205, 1 } }, - { "mediumorchid", { 186, 85, 211, 1 } }, { "mediumpurple", { 147, 112, 219, 1 } }, - { "mediumseagreen", { 60, 179, 113, 1 } }, { "mediumslateblue", { 123, 104, 238, 1 } }, - { "mediumspringgreen", { 0, 250, 154, 1 } }, { "mediumturquoise", { 72, 209, 204, 1 } }, - { "mediumvioletred", { 199, 21, 133, 1 } }, { "midnightblue", { 25, 25, 112, 1 } }, - { "mintcream", { 245, 255, 250, 1 } }, { "mistyrose", { 255, 228, 225, 1 } }, - { "moccasin", { 255, 228, 181, 1 } }, { "navajowhite", { 255, 222, 173, 1 } }, - { "navy", { 0, 0, 128, 1 } }, { "oldlace", { 253, 245, 230, 1 } }, - { "olive", { 128, 128, 0, 1 } }, { "olivedrab", { 107, 142, 35, 1 } }, - { "orange", { 255, 165, 0, 1 } }, { "orangered", { 255, 69, 0, 1 } }, - { "orchid", { 218, 112, 214, 1 } }, { "palegoldenrod", { 238, 232, 170, 1 } }, - { "palegreen", { 152, 251, 152, 1 } }, { "paleturquoise", { 175, 238, 238, 1 } }, - { "palevioletred", { 219, 112, 147, 1 } }, { "papayawhip", { 255, 239, 213, 1 } }, - { "peachpuff", { 255, 218, 185, 1 } }, { "peru", { 205, 133, 63, 1 } }, - { "pink", { 255, 192, 203, 1 } }, { "plum", { 221, 160, 221, 1 } }, - { "powderblue", { 176, 224, 230, 1 } }, { "purple", { 128, 0, 128, 1 } }, - { "red", { 255, 0, 0, 1 } }, { "rosybrown", { 188, 143, 143, 1 } }, - { "royalblue", { 65, 105, 225, 1 } }, { "saddlebrown", { 139, 69, 19, 1 } }, - { "salmon", { 250, 128, 114, 1 } }, { "sandybrown", { 244, 164, 96, 1 } }, - { "seagreen", { 46, 139, 87, 1 } }, { "seashell", { 255, 245, 238, 1 } }, - { "sienna", { 160, 82, 45, 1 } }, { "silver", { 192, 192, 192, 1 } }, - { "skyblue", { 135, 206, 235, 1 } }, { "slateblue", { 106, 90, 205, 1 } }, - { "slategray", { 112, 128, 144, 1 } }, { "slategrey", { 112, 128, 144, 1 } }, - { "snow", { 255, 250, 250, 1 } }, { "springgreen", { 0, 255, 127, 1 } }, - { "steelblue", { 70, 130, 180, 1 } }, { "tan", { 210, 180, 140, 1 } }, - { "teal", { 0, 128, 128, 1 } }, { "thistle", { 216, 191, 216, 1 } }, - { "tomato", { 255, 99, 71, 1 } }, { "turquoise", { 64, 224, 208, 1 } }, - { "violet", { 238, 130, 238, 1 } }, { "wheat", { 245, 222, 179, 1 } }, - { "white", { 255, 255, 255, 1 } }, { "whitesmoke", { 245, 245, 245, 1 } }, - { "yellow", { 255, 255, 0, 1 } }, { "yellowgreen", { 154, 205, 50, 1 } } -}; - -template -uint8_t clamp_css_byte(T i) { // Clamp to integer 0 .. 255. - i = ::round(i); // Seems to be what Chrome does (vs truncation). - return i < 0 ? 0 : i > 255 ? 255 : uint8_t(i); -} - -template -float clamp_css_float(T f) { // Clamp to float 0.0 .. 1.0. - return f < 0 ? 0 : f > 1 ? 1 : float(f); -} - -float parseFloat(const std::string& str) { - return strtof(str.c_str(), nullptr); -} - -int64_t parseInt(const std::string& str, uint8_t base = 10) { - return strtoll(str.c_str(), nullptr, base); -} - -uint8_t parse_css_int(const std::string& str) { // int or percentage. - if (str.length() && str.back() == '%') { - return clamp_css_byte(parseFloat(str) / 100.0f * 255.0f); - } else { - return clamp_css_byte(parseInt(str)); - } -} - -float parse_css_float(const std::string& str) { // float or percentage. - if (str.length() && str.back() == '%') { - return clamp_css_float(parseFloat(str) / 100.0f); - } else { - return clamp_css_float(parseFloat(str)); - } -} - -float css_hue_to_rgb(float m1, float m2, float h) { - if (h < 0.0f) { - h += 1.0f; - } else if (h > 1.0f) { - h -= 1.0f; - } - - if (h * 6.0f < 1.0f) { - return m1 + (m2 - m1) * h * 6.0f; - } - if (h * 2.0f < 1.0f) { - return m2; - } - if (h * 3.0f < 2.0f) { - return m1 + (m2 - m1) * (2.0f / 3.0f - h) * 6.0f; - } - return m1; -} - - - -std::vector split(const std::string& s, char delim) { - std::vector elems; - std::stringstream ss(s); - std::string item; - while (std::getline(ss, item, delim)) { - elems.push_back(item); - } - return elems; -} - -std::optional parse(const std::string& css_str) { - std::string str = css_str; - - // Remove all whitespace, not compliant, but should just be more accepting. - str.erase(std::remove(str.begin(), str.end(), ' '), str.end()); - - // Convert to lowercase. - std::transform(str.begin(), str.end(), str.begin(), ::tolower); - - for (const auto& namedColor : namedColors) { - if (str == namedColor.name) { - return { namedColor.color }; - } - } - - // #abc and #abc123 syntax. - if (str.length() && str.front() == '#') { - if (str.length() == 4) { - int64_t iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing. - if (!(iv >= 0 && iv <= 0xfff)) { - return {}; - } else { - return {{ - static_cast(((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8)), - static_cast((iv & 0xf0) | ((iv & 0xf0) >> 4)), - static_cast((iv & 0xf) | ((iv & 0xf) << 4)), - 1 - }}; - } - } else if (str.length() == 7) { - int64_t iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing. - if (!(iv >= 0 && iv <= 0xffffff)) { - return {}; // Covers NaN. - } else { - return {{ - static_cast((iv & 0xff0000) >> 16), - static_cast((iv & 0xff00) >> 8), - static_cast(iv & 0xff), - 1 - }}; - } - } - - return {}; - } - - size_t op = str.find_first_of('('), ep = str.find_first_of(')'); - if (op != std::string::npos && ep + 1 == str.length()) { - const std::string fname = str.substr(0, op); - const std::vector params = split(str.substr(op + 1, ep - (op + 1)), ','); - - float alpha = 1.0f; - - if (fname == "rgba" || fname == "rgb") { - if (fname == "rgba") { - if (params.size() != 4) { - return {}; - } - alpha = parse_css_float(params.back()); - } else { - if (params.size() != 3) { - return {}; - } - } - - return {{ - parse_css_int(params[0]), - parse_css_int(params[1]), - parse_css_int(params[2]), - alpha - }}; - - } else if (fname == "hsla" || fname == "hsl") { - if (fname == "hsla") { - if (params.size() != 4) { - return {}; - } - alpha = parse_css_float(params.back()); - } else { - if (params.size() != 3) { - return {}; - } - } - - float h = parseFloat(params[0]) / 360.0f; - float i; - // Normalize the hue to [0..1[ - h = std::modf(h, &i); - - // NOTE(deanm): According to the CSS spec s/l should only be - // percentages, but we don't bother and let float or percentage. - float s = parse_css_float(params[1]); - float l = parse_css_float(params[2]); - - float m2 = l <= 0.5f ? l * (s + 1.0f) : l + s - l * s; - float m1 = l * 2.0f - m2; - - return {{ - clamp_css_byte(css_hue_to_rgb(m1, m2, h + 1.0f / 3.0f) * 255.0f), - clamp_css_byte(css_hue_to_rgb(m1, m2, h) * 255.0f), - clamp_css_byte(css_hue_to_rgb(m1, m2, h - 1.0f / 3.0f) * 255.0f), - alpha - }}; - } - } - - return {}; -} - -} // namespace CSSColorParser diff --git a/vendor/csscolorparser/csscolorparser/csscolorparser.hpp b/vendor/csscolorparser/csscolorparser/csscolorparser.hpp deleted file mode 100644 index 7b41bfa5de2..00000000000 --- a/vendor/csscolorparser/csscolorparser/csscolorparser.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// (c) Dean McNamee , 2012. -// C++ port by Mapbox, Konstantin Käfer , 2014-2017. -// -// https://github.com/deanm/css-color-parser-js -// https://github.com/kkaefer/css-color-parser-cpp -// -// 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. - -#ifndef CSS_COLOR_PARSER_CPP -#define CSS_COLOR_PARSER_CPP - -#include -#include -#include - -namespace CSSColorParser { - -struct Color { - inline Color() { - } - inline Color(unsigned char r_, unsigned char g_, unsigned char b_, float a_) - : r(r_), g(g_), b(b_), a(a_ > 1 ? 1 : a_ < 0 ? 0 : a_) { - } - unsigned char r = 0, g = 0, b = 0; - float a = 1.0f; -}; - -inline bool operator==(const Color& lhs, const Color& rhs) { - return lhs.r == rhs.r && lhs.g == rhs.g && lhs.b == rhs.b && ::fabs(lhs.a - rhs.a) < 0.0001f; -} - -inline bool operator!=(const Color& lhs, const Color& rhs) { - return !(lhs == rhs); -} - -std::optional parse(const std::string& css_str); - -} // namespace CSSColorParser - -#endif From e5b038b4306194f1727d3a98c5a71e9bf3b4b828 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 3 Aug 2024 19:15:58 -0400 Subject: [PATCH 02/56] cmake --- .github/workflows/android-ci.yml | 9 +++++++++ .github/workflows/node-ci.yml | 8 ++++++++ .github/workflows/qt-ci.yml | 8 ++++++++ .gitmodules | 3 +++ CMakeLists.txt | 8 +------- vendor/corrosion | 1 + 6 files changed, 30 insertions(+), 7 deletions(-) create mode 160000 vendor/corrosion diff --git a/.github/workflows/android-ci.yml b/.github/workflows/android-ci.yml index 2e6e9abd36b..79f50116dd1 100644 --- a/.github/workflows/android-ci.yml +++ b/.github/workflows/android-ci.yml @@ -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 + - name: Cache node modules uses: actions/cache@v4 env: @@ -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 + - name: Get CMake and Ninja uses: lukka/get-cmake@latest with: @@ -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 + - name: Build Render Test App run: | ./gradlew assemble assembleAndroidTest diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.yml index 8ab8485807d..80caea537a5 100644 --- a/.github/workflows/node-ci.yml +++ b/.github/workflows/node-ci.yml @@ -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 diff --git a/.github/workflows/qt-ci.yml b/.github/workflows/qt-ci.yml index 521f0217963..2e28d77fc29 100644 --- a/.github/workflows/qt-ci.yml +++ b/.github/workflows/qt-ci.yml @@ -206,6 +206,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 diff --git a/.gitmodules b/.gitmodules index c878230b910..b7d91b51205 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 900e722f296..68572c97b8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1439,13 +1439,7 @@ set_target_properties( INTERFACE_MAPBOX_LICENSE ${PROJECT_SOURCE_DIR}/vendor/unordered_dense/LICENSE ) -include(FetchContent) -FetchContent_Declare( - Corrosion - GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git - GIT_TAG v0.5 -) -FetchContent_MakeAvailable(Corrosion) +add_subdirectory(${PROJECT_SOURCE_DIR}/vendor/corrosion) corrosion_import_crate(MANIFEST_PATH rustutils/Cargo.toml) # rustutils_headers is a set of .h headers generated from rustutils crate diff --git a/vendor/corrosion b/vendor/corrosion new file mode 160000 index 00000000000..64289b1d79d --- /dev/null +++ b/vendor/corrosion @@ -0,0 +1 @@ +Subproject commit 64289b1d79d6d19cd2e241db515381a086bb8407 From cad4ff465c6fd520587ea8d6ea0a9e229a397c6b Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 3 Aug 2024 21:53:49 -0400 Subject: [PATCH 03/56] cxx --- .github/workflows/linux-ci.yml | 3 ++ rustutils/BUILD | 35 ++++++++++++++++++++++ scripts/bazel/BUILD | 19 ++++++++++++ scripts/bazel/extension.bzl | 22 ++++++++++++++ scripts/bazel/rust_cxx_bridge.bzl | 49 +++++++++++++++++++++++++++++++ 5 files changed, 128 insertions(+) create mode 100644 rustutils/BUILD create mode 100644 scripts/bazel/BUILD create mode 100644 scripts/bazel/extension.bzl create mode 100644 scripts/bazel/rust_cxx_bridge.bzl diff --git a/.github/workflows/linux-ci.yml b/.github/workflows/linux-ci.yml index 2ddbe30ab1f..2a087e5599b 100644 --- a/.github/workflows/linux-ci.yml +++ b/.github/workflows/linux-ci.yml @@ -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: diff --git a/rustutils/BUILD b/rustutils/BUILD new file mode 100644 index 00000000000..3de1cce884c --- /dev/null +++ b/rustutils/BUILD @@ -0,0 +1,35 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_rust//rust:defs.bzl", "rust_binary") +load("//tools/bazel:rust_cxx_bridge.bzl", "rust_cxx_bridge") + +rust_binary( + name = "demo", + srcs = glob(["src/**/*.rs"]), + edition = "2021", + deps = [ + ":blobstore-sys", + ":bridge", + "//:cxx", + ], +) + +rust_cxx_bridge( + name = "bridge", + src = "src/main.rs", + deps = [":blobstore-include"], +) + +cc_library( + name = "blobstore-sys", + srcs = ["src/blobstore.cc"], + deps = [ + ":blobstore-include", + ":bridge/include", + ], +) + +cc_library( + name = "blobstore-include", + hdrs = ["include/blobstore.h"], + deps = ["//:core"], +) diff --git a/scripts/bazel/BUILD b/scripts/bazel/BUILD new file mode 100644 index 00000000000..63c8db9e534 --- /dev/null +++ b/scripts/bazel/BUILD @@ -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"], +) diff --git a/scripts/bazel/extension.bzl b/scripts/bazel/extension.bzl new file mode 100644 index 00000000000..1d1ae0bda76 --- /dev/null +++ b/scripts/bazel/extension.bzl @@ -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, +) diff --git a/scripts/bazel/rust_cxx_bridge.bzl b/scripts/bazel/rust_cxx_bridge.bzl new file mode 100644 index 00000000000..c7d07e8a109 --- /dev/null +++ b/scripts/bazel/rust_cxx_bridge.bzl @@ -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 = "@cxx.rs//:codegen", + ) + + cc_library( + name = name, + srcs = [src + ".cc"], + deps = deps + [":%s/include" % name], + ) + + cc_library( + name = "%s/include" % name, + hdrs = [src + ".h"], + ) From dc0defe8fc91a7df6c585565106893de8cc64d14 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sun, 4 Aug 2024 14:40:12 -0400 Subject: [PATCH 04/56] wip --- CMakeLists.txt | 10 +++--- bazel/BUILD.bazel | 19 +++++++++++ bazel/extension.bzl | 22 ++++++++++++ {scripts/bazel => bazel}/rust_cxx_bridge.bzl | 0 docker/Dockerfile | 20 ++++++++--- docker/startup.sh | 27 +++++++++++++-- rustutils/BUILD | 35 -------------------- rustutils/BUILD.bazel | 17 ++++++++++ scripts/bazel/BUILD | 19 ----------- scripts/bazel/extension.bzl | 22 ------------ src/mbgl/util/color.cpp | 2 +- 11 files changed, 104 insertions(+), 89 deletions(-) create mode 100644 bazel/extension.bzl rename {scripts/bazel => bazel}/rust_cxx_bridge.bzl (100%) delete mode 100644 rustutils/BUILD create mode 100644 rustutils/BUILD.bazel delete mode 100644 scripts/bazel/BUILD delete mode 100644 scripts/bazel/extension.bzl diff --git a/CMakeLists.txt b/CMakeLists.txt index 68572c97b8e..f6a6adcd844 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1442,11 +1442,11 @@ set_target_properties( add_subdirectory(${PROJECT_SOURCE_DIR}/vendor/corrosion) corrosion_import_crate(MANIFEST_PATH rustutils/Cargo.toml) -# rustutils_headers is a set of .h headers generated from rustutils crate -corrosion_add_cxxbridge(rustutils_headers CRATE rustutils FILES lib.rs) +# 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_headers + rustutils_bridge PROPERTIES INTERFACE_MAPBOX_NAME "Rust Utils" INTERFACE_MAPBOX_AUTHOR "Yuri Astrakhan" @@ -1471,7 +1471,7 @@ target_link_libraries( mbgl-vendor-unique_resource mbgl-vendor-vector-tile mbgl-vendor-wagyu - rustutils_headers + rustutils_bridge PUBLIC Mapbox::Base Mapbox::Base::Extras::expected-lite @@ -1485,7 +1485,7 @@ target_link_libraries( ) export(TARGETS - rustutils_headers + rustutils_bridge mbgl-core rustutils mapbox-base diff --git a/bazel/BUILD.bazel b/bazel/BUILD.bazel index e69de29bb2d..94b44225327 100644 --- a/bazel/BUILD.bazel +++ b/bazel/BUILD.bazel @@ -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"], +#) diff --git a/bazel/extension.bzl b/bazel/extension.bzl new file mode 100644 index 00000000000..e54168a0dc7 --- /dev/null +++ b/bazel/extension.bzl @@ -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, +#) diff --git a/scripts/bazel/rust_cxx_bridge.bzl b/bazel/rust_cxx_bridge.bzl similarity index 100% rename from scripts/bazel/rust_cxx_bridge.bzl rename to bazel/rust_cxx_bridge.bzl diff --git a/docker/Dockerfile b/docker/Dockerfile index 2549642fa9e..7a6211e4668 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,3 +1,4 @@ +# Ubuntu version should match SWIFT version below FROM ubuntu:22.04 # Install build tools and dependencies @@ -23,11 +24,15 @@ RUN apt-get update \ ccache \ ninja-build \ pkg-config \ + python3 \ + python3-pip \ + python-is-python3 \ && : # end of the RUN cmd - easier to keep a colon at the end of the list, than to keep the backslashes in check # This could also be `.../releases/latest/download/bazelisk-linux-amd64` for the latest version, but for predictability better hardcode it # Detect if current CPU is x64 or ARM64 and download the appropriate binary -RUN if [ "$(uname -m)" = "aarch64" ]; then \ +RUN echo "Download and install Bazel" \ + && if [ "$(uname -m)" = "aarch64" ]; then \ curl -fsSL https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-linux-arm64 -o /usr/local/bin/bazel ;\ else \ curl -fsSL https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-linux-amd64 -o /usr/local/bin/bazel ;\ @@ -35,7 +40,6 @@ RUN if [ "$(uname -m)" = "aarch64" ]; then \ && chmod +x /usr/local/bin/bazel \ && : -WORKDIR /app ARG USERNAME=user ARG USER_UID=1000 @@ -49,15 +53,21 @@ RUN groupadd --force --gid $USER_GID $USERNAME \ && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ && chmod 0440 /etc/sudoers.d/$USERNAME -COPY startup.sh /usr/local/bin/startup.sh -RUN chmod +x /usr/local/bin/startup.sh - # This allows users to `docker run` without specifying -u and -g USER $USERNAME +RUN pip install pre-commit + ENV RUSTUP_HOME=/home/$USERNAME/.cache/.rustup \ CARGO_HOME=/home/$USERNAME/.cache/.cargo \ PATH=/home/$USERNAME/.cache/.cargo/bin:$PATH +# As the very last step, copy the startup script +USER root +COPY startup.sh /usr/local/bin/startup.sh +RUN chmod +x /usr/local/bin/startup.sh +USER $USERNAME + +WORKDIR /app ENTRYPOINT ["/usr/local/bin/startup.sh"] CMD ["bash"] diff --git a/docker/startup.sh b/docker/startup.sh index 81530303dc7..6f59dbad338 100644 --- a/docker/startup.sh +++ b/docker/startup.sh @@ -1,15 +1,37 @@ #!/bin/sh -if [ ! -d /app/.github ] || [ ! -d /home/user/.cache ]; then +if [ ! -d /app/.github ] || [ ! -d ~/.cache ]; then echo " " echo "ERROR: Docker container was not started properly." echo " From the root of this repo, run the following command." echo " You may add any command to perform in the container at the end of this command." echo " " - echo ' docker run --rm -it -v "$PWD:/app/" -v "$PWD/docker/.cache:/home/user/.cache" maplibre-native-image' + echo " docker run --rm -it -v \"$PWD:/app/\" -v \"$PWD/docker/.cache:/home/$USERNAME/.cache\" maplibre-native-image" exit 1 fi +export PATH="$PATH:~/.local/bin/" + + +# Work in progress: install and configure Swift and pre-commit +# Detect if current CPU is x64 or ARM64 and download the appropriate binary +#RUN echo "Download and install SWIFT" \ +# && if [ "$(uname -m)" = "aarch64" ]; then \ +# curl -fsSL https://download.swift.org/swift-5.10.1-release/ubuntu2204-aarch64/swift-5.10.1-RELEASE/swift-5.10.1-RELEASE-ubuntu22.04-aarch64.tar.gz \ +# -o /tmp/swift.tar.gz ;\ +# else \ +# curl -fsSL https://download.swift.org/swift-5.10.1-release/ubuntu2204/swift-5.10.1-RELEASE/swift-5.10.1-RELEASE-ubuntu22.04.tar.gz \ +# -o /tmp/swift.tar.gz ;\ +# fi \ +# && tar -xzf /tmp/swift.tar.gz -C / --strip-components=1 \ +# && rm /tmp/swift.tar.gz \ +# && : +#if [ ! -f "/app/.git/hooks/pre-commit" ]; then +# echo "Configuring pre-commit git hooks by creating a .git/hooks/pre-commit file..." +# ~/.local/bin/pre-commit install +#fi + + if [ ! -f "$CARGO_HOME/env" ]; then echo "Downloading and installing Rust..." @@ -25,4 +47,5 @@ if ! command -v cxxbridge > /dev/null; then fi + exec "$@" diff --git a/rustutils/BUILD b/rustutils/BUILD deleted file mode 100644 index 3de1cce884c..00000000000 --- a/rustutils/BUILD +++ /dev/null @@ -1,35 +0,0 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") -load("@rules_rust//rust:defs.bzl", "rust_binary") -load("//tools/bazel:rust_cxx_bridge.bzl", "rust_cxx_bridge") - -rust_binary( - name = "demo", - srcs = glob(["src/**/*.rs"]), - edition = "2021", - deps = [ - ":blobstore-sys", - ":bridge", - "//:cxx", - ], -) - -rust_cxx_bridge( - name = "bridge", - src = "src/main.rs", - deps = [":blobstore-include"], -) - -cc_library( - name = "blobstore-sys", - srcs = ["src/blobstore.cc"], - deps = [ - ":blobstore-include", - ":bridge/include", - ], -) - -cc_library( - name = "blobstore-include", - hdrs = ["include/blobstore.h"], - deps = ["//:core"], -) diff --git a/rustutils/BUILD.bazel b/rustutils/BUILD.bazel new file mode 100644 index 00000000000..f7ac41475fb --- /dev/null +++ b/rustutils/BUILD.bazel @@ -0,0 +1,17 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_rust//rust:defs.bzl", "rust_static_library") +load("//bazel:rust_cxx_bridge.bzl", "rust_cxx_bridge") + +rust_static_library( + name = "rustutils", + srcs = glob(["src/**/*.rs"]), + edition = "2021", + deps = [ + ":bridge", + ], +) + +rust_cxx_bridge( + name = "bridge", + src = "src/lib.rs", +) diff --git a/scripts/bazel/BUILD b/scripts/bazel/BUILD deleted file mode 100644 index 63c8db9e534..00000000000 --- a/scripts/bazel/BUILD +++ /dev/null @@ -1,19 +0,0 @@ -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"], -) diff --git a/scripts/bazel/extension.bzl b/scripts/bazel/extension.bzl deleted file mode 100644 index 1d1ae0bda76..00000000000 --- a/scripts/bazel/extension.bzl +++ /dev/null @@ -1,22 +0,0 @@ -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, -) diff --git a/src/mbgl/util/color.cpp b/src/mbgl/util/color.cpp index 433e8b8ee96..30aed5fe299 100644 --- a/src/mbgl/util/color.cpp +++ b/src/mbgl/util/color.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include namespace mbgl { From 46ac304049b9de15295596fc9148cb228745025b Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Mon, 5 Aug 2024 05:25:01 -0400 Subject: [PATCH 05/56] add armv7-linux-androideabi --- .github/workflows/android-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/android-ci.yml b/.github/workflows/android-ci.yml index 79f50116dd1..47c890b3831 100644 --- a/.github/workflows/android-ci.yml +++ b/.github/workflows/android-ci.yml @@ -71,7 +71,7 @@ jobs: 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 + 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 @@ -178,7 +178,7 @@ jobs: 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 + 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 @@ -230,7 +230,7 @@ jobs: 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 + 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: | From 0aacaafa7ce657692bbfe0b5158eb4451831cfa5 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Mon, 5 Aug 2024 13:44:09 -0400 Subject: [PATCH 06/56] add rust to qt docker build --- .github/actions/qt5-build/entrypoint.sh | 3 +++ .github/actions/qt6-build/entrypoint.sh | 3 +++ 2 files changed, 6 insertions(+) diff --git a/.github/actions/qt5-build/entrypoint.sh b/.github/actions/qt5-build/entrypoint.sh index e651013cda7..2eb47c287d2 100755 --- a/.github/actions/qt5-build/entrypoint.sh +++ b/.github/actions/qt5-build/entrypoint.sh @@ -8,6 +8,9 @@ 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 + mkdir build && cd build cmake ../source/ \ -G Ninja \ diff --git a/.github/actions/qt6-build/entrypoint.sh b/.github/actions/qt6-build/entrypoint.sh index 702bcc3f8f7..e5aa3fd4bfb 100755 --- a/.github/actions/qt6-build/entrypoint.sh +++ b/.github/actions/qt6-build/entrypoint.sh @@ -8,6 +8,9 @@ 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 + mkdir build && cd build qt-cmake ../source/ \ -G Ninja \ From 2847d275e9f094dcbab879d04fa5dcfdcc0123fc Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Mon, 5 Aug 2024 13:52:28 -0400 Subject: [PATCH 07/56] fix --- .github/actions/qt5-build/entrypoint.sh | 1 + .github/actions/qt6-build/entrypoint.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/actions/qt5-build/entrypoint.sh b/.github/actions/qt5-build/entrypoint.sh index 2eb47c287d2..8cb293bb715 100755 --- a/.github/actions/qt5-build/entrypoint.sh +++ b/.github/actions/qt5-build/entrypoint.sh @@ -10,6 +10,7 @@ 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 +. "$HOME/.cargo/env" mkdir build && cd build cmake ../source/ \ diff --git a/.github/actions/qt6-build/entrypoint.sh b/.github/actions/qt6-build/entrypoint.sh index e5aa3fd4bfb..74476d85c57 100755 --- a/.github/actions/qt6-build/entrypoint.sh +++ b/.github/actions/qt6-build/entrypoint.sh @@ -10,6 +10,7 @@ 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 +. "$HOME/.cargo/env" mkdir build && cd build qt-cmake ../source/ \ From 4752a7de747379e8250a1eaa54d195b3e9e75cb1 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Mon, 5 Aug 2024 13:58:20 -0400 Subject: [PATCH 08/56] fix --- .github/actions/qt5-build/entrypoint.sh | 3 ++- .github/actions/qt6-build/entrypoint.sh | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/actions/qt5-build/entrypoint.sh b/.github/actions/qt5-build/entrypoint.sh index 8cb293bb715..6e7e554994a 100755 --- a/.github/actions/qt5-build/entrypoint.sh +++ b/.github/actions/qt5-build/entrypoint.sh @@ -10,7 +10,8 @@ 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 -. "$HOME/.cargo/env" +# 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/ \ diff --git a/.github/actions/qt6-build/entrypoint.sh b/.github/actions/qt6-build/entrypoint.sh index 74476d85c57..434f470e6a8 100755 --- a/.github/actions/qt6-build/entrypoint.sh +++ b/.github/actions/qt6-build/entrypoint.sh @@ -10,7 +10,8 @@ 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 -. "$HOME/.cargo/env" +# 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/ \ From cc8eb726b34d6394e35e8f63324d9c866d5613c8 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Mon, 5 Aug 2024 14:44:47 -0400 Subject: [PATCH 09/56] build all qt --- .github/workflows/qt-ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/qt-ci.yml b/.github/workflows/qt-ci.yml index 2e28d77fc29..f99fb863859 100644 --- a/.github/workflows/qt-ci.yml +++ b/.github/workflows/qt-ci.yml @@ -52,7 +52,12 @@ on: concurrency: # cancel jobs on PRs only group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} +# +# +# FIXME: reenable this +# +# cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} + cancel-in-progress: false jobs: build: From e07f5c8969501e6c6484f0049d241e16a92bed0c Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Mon, 5 Aug 2024 15:04:41 -0400 Subject: [PATCH 10/56] build all qt --- .github/workflows/qt-ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/qt-ci.yml b/.github/workflows/qt-ci.yml index f99fb863859..e60803fc1f7 100644 --- a/.github/workflows/qt-ci.yml +++ b/.github/workflows/qt-ci.yml @@ -49,19 +49,19 @@ on: - ".gitmodules" - "!**/*.md" -concurrency: - # cancel jobs on PRs only - group: ${{ github.workflow }}-${{ github.ref }} # # # FIXME: reenable this # +#concurrency: +# # cancel jobs on PRs only +# group: ${{ github.workflow }}-${{ github.ref }} # cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} - cancel-in-progress: false jobs: build: strategy: + fail-fast: false # FIXME: delete! matrix: include: - name: Linux From 0afbe40e02739968d055ff613ca95ea2b8bcee67 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Mon, 5 Aug 2024 23:25:38 -0400 Subject: [PATCH 11/56] wip --- rustutils/BUILD.bazel | 17 ----------------- rustutils/MODULE.bazel | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 17 deletions(-) delete mode 100644 rustutils/BUILD.bazel create mode 100644 rustutils/MODULE.bazel diff --git a/rustutils/BUILD.bazel b/rustutils/BUILD.bazel deleted file mode 100644 index f7ac41475fb..00000000000 --- a/rustutils/BUILD.bazel +++ /dev/null @@ -1,17 +0,0 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") -load("@rules_rust//rust:defs.bzl", "rust_static_library") -load("//bazel:rust_cxx_bridge.bzl", "rust_cxx_bridge") - -rust_static_library( - name = "rustutils", - srcs = glob(["src/**/*.rs"]), - edition = "2021", - deps = [ - ":bridge", - ], -) - -rust_cxx_bridge( - name = "bridge", - src = "src/lib.rs", -) diff --git a/rustutils/MODULE.bazel b/rustutils/MODULE.bazel new file mode 100644 index 00000000000..0ed58633535 --- /dev/null +++ b/rustutils/MODULE.bazel @@ -0,0 +1,26 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_rust//rust:defs.bzl", "rust_static_library") +load("//bazel:rust_cxx_bridge.bzl", "rust_cxx_bridge") + +crate = use_extension("@rules_rust//crate_universe:docs_bzlmod.bzl", "crate") +crate.from_cargo( + name = "crates", + cargo_lockfile = "//:Cargo.lock", + manifests = ["//:Cargo.toml"], +) +use_repo(crate, "crates") + +# +#rust_static_library( +# name = "rustutils", +# srcs = glob(["src/**/*.rs"]), +# edition = "2021", +# deps = [ +# ":bridge", +# ], +#) +# +#rust_cxx_bridge( +# name = "bridge", +# src = "src/lib.rs", +#) From c157da8ee6494f3ebdc932a11b5af54d87e4b277 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 7 Aug 2024 11:18:04 -0400 Subject: [PATCH 12/56] wip --- BUILD.bazel | 1 + rustutils/BUILD.bazel | 14 ++++++++++++++ rustutils/MODULE.bazel | 26 -------------------------- 3 files changed, 15 insertions(+), 26 deletions(-) create mode 100644 rustutils/BUILD.bazel delete mode 100644 rustutils/MODULE.bazel diff --git a/BUILD.bazel b/BUILD.bazel index 0692289a0c2..72b9c0d6539 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -123,6 +123,7 @@ cc_library( deps = [ ":mbgl-core-generated-private-artifacts", ":mbgl-core-generated-public-artifacts", + "//rustutils:rustutils", "//vendor:boost", "//vendor:earcut.hpp", "//vendor:eternal", diff --git a/rustutils/BUILD.bazel b/rustutils/BUILD.bazel new file mode 100644 index 00000000000..fb81056a608 --- /dev/null +++ b/rustutils/BUILD.bazel @@ -0,0 +1,14 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_static_library") +load("//bazel:rust_cxx_bridge.bzl", "rust_cxx_bridge") + +rust_cxx_bridge( + name = "bridge", + src = "src/lib.rs", +) + +rust_static_library( + name = "rustutils", + srcs = ["src/**/*.rs"], + edition = "2021", +) diff --git a/rustutils/MODULE.bazel b/rustutils/MODULE.bazel deleted file mode 100644 index 0ed58633535..00000000000 --- a/rustutils/MODULE.bazel +++ /dev/null @@ -1,26 +0,0 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") -load("@rules_rust//rust:defs.bzl", "rust_static_library") -load("//bazel:rust_cxx_bridge.bzl", "rust_cxx_bridge") - -crate = use_extension("@rules_rust//crate_universe:docs_bzlmod.bzl", "crate") -crate.from_cargo( - name = "crates", - cargo_lockfile = "//:Cargo.lock", - manifests = ["//:Cargo.toml"], -) -use_repo(crate, "crates") - -# -#rust_static_library( -# name = "rustutils", -# srcs = glob(["src/**/*.rs"]), -# edition = "2021", -# deps = [ -# ":bridge", -# ], -#) -# -#rust_cxx_bridge( -# name = "bridge", -# src = "src/lib.rs", -#) From 61f7d3feae9c791f348a7f97cc00bcb3fd4d1294 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 7 Aug 2024 11:45:56 -0400 Subject: [PATCH 13/56] wip --- BUILD.bazel | 1 + MODULE.bazel | 6 ++++++ bazel/extension.bzl | 44 +++++++++++++++++++++---------------------- rustutils/BUILD.bazel | 4 +++- 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 72b9c0d6539..31b835bd8e4 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -123,6 +123,7 @@ cc_library( deps = [ ":mbgl-core-generated-private-artifacts", ":mbgl-core-generated-public-artifacts", + "//rustutils:bridge", "//rustutils:rustutils", "//vendor:boost", "//vendor:earcut.hpp", diff --git a/MODULE.bazel b/MODULE.bazel index 97704d2e93b..440b366a44c 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -7,6 +7,12 @@ bazel_dep(name = "platforms", version = "0.0.10") bazel_dep(name = "rules_apple", version = "3.7.0", repo_name = "build_bazel_rules_apple") bazel_dep(name = "rules_swift", version = "2.1.1", repo_name = "build_bazel_rules_swift") bazel_dep(name = "rules_xcodeproj", version = "2.5.2") +bazel_dep(name = "rules_rust", version = "0.49.0") + +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") npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm") npm.npm_translate_lock( diff --git a/bazel/extension.bzl b/bazel/extension.bzl index e54168a0dc7..1d1ae0bda76 100644 --- a/bazel/extension.bzl +++ b/bazel/extension.bzl @@ -1,22 +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, -#) +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, +) diff --git a/rustutils/BUILD.bazel b/rustutils/BUILD.bazel index fb81056a608..ba4901425a7 100644 --- a/rustutils/BUILD.bazel +++ b/rustutils/BUILD.bazel @@ -2,6 +2,8 @@ load("@rules_cc//cc:defs.bzl", "cc_library") load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_static_library") load("//bazel:rust_cxx_bridge.bzl", "rust_cxx_bridge") +package(default_visibility = ["//visibility:public"]) + rust_cxx_bridge( name = "bridge", src = "src/lib.rs", @@ -9,6 +11,6 @@ rust_cxx_bridge( rust_static_library( name = "rustutils", - srcs = ["src/**/*.rs"], + srcs = ["src/lib.rs"], edition = "2021", ) From 5e404f4acce7c7c1dd33e41201215a6db44cb46a Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 7 Aug 2024 17:39:04 -0400 Subject: [PATCH 14/56] wip --- MODULE.bazel | 17 +++++++++------ bazel/extension.bzl | 44 +++++++++++++++++++-------------------- bazel/rust_cxx_bridge.bzl | 2 +- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 440b366a44c..3f850547253 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -7,12 +7,6 @@ bazel_dep(name = "platforms", version = "0.0.10") bazel_dep(name = "rules_apple", version = "3.7.0", repo_name = "build_bazel_rules_apple") bazel_dep(name = "rules_swift", version = "2.1.1", repo_name = "build_bazel_rules_swift") bazel_dep(name = "rules_xcodeproj", version = "2.5.2") -bazel_dep(name = "rules_rust", version = "0.49.0") - -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") npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm") npm.npm_translate_lock( @@ -66,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") diff --git a/bazel/extension.bzl b/bazel/extension.bzl index 1d1ae0bda76..e54168a0dc7 100644 --- a/bazel/extension.bzl +++ b/bazel/extension.bzl @@ -1,22 +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, -) +#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, +#) diff --git a/bazel/rust_cxx_bridge.bzl b/bazel/rust_cxx_bridge.bzl index c7d07e8a109..304a9f3c327 100644 --- a/bazel/rust_cxx_bridge.bzl +++ b/bazel/rust_cxx_bridge.bzl @@ -34,7 +34,7 @@ def rust_cxx_bridge(name, src, deps = []): "-o", "$(location %s.cc)" % src, ], - tool = "@cxx.rs//:codegen", + 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( From f2b7b7b029ad24b1aac14d7818bae5646588f319 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 10 Jan 2025 16:40:43 +0100 Subject: [PATCH 15/56] Add Bazel support --- .gitmodules | 3 - BUILD.bazel | 26 +- CMakeLists.txt | 35 +-- MODULE.bazel | 18 +- bazel/core.bzl | 10 +- bazel/extension.bzl | 22 -- bazel/rust_cxx_bridge.bzl | 49 --- docs/mdbook/src/SUMMARY.md | 2 + docs/mdbook/src/rust.md | 27 ++ rustutils/BUILD.bazel | 39 ++- rustutils/README.md | 1 + rustutils/cpp/generate.sh | 8 + rustutils/cpp/include/rustutils/lib.hpp | 86 ++++++ rustutils/cpp/src/lib.rs.cc | 91 ++++++ rustutils/rustutils.cmake | 28 ++ scripts/license.cmake | 2 +- src/mbgl/util/color.cpp | 13 +- src/mbgl/util/color.rs.cpp | 56 ++++ vendor/BUILD.bazel | 14 + vendor/corrosion | 1 - vendor/csscolorparser.cmake | 37 +++ .../csscolorparser/LICENSE | 23 +- vendor/csscolorparser/csscolorparser.cpp | 288 ++++++++++++++++++ .../csscolorparser/csscolorparser.hpp | 56 ++++ 24 files changed, 799 insertions(+), 136 deletions(-) delete mode 100644 bazel/extension.bzl delete mode 100644 bazel/rust_cxx_bridge.bzl create mode 100644 docs/mdbook/src/rust.md create mode 100644 rustutils/README.md create mode 100755 rustutils/cpp/generate.sh create mode 100644 rustutils/cpp/include/rustutils/lib.hpp create mode 100644 rustutils/cpp/src/lib.rs.cc create mode 100644 rustutils/rustutils.cmake create mode 100644 src/mbgl/util/color.rs.cpp delete mode 160000 vendor/corrosion create mode 100644 vendor/csscolorparser.cmake rename rustutils/LICENSE-MIT => vendor/csscolorparser/LICENSE (56%) create mode 100644 vendor/csscolorparser/csscolorparser.cpp create mode 100644 vendor/csscolorparser/csscolorparser/csscolorparser.hpp diff --git a/.gitmodules b/.gitmodules index 92f61f6decd..72537dd37ef 100644 --- a/.gitmodules +++ b/.gitmodules @@ -55,9 +55,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 [submodule "vendor/PMTiles"] path = vendor/PMTiles url = https://github.com/protomaps/PMTiles.git diff --git a/BUILD.bazel b/BUILD.bazel index 6e18ee00ebc..fc59dd2a766 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,5 +1,5 @@ load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_library", "js_run_binary") -load("@bazel_skylib//rules:common_settings.bzl", "string_flag") +load("@bazel_skylib//rules:common_settings.bzl", "string_flag", "bool_flag") load("@npm//:defs.bzl", "npm_link_all_packages") load( "//bazel:core.bzl", @@ -123,8 +123,6 @@ cc_library( deps = [ ":mbgl-core-generated-private-artifacts", ":mbgl-core-generated-public-artifacts", - "//rustutils:bridge", - "//rustutils:rustutils", "//vendor:boost", "//vendor:earcut.hpp", "//vendor:eternal", @@ -150,7 +148,14 @@ cc_library( "//vendor:metal-cpp", ], "//conditions:default": [], - }), + }) + select({ + ":rust": [ + "//rustutils:rustutilslib", + ], + "//conditions:default": [ + "//vendor:csscolorparser", + ] + }) ) genrule( @@ -196,6 +201,19 @@ config_setting( }, ) +bool_flag( + name = "use_rust", + build_setting_default = False, + visibility = ["//visibility:public"], +) + +config_setting( + name = "rust", + flag_values = { + "//:use_rust": "true", + }, +) + exports_files( [ "LICENSE.md", diff --git a/CMakeLists.txt b/CMakeLists.txt index 63f297da2e6..904c4b3ec7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ option(MLN_LEGACY_RENDERER "Include the legacy rendering pathway" ON) option(MLN_DRAWABLE_RENDERER "Include the drawable rendering pathway" OFF) option(MLN_USE_UNORDERED_DENSE "Use ankerl dense containers for performance" ON) option(MLN_USE_TRACY "Enable Tracy instrumentation" OFF) +option(MLN_USE_RUST "Use components in Rust" OFF) if (MLN_WITH_CLANG_TIDY) find_program(CLANG_TIDY_COMMAND NAMES clang-tidy) @@ -940,7 +941,7 @@ list(APPEND SRC_FILES ${PROJECT_SOURCE_DIR}/src/mbgl/util/bounding_volumes.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/util/chrono.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/util/client_options.cpp - ${PROJECT_SOURCE_DIR}/src/mbgl/util/color.cpp + ${PROJECT_SOURCE_DIR}/src/mbgl/util/color$,.rs.cpp,.cpp> ${PROJECT_SOURCE_DIR}/src/mbgl/util/constants.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/util/convert.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/util/event.cpp @@ -1443,6 +1444,7 @@ 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) @@ -1457,19 +1459,7 @@ include(${PROJECT_SOURCE_DIR}/vendor/vector-tile.cmake) include(${PROJECT_SOURCE_DIR}/vendor/wagyu.cmake) include(${PROJECT_SOURCE_DIR}/vendor/metal-cpp.cmake) -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_MAPLIBRE_NAME "Rust Utils" - INTERFACE_MAPLIBRE_AUTHOR "MapLibre Contributors" - INTERFACE_MAPLIBRE_LICENSE ${CMAKE_CURRENT_LIST_DIR}/rustutils/LICENSE-MIT -) +include(${PROJECT_SOURCE_DIR}/rustutils/rustutils.cmake) target_link_libraries( mbgl-core @@ -1490,8 +1480,8 @@ target_link_libraries( mbgl-vendor-unique_resource mbgl-vendor-vector-tile mbgl-vendor-wagyu - rustutils_bridge $<$:mbgl-vendor-metal-cpp> + $,mbgl-rustutils,mbgl-vendor-csscolorparser> PUBLIC Mapbox::Base Mapbox::Base::Extras::expected-lite @@ -1501,13 +1491,10 @@ target_link_libraries( Mapbox::Base::variant $<$:TracyClient> unordered_dense - rustutils ) -export(TARGETS - rustutils_bridge +set(EXPORT_TARGETS mbgl-core - rustutils mapbox-base mapbox-base-cheap-ruler-cpp mapbox-base-extras-expected-lite @@ -1534,10 +1521,16 @@ export(TARGETS mbgl-vendor-wagyu mbgl-vendor-metal-cpp unordered_dense - - FILE MapboxCoreTargets.cmake ) +if(MLN_USE_RUST) + list(APPEND EXPORT_TARGETS mbgl-rustutils rustutils) +else() + list(APPEND EXPORT_TARGETS mbgl-vendor-csscolorparser) +endif() + +export(TARGETS ${EXPORT_TARGETS} FILE MapboxCoreTargets.cmake) + if(MLN_WITH_VULKAN) include(${PROJECT_SOURCE_DIR}/vendor/vulkan.cmake) diff --git a/MODULE.bazel b/MODULE.bazel index bb82f4036ea..c0b578d5c05 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -61,13 +61,23 @@ darwin_config( name = "darwin_config", ) -bazel_dep(name = "rules_rust", version = "0.49.1") +bazel_dep(name = "rules_rust", version = "0.56.0") rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") -rust.toolchain(versions = ["1.80.0"]) + +rust.toolchain( + edition = "2021", + 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") +crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate") + +crate.from_cargo( + name = "crates", + cargo_lockfile = "//rustutils:Cargo.lock", + manifests = ["//rustutils:Cargo.toml"], +) +use_repo(crate, "crates") diff --git a/bazel/core.bzl b/bazel/core.bzl index 6d7dbca391d..6f31b587e1a 100644 --- a/bazel/core.bzl +++ b/bazel/core.bzl @@ -584,7 +584,6 @@ MLN_CORE_SOURCE = [ "src/mbgl/util/bounding_volumes.cpp", "src/mbgl/util/chrono.cpp", "src/mbgl/util/client_options.cpp", - "src/mbgl/util/color.cpp", "src/mbgl/util/constants.cpp", "src/mbgl/util/convert.cpp", "src/mbgl/util/event.cpp", @@ -652,7 +651,14 @@ MLN_CORE_SOURCE = [ "src/mbgl/util/version.cpp", "src/mbgl/util/version.hpp", "src/mbgl/util/work_request.cpp", -] +] + select({ + "//:rust": [ + "src/mbgl/util/color.rs.cpp", + ], + "//conditions:default": [ + "src/mbgl/util/color.cpp", + ] +}) MLN_CORE_HEADERS = [ "include/mbgl/gfx/context.hpp", diff --git a/bazel/extension.bzl b/bazel/extension.bzl deleted file mode 100644 index e54168a0dc7..00000000000 --- a/bazel/extension.bzl +++ /dev/null @@ -1,22 +0,0 @@ -#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, -#) diff --git a/bazel/rust_cxx_bridge.bzl b/bazel/rust_cxx_bridge.bzl deleted file mode 100644 index 304a9f3c327..00000000000 --- a/bazel/rust_cxx_bridge.bzl +++ /dev/null @@ -1,49 +0,0 @@ -# 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"], - ) diff --git a/docs/mdbook/src/SUMMARY.md b/docs/mdbook/src/SUMMARY.md index d07b042abd6..951078c58f4 100644 --- a/docs/mdbook/src/SUMMARY.md +++ b/docs/mdbook/src/SUMMARY.md @@ -22,3 +22,5 @@ - [Profiling applications that use MapLibre Native](./profiling/README.md) - [Tracy profiling](./profiling/tracy-profiling.md) + +- [Rust](./rust.md) diff --git a/docs/mdbook/src/rust.md b/docs/mdbook/src/rust.md new file mode 100644 index 00000000000..634d5bb2ca2 --- /dev/null +++ b/docs/mdbook/src/rust.md @@ -0,0 +1,27 @@ +# Rust + +We have added experimental support for intergrating Rust code into the source tree. + +## Rust Bridge + +The Rust bridge lives in `rustutils`. To regenerate the C++ bridge run the following script from the root of the repository. + +``` +rustutils/cpp/generate.sh +``` + +Check in the generated files under `rustutils/cpp`. + +We might intergrate this generation process into the build, but the tools to do so are experimental and immature as of January 2025. + +## Building + +You need to have the correct Rust toolchain(s) installed. + +### CMake + +Set `MLN_USE_RUST` to `ON`. + +### Bazel + +Pass `--//:use_rust` to Bazel. \ No newline at end of file diff --git a/rustutils/BUILD.bazel b/rustutils/BUILD.bazel index ba4901425a7..6fe1fb4b093 100644 --- a/rustutils/BUILD.bazel +++ b/rustutils/BUILD.bazel @@ -1,16 +1,33 @@ load("@rules_cc//cc:defs.bzl", "cc_library") -load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_static_library") -load("//bazel:rust_cxx_bridge.bzl", "rust_cxx_bridge") - -package(default_visibility = ["//visibility:public"]) - -rust_cxx_bridge( - name = "bridge", - src = "src/lib.rs", -) +load("@rules_rust//rust:defs.bzl", "rust_static_library") rust_static_library( name = "rustutils", - srcs = ["src/lib.rs"], - edition = "2021", + srcs = [ + "src/lib.rs", + ], + crate_name = "rustutils", + visibility = ["//visibility:public"], + deps = [ + "@crates//:csscolorparser", + "@crates//:cxx", + ], ) + +# Link the Rust static library to the C++ library +cc_library( + name = "rustutilslib", + srcs = [ + "cpp/src/lib.rs.cc" + ], + hdrs = [ + "cpp/include/rustutils/lib.hpp" + ], + includes = [ + "cpp/include" + ], + deps = [ + ":rustutils", + ], + visibility = ["//visibility:public"], +) \ No newline at end of file diff --git a/rustutils/README.md b/rustutils/README.md new file mode 100644 index 00000000000..e8e5fe7f890 --- /dev/null +++ b/rustutils/README.md @@ -0,0 +1 @@ +# Rustutils \ No newline at end of file diff --git a/rustutils/cpp/generate.sh b/rustutils/cpp/generate.sh new file mode 100755 index 00000000000..1f842c2706d --- /dev/null +++ b/rustutils/cpp/generate.sh @@ -0,0 +1,8 @@ +# Run this script from the repository root +# Install cxxbridge with: +# $ cargo install cxxbridge-cmd + +set -e + +cxxbridge rustutils/src/lib.rs --header > rustutils/lib.h +cxxbridge rustutils/src/lib.rs > rustutils/cpp/src/lib.rs.cc \ No newline at end of file diff --git a/rustutils/cpp/include/rustutils/lib.hpp b/rustutils/cpp/include/rustutils/lib.hpp new file mode 100644 index 00000000000..91047f0bef8 --- /dev/null +++ b/rustutils/cpp/include/rustutils/lib.hpp @@ -0,0 +1,86 @@ +#pragma once +#include +#include +#include +#include + +namespace rust { +inline namespace cxxbridge1 { +// #include "rust/cxx.h" + +namespace { +template +class impl; +} // namespace + +class String; + +#ifndef CXXBRIDGE1_RUST_STR +#define CXXBRIDGE1_RUST_STR +class Str final { +public: + Str() noexcept; + Str(const String &) noexcept; + Str(const std::string &); + Str(const char *); + Str(const char *, std::size_t); + + Str &operator=(const Str &) &noexcept = default; + + explicit operator std::string() const; + + const char *data() const noexcept; + std::size_t size() const noexcept; + std::size_t length() const noexcept; + bool empty() const noexcept; + + Str(const Str &) noexcept = default; + ~Str() noexcept = default; + + using iterator = const char *; + using const_iterator = const char *; + const_iterator begin() const noexcept; + const_iterator end() const noexcept; + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + + bool operator==(const Str &) const noexcept; + bool operator!=(const Str &) const noexcept; + bool operator<(const Str &) const noexcept; + bool operator<=(const Str &) const noexcept; + bool operator>(const Str &) const noexcept; + bool operator>=(const Str &) const noexcept; + + void swap(Str &) noexcept; + +private: + class uninit; + Str(uninit) noexcept; + friend impl; + + std::array repr; +}; +#endif // CXXBRIDGE1_RUST_STR +} // namespace cxxbridge1 +} // namespace rust + +namespace rustutils { + struct ParsedColor; +} + +namespace rustutils { +#ifndef CXXBRIDGE1_STRUCT_rustutils$ParsedColor +#define CXXBRIDGE1_STRUCT_rustutils$ParsedColor +struct ParsedColor final { + bool success; + float r; + float g; + float b; + float a; + + using IsRelocatable = ::std::true_type; +}; +#endif // CXXBRIDGE1_STRUCT_rustutils$ParsedColor + +::rustutils::ParsedColor parse_css_color(::rust::Str css_str) noexcept; +} // namespace rustutils diff --git a/rustutils/cpp/src/lib.rs.cc b/rustutils/cpp/src/lib.rs.cc new file mode 100644 index 00000000000..76f36bb6ef5 --- /dev/null +++ b/rustutils/cpp/src/lib.rs.cc @@ -0,0 +1,91 @@ +#include +#include +#include +#include + +namespace rust { +inline namespace cxxbridge1 { +// #include "rust/cxx.h" + +namespace { +template +class impl; +} // namespace + +class String; + +#ifndef CXXBRIDGE1_RUST_STR +#define CXXBRIDGE1_RUST_STR +class Str final { +public: + Str() noexcept; + Str(const String &) noexcept; + Str(const std::string &); + Str(const char *); + Str(const char *, std::size_t); + + Str &operator=(const Str &) &noexcept = default; + + explicit operator std::string() const; + + const char *data() const noexcept; + std::size_t size() const noexcept; + std::size_t length() const noexcept; + bool empty() const noexcept; + + Str(const Str &) noexcept = default; + ~Str() noexcept = default; + + using iterator = const char *; + using const_iterator = const char *; + const_iterator begin() const noexcept; + const_iterator end() const noexcept; + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + + bool operator==(const Str &) const noexcept; + bool operator!=(const Str &) const noexcept; + bool operator<(const Str &) const noexcept; + bool operator<=(const Str &) const noexcept; + bool operator>(const Str &) const noexcept; + bool operator>=(const Str &) const noexcept; + + void swap(Str &) noexcept; + +private: + class uninit; + Str(uninit) noexcept; + friend impl; + + std::array repr; +}; +#endif // CXXBRIDGE1_RUST_STR +} // namespace cxxbridge1 +} // namespace rust + +namespace rustutils { + struct ParsedColor; +} + +namespace rustutils { +#ifndef CXXBRIDGE1_STRUCT_rustutils$ParsedColor +#define CXXBRIDGE1_STRUCT_rustutils$ParsedColor +struct ParsedColor final { + bool success; + float r; + float g; + float b; + float a; + + using IsRelocatable = ::std::true_type; +}; +#endif // CXXBRIDGE1_STRUCT_rustutils$ParsedColor + +extern "C" { +::rustutils::ParsedColor rustutils$cxxbridge1$parse_css_color(::rust::Str css_str) noexcept; +} // extern "C" + +::rustutils::ParsedColor parse_css_color(::rust::Str css_str) noexcept { + return rustutils$cxxbridge1$parse_css_color(css_str); +} +} // namespace rustutils diff --git a/rustutils/rustutils.cmake b/rustutils/rustutils.cmake new file mode 100644 index 00000000000..2e86a441580 --- /dev/null +++ b/rustutils/rustutils.cmake @@ -0,0 +1,28 @@ +# Include guard +if(TARGET rustutils AND MLN_USE_RUST) + return() +endif() + +include(FetchContent) + +FetchContent_Declare( + Corrosion + GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git + GIT_TAG v0.5 # Optionally specify a commit hash, version tag or branch here +) +FetchContent_MakeAvailable(Corrosion) + +corrosion_import_crate(MANIFEST_PATH ${CMAKE_CURRENT_LIST_DIR}/Cargo.toml) + +set(RUSTUTILS_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/cpp/include") +set(RUSTUTILS_SRC "${CMAKE_CURRENT_LIST_DIR}/cpp/src/lib.rs.cc") + +add_library(mbgl-rustutils STATIC + ${RUSTUTILS_SRC} +) + +target_include_directories(mbgl-rustutils PUBLIC + ${RUSTUTILS_INCLUDE_DIR} +) + +target_link_libraries(mbgl-rustutils PUBLIC rustutils) diff --git a/scripts/license.cmake b/scripts/license.cmake index 7c0b0bd10af..86141540a31 100644 --- a/scripts/license.cmake +++ b/scripts/license.cmake @@ -2,7 +2,7 @@ function(mbgl_generate_license param) # Fake targets or non relevant. - set(BLACKLIST "mbgl-compiler-options") + set(BLACKLIST "mbgl-compiler-options" "mbgl-rustutils") get_target_property(LIBRARIES ${param} LINK_LIBRARIES) list(INSERT LIBRARIES 0 ${param}) diff --git a/src/mbgl/util/color.cpp b/src/mbgl/util/color.cpp index 30aed5fe299..44fb65f732a 100644 --- a/src/mbgl/util/color.cpp +++ b/src/mbgl/util/color.cpp @@ -1,16 +1,17 @@ -#include - #include #include -#include +#include namespace mbgl { std::optional Color::parse(const std::string& s) { - auto css_color = rustutils::parse_css_color(s); - if (css_color.success) { - return {{css_color.r, css_color.g, css_color.b, css_color.a}}; + auto css_color = CSSColorParser::parse(s); + + // Premultiply the color. + if (css_color) { + const float factor = css_color->a / 255; + return {{css_color->r * factor, css_color->g * factor, css_color->b * factor, css_color->a}}; } else { return {}; } diff --git a/src/mbgl/util/color.rs.cpp b/src/mbgl/util/color.rs.cpp new file mode 100644 index 00000000000..e1ff57996cd --- /dev/null +++ b/src/mbgl/util/color.rs.cpp @@ -0,0 +1,56 @@ +#include + +#include +#include + +#include + +namespace mbgl { + +std::optional Color::parse(const std::string& s) { + auto css_color = rustutils::parse_css_color(s); + if (css_color.success) { + return {{css_color.r, css_color.g, css_color.b, css_color.a}}; + } else { + return {}; + } +} + +std::string Color::stringify() const { + std::array array = toArray(); + return "rgba(" + util::toString(array[0]) + "," + util::toString(array[1]) + "," + util::toString(array[2]) + "," + + util::toString(array[3]) + ")"; +} + +std::array Color::toArray() const { + if (a == 0) { + return {{0, 0, 0, 0}}; + } else { + return {{ + r * 255 / a, + g * 255 / a, + b * 255 / a, + floor(a * 100 + .5) / 100 // round to 2 decimal places + }}; + } +} + +mbgl::Value Color::toObject() const { + return mapbox::base::ValueObject{{"r", static_cast(r)}, + {"g", static_cast(g)}, + {"b", static_cast(b)}, + {"a", static_cast(a)}}; +} + +mbgl::Value Color::serialize() const { + std::array array = toArray(); + return std::vector{ + std::string("rgba"), + array[0], + array[1], + array[2], + array[3], + }; +} + +} // namespace mbgl diff --git a/vendor/BUILD.bazel b/vendor/BUILD.bazel index 3bb48b4e71b..78fbf69c6c8 100644 --- a/vendor/BUILD.bazel +++ b/vendor/BUILD.bazel @@ -56,6 +56,20 @@ cc_library( visibility = ["//visibility:public"], ) +# vendor/csscolorparser +cc_library( + name = "csscolorparser", + srcs = glob( + [ + "csscolorparser/**/*.hpp", + "csscolorparser/**/*.cpp", + ], + ), + copts = CPP_FLAGS, + includes = ["csscolorparser"], + visibility = ["//visibility:public"], +) + # vendor/wagyu-files.json cc_library( name = "wagyu", diff --git a/vendor/corrosion b/vendor/corrosion deleted file mode 160000 index 64289b1d79d..00000000000 --- a/vendor/corrosion +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 64289b1d79d6d19cd2e241db515381a086bb8407 diff --git a/vendor/csscolorparser.cmake b/vendor/csscolorparser.cmake new file mode 100644 index 00000000000..e5f15cc3856 --- /dev/null +++ b/vendor/csscolorparser.cmake @@ -0,0 +1,37 @@ +if(TARGET mbgl-vendor-csscolorparser) + return() +endif() + +if(MLN_WITH_QT) + add_library(mbgl-vendor-csscolorparser OBJECT) +else() + add_library(mbgl-vendor-csscolorparser STATIC) +endif() + +target_sources( + mbgl-vendor-csscolorparser PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/csscolorparser/csscolorparser.cpp +) + +target_link_libraries( + mbgl-vendor-csscolorparser + PRIVATE mbgl-compiler-options +) + +target_include_directories( + mbgl-vendor-csscolorparser SYSTEM + PUBLIC ${CMAKE_CURRENT_LIST_DIR}/csscolorparser +) + +if(MSVC) + target_compile_options(mbgl-vendor-csscolorparser PRIVATE /wd4244) +endif() + +set_target_properties( + mbgl-vendor-csscolorparser + PROPERTIES + INTERFACE_MAPLIBRE_NAME "csscolorparser" + INTERFACE_MAPLIBRE_URL "https://github.com/mapbox/css-color-parser-cpp" + INTERFACE_MAPLIBRE_AUTHOR "Dean McNamee and Konstantin Käfer" + INTERFACE_MAPLIBRE_LICENSE ${CMAKE_CURRENT_LIST_DIR}/csscolorparser/LICENSE +) diff --git a/rustutils/LICENSE-MIT b/vendor/csscolorparser/LICENSE similarity index 56% rename from rustutils/LICENSE-MIT rename to vendor/csscolorparser/LICENSE index 8591dea8f51..2408b4a02e1 100644 --- a/rustutils/LICENSE-MIT +++ b/vendor/csscolorparser/LICENSE @@ -1,21 +1,20 @@ -MIT License - -Copyright (c) 2024 Yuri Astrakhan +(c) Dean McNamee , 2012. +(c) Konstantin Käfer , 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 +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 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. +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. diff --git a/vendor/csscolorparser/csscolorparser.cpp b/vendor/csscolorparser/csscolorparser.cpp new file mode 100644 index 00000000000..74764a22e24 --- /dev/null +++ b/vendor/csscolorparser/csscolorparser.cpp @@ -0,0 +1,288 @@ +// (c) Dean McNamee , 2012. +// C++ port by Mapbox, Konstantin Käfer , 2014-2017. +// +// https://github.com/deanm/css-color-parser-js +// https://github.com/kkaefer/css-color-parser-cpp +// +// 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. + +#include "csscolorparser/csscolorparser.hpp" + +#include +#include +#include +#include + +namespace CSSColorParser { + +// http://www.w3.org/TR/css3-color/ +struct NamedColor { const char *const name; const Color color; }; +const NamedColor namedColors[] = { + { "transparent", { 0, 0, 0, 0 } }, { "aliceblue", { 240, 248, 255, 1 } }, + { "antiquewhite", { 250, 235, 215, 1 } }, { "aqua", { 0, 255, 255, 1 } }, + { "aquamarine", { 127, 255, 212, 1 } }, { "azure", { 240, 255, 255, 1 } }, + { "beige", { 245, 245, 220, 1 } }, { "bisque", { 255, 228, 196, 1 } }, + { "black", { 0, 0, 0, 1 } }, { "blanchedalmond", { 255, 235, 205, 1 } }, + { "blue", { 0, 0, 255, 1 } }, { "blueviolet", { 138, 43, 226, 1 } }, + { "brown", { 165, 42, 42, 1 } }, { "burlywood", { 222, 184, 135, 1 } }, + { "cadetblue", { 95, 158, 160, 1 } }, { "chartreuse", { 127, 255, 0, 1 } }, + { "chocolate", { 210, 105, 30, 1 } }, { "coral", { 255, 127, 80, 1 } }, + { "cornflowerblue", { 100, 149, 237, 1 } }, { "cornsilk", { 255, 248, 220, 1 } }, + { "crimson", { 220, 20, 60, 1 } }, { "cyan", { 0, 255, 255, 1 } }, + { "darkblue", { 0, 0, 139, 1 } }, { "darkcyan", { 0, 139, 139, 1 } }, + { "darkgoldenrod", { 184, 134, 11, 1 } }, { "darkgray", { 169, 169, 169, 1 } }, + { "darkgreen", { 0, 100, 0, 1 } }, { "darkgrey", { 169, 169, 169, 1 } }, + { "darkkhaki", { 189, 183, 107, 1 } }, { "darkmagenta", { 139, 0, 139, 1 } }, + { "darkolivegreen", { 85, 107, 47, 1 } }, { "darkorange", { 255, 140, 0, 1 } }, + { "darkorchid", { 153, 50, 204, 1 } }, { "darkred", { 139, 0, 0, 1 } }, + { "darksalmon", { 233, 150, 122, 1 } }, { "darkseagreen", { 143, 188, 143, 1 } }, + { "darkslateblue", { 72, 61, 139, 1 } }, { "darkslategray", { 47, 79, 79, 1 } }, + { "darkslategrey", { 47, 79, 79, 1 } }, { "darkturquoise", { 0, 206, 209, 1 } }, + { "darkviolet", { 148, 0, 211, 1 } }, { "deeppink", { 255, 20, 147, 1 } }, + { "deepskyblue", { 0, 191, 255, 1 } }, { "dimgray", { 105, 105, 105, 1 } }, + { "dimgrey", { 105, 105, 105, 1 } }, { "dodgerblue", { 30, 144, 255, 1 } }, + { "firebrick", { 178, 34, 34, 1 } }, { "floralwhite", { 255, 250, 240, 1 } }, + { "forestgreen", { 34, 139, 34, 1 } }, { "fuchsia", { 255, 0, 255, 1 } }, + { "gainsboro", { 220, 220, 220, 1 } }, { "ghostwhite", { 248, 248, 255, 1 } }, + { "gold", { 255, 215, 0, 1 } }, { "goldenrod", { 218, 165, 32, 1 } }, + { "gray", { 128, 128, 128, 1 } }, { "green", { 0, 128, 0, 1 } }, + { "greenyellow", { 173, 255, 47, 1 } }, { "grey", { 128, 128, 128, 1 } }, + { "honeydew", { 240, 255, 240, 1 } }, { "hotpink", { 255, 105, 180, 1 } }, + { "indianred", { 205, 92, 92, 1 } }, { "indigo", { 75, 0, 130, 1 } }, + { "ivory", { 255, 255, 240, 1 } }, { "khaki", { 240, 230, 140, 1 } }, + { "lavender", { 230, 230, 250, 1 } }, { "lavenderblush", { 255, 240, 245, 1 } }, + { "lawngreen", { 124, 252, 0, 1 } }, { "lemonchiffon", { 255, 250, 205, 1 } }, + { "lightblue", { 173, 216, 230, 1 } }, { "lightcoral", { 240, 128, 128, 1 } }, + { "lightcyan", { 224, 255, 255, 1 } }, { "lightgoldenrodyellow", { 250, 250, 210, 1 } }, + { "lightgray", { 211, 211, 211, 1 } }, { "lightgreen", { 144, 238, 144, 1 } }, + { "lightgrey", { 211, 211, 211, 1 } }, { "lightpink", { 255, 182, 193, 1 } }, + { "lightsalmon", { 255, 160, 122, 1 } }, { "lightseagreen", { 32, 178, 170, 1 } }, + { "lightskyblue", { 135, 206, 250, 1 } }, { "lightslategray", { 119, 136, 153, 1 } }, + { "lightslategrey", { 119, 136, 153, 1 } }, { "lightsteelblue", { 176, 196, 222, 1 } }, + { "lightyellow", { 255, 255, 224, 1 } }, { "lime", { 0, 255, 0, 1 } }, + { "limegreen", { 50, 205, 50, 1 } }, { "linen", { 250, 240, 230, 1 } }, + { "magenta", { 255, 0, 255, 1 } }, { "maroon", { 128, 0, 0, 1 } }, + { "mediumaquamarine", { 102, 205, 170, 1 } }, { "mediumblue", { 0, 0, 205, 1 } }, + { "mediumorchid", { 186, 85, 211, 1 } }, { "mediumpurple", { 147, 112, 219, 1 } }, + { "mediumseagreen", { 60, 179, 113, 1 } }, { "mediumslateblue", { 123, 104, 238, 1 } }, + { "mediumspringgreen", { 0, 250, 154, 1 } }, { "mediumturquoise", { 72, 209, 204, 1 } }, + { "mediumvioletred", { 199, 21, 133, 1 } }, { "midnightblue", { 25, 25, 112, 1 } }, + { "mintcream", { 245, 255, 250, 1 } }, { "mistyrose", { 255, 228, 225, 1 } }, + { "moccasin", { 255, 228, 181, 1 } }, { "navajowhite", { 255, 222, 173, 1 } }, + { "navy", { 0, 0, 128, 1 } }, { "oldlace", { 253, 245, 230, 1 } }, + { "olive", { 128, 128, 0, 1 } }, { "olivedrab", { 107, 142, 35, 1 } }, + { "orange", { 255, 165, 0, 1 } }, { "orangered", { 255, 69, 0, 1 } }, + { "orchid", { 218, 112, 214, 1 } }, { "palegoldenrod", { 238, 232, 170, 1 } }, + { "palegreen", { 152, 251, 152, 1 } }, { "paleturquoise", { 175, 238, 238, 1 } }, + { "palevioletred", { 219, 112, 147, 1 } }, { "papayawhip", { 255, 239, 213, 1 } }, + { "peachpuff", { 255, 218, 185, 1 } }, { "peru", { 205, 133, 63, 1 } }, + { "pink", { 255, 192, 203, 1 } }, { "plum", { 221, 160, 221, 1 } }, + { "powderblue", { 176, 224, 230, 1 } }, { "purple", { 128, 0, 128, 1 } }, + { "red", { 255, 0, 0, 1 } }, { "rosybrown", { 188, 143, 143, 1 } }, + { "royalblue", { 65, 105, 225, 1 } }, { "saddlebrown", { 139, 69, 19, 1 } }, + { "salmon", { 250, 128, 114, 1 } }, { "sandybrown", { 244, 164, 96, 1 } }, + { "seagreen", { 46, 139, 87, 1 } }, { "seashell", { 255, 245, 238, 1 } }, + { "sienna", { 160, 82, 45, 1 } }, { "silver", { 192, 192, 192, 1 } }, + { "skyblue", { 135, 206, 235, 1 } }, { "slateblue", { 106, 90, 205, 1 } }, + { "slategray", { 112, 128, 144, 1 } }, { "slategrey", { 112, 128, 144, 1 } }, + { "snow", { 255, 250, 250, 1 } }, { "springgreen", { 0, 255, 127, 1 } }, + { "steelblue", { 70, 130, 180, 1 } }, { "tan", { 210, 180, 140, 1 } }, + { "teal", { 0, 128, 128, 1 } }, { "thistle", { 216, 191, 216, 1 } }, + { "tomato", { 255, 99, 71, 1 } }, { "turquoise", { 64, 224, 208, 1 } }, + { "violet", { 238, 130, 238, 1 } }, { "wheat", { 245, 222, 179, 1 } }, + { "white", { 255, 255, 255, 1 } }, { "whitesmoke", { 245, 245, 245, 1 } }, + { "yellow", { 255, 255, 0, 1 } }, { "yellowgreen", { 154, 205, 50, 1 } } +}; + +template +uint8_t clamp_css_byte(T i) { // Clamp to integer 0 .. 255. + i = ::round(i); // Seems to be what Chrome does (vs truncation). + return i < 0 ? 0 : i > 255 ? 255 : uint8_t(i); +} + +template +float clamp_css_float(T f) { // Clamp to float 0.0 .. 1.0. + return f < 0 ? 0 : f > 1 ? 1 : float(f); +} + +float parseFloat(const std::string& str) { + return strtof(str.c_str(), nullptr); +} + +int64_t parseInt(const std::string& str, uint8_t base = 10) { + return strtoll(str.c_str(), nullptr, base); +} + +uint8_t parse_css_int(const std::string& str) { // int or percentage. + if (str.length() && str.back() == '%') { + return clamp_css_byte(parseFloat(str) / 100.0f * 255.0f); + } else { + return clamp_css_byte(parseInt(str)); + } +} + +float parse_css_float(const std::string& str) { // float or percentage. + if (str.length() && str.back() == '%') { + return clamp_css_float(parseFloat(str) / 100.0f); + } else { + return clamp_css_float(parseFloat(str)); + } +} + +float css_hue_to_rgb(float m1, float m2, float h) { + if (h < 0.0f) { + h += 1.0f; + } else if (h > 1.0f) { + h -= 1.0f; + } + + if (h * 6.0f < 1.0f) { + return m1 + (m2 - m1) * h * 6.0f; + } + if (h * 2.0f < 1.0f) { + return m2; + } + if (h * 3.0f < 2.0f) { + return m1 + (m2 - m1) * (2.0f / 3.0f - h) * 6.0f; + } + return m1; +} + + + +std::vector split(const std::string& s, char delim) { + std::vector elems; + std::stringstream ss(s); + std::string item; + while (std::getline(ss, item, delim)) { + elems.push_back(item); + } + return elems; +} + +std::optional parse(const std::string& css_str) { + std::string str = css_str; + + // Remove all whitespace, not compliant, but should just be more accepting. + str.erase(std::remove(str.begin(), str.end(), ' '), str.end()); + + // Convert to lowercase. + std::transform(str.begin(), str.end(), str.begin(), ::tolower); + + for (const auto& namedColor : namedColors) { + if (str == namedColor.name) { + return { namedColor.color }; + } + } + + // #abc and #abc123 syntax. + if (str.length() && str.front() == '#') { + if (str.length() == 4) { + int64_t iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing. + if (!(iv >= 0 && iv <= 0xfff)) { + return {}; + } else { + return {{ + static_cast(((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8)), + static_cast((iv & 0xf0) | ((iv & 0xf0) >> 4)), + static_cast((iv & 0xf) | ((iv & 0xf) << 4)), + 1 + }}; + } + } else if (str.length() == 7) { + int64_t iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing. + if (!(iv >= 0 && iv <= 0xffffff)) { + return {}; // Covers NaN. + } else { + return {{ + static_cast((iv & 0xff0000) >> 16), + static_cast((iv & 0xff00) >> 8), + static_cast(iv & 0xff), + 1 + }}; + } + } + + return {}; + } + + size_t op = str.find_first_of('('), ep = str.find_first_of(')'); + if (op != std::string::npos && ep + 1 == str.length()) { + const std::string fname = str.substr(0, op); + const std::vector params = split(str.substr(op + 1, ep - (op + 1)), ','); + + float alpha = 1.0f; + + if (fname == "rgba" || fname == "rgb") { + if (fname == "rgba") { + if (params.size() != 4) { + return {}; + } + alpha = parse_css_float(params.back()); + } else { + if (params.size() != 3) { + return {}; + } + } + + return {{ + parse_css_int(params[0]), + parse_css_int(params[1]), + parse_css_int(params[2]), + alpha + }}; + + } else if (fname == "hsla" || fname == "hsl") { + if (fname == "hsla") { + if (params.size() != 4) { + return {}; + } + alpha = parse_css_float(params.back()); + } else { + if (params.size() != 3) { + return {}; + } + } + + float h = parseFloat(params[0]) / 360.0f; + float i; + // Normalize the hue to [0..1[ + h = std::modf(h, &i); + + // NOTE(deanm): According to the CSS spec s/l should only be + // percentages, but we don't bother and let float or percentage. + float s = parse_css_float(params[1]); + float l = parse_css_float(params[2]); + + float m2 = l <= 0.5f ? l * (s + 1.0f) : l + s - l * s; + float m1 = l * 2.0f - m2; + + return {{ + clamp_css_byte(css_hue_to_rgb(m1, m2, h + 1.0f / 3.0f) * 255.0f), + clamp_css_byte(css_hue_to_rgb(m1, m2, h) * 255.0f), + clamp_css_byte(css_hue_to_rgb(m1, m2, h - 1.0f / 3.0f) * 255.0f), + alpha + }}; + } + } + + return {}; +} + +} // namespace CSSColorParser diff --git a/vendor/csscolorparser/csscolorparser/csscolorparser.hpp b/vendor/csscolorparser/csscolorparser/csscolorparser.hpp new file mode 100644 index 00000000000..7b41bfa5de2 --- /dev/null +++ b/vendor/csscolorparser/csscolorparser/csscolorparser.hpp @@ -0,0 +1,56 @@ +// (c) Dean McNamee , 2012. +// C++ port by Mapbox, Konstantin Käfer , 2014-2017. +// +// https://github.com/deanm/css-color-parser-js +// https://github.com/kkaefer/css-color-parser-cpp +// +// 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. + +#ifndef CSS_COLOR_PARSER_CPP +#define CSS_COLOR_PARSER_CPP + +#include +#include +#include + +namespace CSSColorParser { + +struct Color { + inline Color() { + } + inline Color(unsigned char r_, unsigned char g_, unsigned char b_, float a_) + : r(r_), g(g_), b(b_), a(a_ > 1 ? 1 : a_ < 0 ? 0 : a_) { + } + unsigned char r = 0, g = 0, b = 0; + float a = 1.0f; +}; + +inline bool operator==(const Color& lhs, const Color& rhs) { + return lhs.r == rhs.r && lhs.g == rhs.g && lhs.b == rhs.b && ::fabs(lhs.a - rhs.a) < 0.0001f; +} + +inline bool operator!=(const Color& lhs, const Color& rhs) { + return !(lhs == rhs); +} + +std::optional parse(const std::string& css_str); + +} // namespace CSSColorParser + +#endif From d3836b6e9fb365cfd7a1d791500760362723df1f Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 10 Jan 2025 16:42:03 +0100 Subject: [PATCH 16/56] Add back license --- platform/android/LICENSE.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/platform/android/LICENSE.md b/platform/android/LICENSE.md index bf720b2ae78..72b908825de 100644 --- a/platform/android/LICENSE.md +++ b/platform/android/LICENSE.md @@ -456,6 +456,34 @@ DEALINGS IN THE SOFTWARE. --- +### [csscolorparser](https://github.com/mapbox/css-color-parser-cpp) by Dean McNamee and Konstantin Käfer + +``` +(c) Dean McNamee , 2012. +(c) Konstantin Käfer , 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 ``` @@ -914,3 +942,4 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ``` --- + From 90ba3efe0e44974d60183f09d718806c0a4dd9f7 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 10 Jan 2025 16:42:33 +0100 Subject: [PATCH 17/56] Cleanup unused code --- bazel/BUILD.bazel | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/bazel/BUILD.bazel b/bazel/BUILD.bazel index 94b44225327..e69de29bb2d 100644 --- a/bazel/BUILD.bazel +++ b/bazel/BUILD.bazel @@ -1,19 +0,0 @@ -#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"], -#) From 6f618ece7d357d60421c71ec324fabb961e57f9d Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 10 Jan 2025 16:43:27 +0100 Subject: [PATCH 18/56] Revert some files --- .github/actions/qt5-build/entrypoint.sh | 5 ----- .github/actions/qt6-build/entrypoint.sh | 5 ----- LICENSES.core.md | 29 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/.github/actions/qt5-build/entrypoint.sh b/.github/actions/qt5-build/entrypoint.sh index 6e7e554994a..e651013cda7 100755 --- a/.github/actions/qt5-build/entrypoint.sh +++ b/.github/actions/qt5-build/entrypoint.sh @@ -8,11 +8,6 @@ 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 \ diff --git a/.github/actions/qt6-build/entrypoint.sh b/.github/actions/qt6-build/entrypoint.sh index 434f470e6a8..702bcc3f8f7 100755 --- a/.github/actions/qt6-build/entrypoint.sh +++ b/.github/actions/qt6-build/entrypoint.sh @@ -8,11 +8,6 @@ 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 \ diff --git a/LICENSES.core.md b/LICENSES.core.md index 86a5dd3fa4e..558d0e48945 100644 --- a/LICENSES.core.md +++ b/LICENSES.core.md @@ -178,6 +178,34 @@ DEALINGS IN THE SOFTWARE. --- +### [csscolorparser](https://github.com/mapbox/css-color-parser-cpp) by Dean McNamee and Konstantin Käfer + +``` +(c) Dean McNamee , 2012. +(c) Konstantin Käfer , 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 ``` @@ -605,3 +633,4 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ``` --- + From 729dafb6358d1d6df734afef47ca43cc402bde19 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 10 Jan 2025 16:47:09 +0100 Subject: [PATCH 19/56] CI fixes --- .github/workflows/android-ci.yml | 25 ++++--------------------- .github/workflows/linux-ci.yml | 1 + .github/workflows/node-ci.yml | 8 -------- .github/workflows/qt-ci.yml | 21 ++++----------------- 4 files changed, 9 insertions(+), 46 deletions(-) diff --git a/.github/workflows/android-ci.yml b/.github/workflows/android-ci.yml index 3fcb8a42362..3bdcb7d142f 100644 --- a/.github/workflows/android-ci.yml +++ b/.github/workflows/android-ci.yml @@ -231,18 +231,9 @@ jobs: submodules: recursive fetch-depth: 0 - - 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: - cmakeVersion: 3.24.1 - ninjaVersion: latest - - uses: actions/setup-java@v4 - with: - distribution: "temurin" - java-version: "17" + - name: Add aarch64-linux-android for Rust toolchian + if: ${{ github.ref == 'refs/heads/rust' || github.event.pull_request.base.ref == 'rust' }} + 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 @@ -324,17 +315,9 @@ jobs: java-version: "17" - name: Add aarch64-linux-android for Rust toolchian + if: ${{ github.ref == 'refs/heads/rust' || github.event.pull_request.base.ref == 'rust' }} 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 - cp app/build/outputs/apk/release/app-release.apk RenderTestsApp.apk - cp app/build/outputs/apk/androidTest/release/app-release-androidTest.apk RenderTests.apk - working-directory: ./render-test/android - - - name: Store Render Test .apk files - uses: actions/upload-artifact@v4 - name: Build and Upload Render Test APKs (${{ matrix.flavor }}) uses: ./.github/actions/android-build-and-upload-render-test with: diff --git a/.github/workflows/linux-ci.yml b/.github/workflows/linux-ci.yml index c3579644d24..6c09c01abbf 100644 --- a/.github/workflows/linux-ci.yml +++ b/.github/workflows/linux-ci.yml @@ -201,6 +201,7 @@ jobs: x11-xserver-utils - name: Install cxxbridge-cmd (compile) + if: ${{ github.ref == 'refs/heads/rust' || github.event.pull_request.base.ref == 'rust' }} run: cargo install cxxbridge-cmd - name: Cache Bazel diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.yml index 622b3bc8880..1d4b6abe2f9 100644 --- a/.github/workflows/node-ci.yml +++ b/.github/workflows/node-ci.yml @@ -173,14 +173,6 @@ 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 diff --git a/.github/workflows/qt-ci.yml b/.github/workflows/qt-ci.yml index e60803fc1f7..521f0217963 100644 --- a/.github/workflows/qt-ci.yml +++ b/.github/workflows/qt-ci.yml @@ -49,19 +49,14 @@ on: - ".gitmodules" - "!**/*.md" -# -# -# FIXME: reenable this -# -#concurrency: -# # cancel jobs on PRs only -# group: ${{ github.workflow }}-${{ github.ref }} -# cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} +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 @@ -211,14 +206,6 @@ 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 From c7aceda9eab355237b9290d64e73b856f49359c1 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 10 Jan 2025 16:47:36 +0100 Subject: [PATCH 20/56] Remove README.md --- rustutils/README.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 rustutils/README.md diff --git a/rustutils/README.md b/rustutils/README.md deleted file mode 100644 index e8e5fe7f890..00000000000 --- a/rustutils/README.md +++ /dev/null @@ -1 +0,0 @@ -# Rustutils \ No newline at end of file From 5fc141ea066d608b4dde57ee2fa2e2ef60a5904e Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 10 Jan 2025 16:47:54 +0100 Subject: [PATCH 21/56] revert qt.cmake --- platform/qt/qt.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake index 5d7ae5dd6b5..04920ca8b38 100644 --- a/platform/qt/qt.cmake +++ b/platform/qt/qt.cmake @@ -139,6 +139,7 @@ target_link_libraries( PUBLIC $ $ + $ $<$,$>>:z> $,$,Qt${QT_VERSION_MAJOR}::Sql> PRIVATE @@ -162,6 +163,7 @@ if(MLN_QT_HAS_PARENT) set(MLN_QT_VENDOR_LIBRARIES mbgl-vendor-parsedate mbgl-vendor-nunicode + mbgl-vendor-csscolorparser $<$:$> $<$,$>:$> PARENT_SCOPE From 671a41f65095477a36e6532490f6f7f84c653607 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 10 Jan 2025 16:48:11 +0100 Subject: [PATCH 22/56] revert README.md --- platform/linux/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/platform/linux/README.md b/platform/linux/README.md index b0a07646fa5..371d4ae1358 100644 --- a/platform/linux/README.md +++ b/platform/linux/README.md @@ -19,9 +19,6 @@ cd maplibre-native # Install build tools apt install build-essential clang cmake ccache ninja-build pkg-config -# Install rust toolchain (default options should be sufficient) -curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh - # Install system dependencies apt install libcurl4-openssl-dev libglfw3-dev libuv1-dev libpng-dev libicu-dev libjpeg-turbo8-dev libwebp-dev xvfb ``` From 8ed43037f03a2ce1dbbf5e61da90343f12f69eeb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:48:17 +0000 Subject: [PATCH 23/56] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- rustutils/cpp/include/rustutils/lib.hpp | 74 ++++++++++++------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/rustutils/cpp/include/rustutils/lib.hpp b/rustutils/cpp/include/rustutils/lib.hpp index 91047f0bef8..b6f6d244e71 100644 --- a/rustutils/cpp/include/rustutils/lib.hpp +++ b/rustutils/cpp/include/rustutils/lib.hpp @@ -19,66 +19,66 @@ class String; #define CXXBRIDGE1_RUST_STR class Str final { public: - Str() noexcept; - Str(const String &) noexcept; - Str(const std::string &); - Str(const char *); - Str(const char *, std::size_t); + Str() noexcept; + Str(const String &) noexcept; + Str(const std::string &); + Str(const char *); + Str(const char *, std::size_t); - Str &operator=(const Str &) &noexcept = default; + Str &operator=(const Str &) & noexcept = default; - explicit operator std::string() const; + explicit operator std::string() const; - const char *data() const noexcept; - std::size_t size() const noexcept; - std::size_t length() const noexcept; - bool empty() const noexcept; + const char *data() const noexcept; + std::size_t size() const noexcept; + std::size_t length() const noexcept; + bool empty() const noexcept; - Str(const Str &) noexcept = default; - ~Str() noexcept = default; + Str(const Str &) noexcept = default; + ~Str() noexcept = default; - using iterator = const char *; - using const_iterator = const char *; - const_iterator begin() const noexcept; - const_iterator end() const noexcept; - const_iterator cbegin() const noexcept; - const_iterator cend() const noexcept; + using iterator = const char *; + using const_iterator = const char *; + const_iterator begin() const noexcept; + const_iterator end() const noexcept; + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; - bool operator==(const Str &) const noexcept; - bool operator!=(const Str &) const noexcept; - bool operator<(const Str &) const noexcept; - bool operator<=(const Str &) const noexcept; - bool operator>(const Str &) const noexcept; - bool operator>=(const Str &) const noexcept; + bool operator==(const Str &) const noexcept; + bool operator!=(const Str &) const noexcept; + bool operator<(const Str &) const noexcept; + bool operator<=(const Str &) const noexcept; + bool operator>(const Str &) const noexcept; + bool operator>=(const Str &) const noexcept; - void swap(Str &) noexcept; + void swap(Str &) noexcept; private: - class uninit; - Str(uninit) noexcept; - friend impl; + class uninit; + Str(uninit) noexcept; + friend impl; - std::array repr; + std::array repr; }; #endif // CXXBRIDGE1_RUST_STR } // namespace cxxbridge1 } // namespace rust namespace rustutils { - struct ParsedColor; +struct ParsedColor; } namespace rustutils { #ifndef CXXBRIDGE1_STRUCT_rustutils$ParsedColor #define CXXBRIDGE1_STRUCT_rustutils$ParsedColor struct ParsedColor final { - bool success; - float r; - float g; - float b; - float a; + bool success; + float r; + float g; + float b; + float a; - using IsRelocatable = ::std::true_type; + using IsRelocatable = ::std::true_type; }; #endif // CXXBRIDGE1_STRUCT_rustutils$ParsedColor From 53a33c8e8d5ff0ff04ad9135268158eb0beb5e81 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 10 Jan 2025 16:48:27 +0100 Subject: [PATCH 24/56] revert --- platform/ios/LICENSE.md | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/platform/ios/LICENSE.md b/platform/ios/LICENSE.md index 5378fb1fbf3..5a9143de0ce 100644 --- a/platform/ios/LICENSE.md +++ b/platform/ios/LICENSE.md @@ -1026,6 +1026,34 @@ DEALINGS IN THE SOFTWARE. --- +### [csscolorparser](https://github.com/mapbox/css-color-parser-cpp) by Dean McNamee and Konstantin Käfer + +``` +(c) Dean McNamee , 2012. +(c) Konstantin Käfer , 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 ``` @@ -1659,4 +1687,4 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -``` +``` \ No newline at end of file From a5853d9039270f668b5bb3af7e4f08214fb162d0 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 10 Jan 2025 16:49:08 +0100 Subject: [PATCH 25/56] revert --- platform/android/android.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/android/android.cmake b/platform/android/android.cmake index d7ddfc491a7..fbddbb2a4f0 100644 --- a/platform/android/android.cmake +++ b/platform/android/android.cmake @@ -11,6 +11,7 @@ include(${PROJECT_SOURCE_DIR}/vendor/icu.cmake) include(${PROJECT_SOURCE_DIR}/vendor/sqlite.cmake) # cmake-format: off +target_compile_options(mbgl-vendor-csscolorparser PRIVATE $<$:-Oz> $<$:-Qunused-arguments> $<$:-flto>) target_compile_options(mbgl-vendor-icu PRIVATE $<$:-Oz> $<$:-Qunused-arguments> $<$:-flto>) target_compile_options(mbgl-vendor-parsedate PRIVATE $<$:-Oz> $<$:-Qunused-arguments> $<$:-flto>) target_compile_options(mbgl-vendor-sqlite PRIVATE $<$:-Oz> $<$:-Qunused-arguments> $<$:-flto>) From bda511d5879dcfcb6092b3099d146f7e58924f5f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:57:48 +0000 Subject: [PATCH 26/56] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- rustutils/cpp/include/rustutils/lib.hpp | 74 ++++++++++++------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/rustutils/cpp/include/rustutils/lib.hpp b/rustutils/cpp/include/rustutils/lib.hpp index 91047f0bef8..b6f6d244e71 100644 --- a/rustutils/cpp/include/rustutils/lib.hpp +++ b/rustutils/cpp/include/rustutils/lib.hpp @@ -19,66 +19,66 @@ class String; #define CXXBRIDGE1_RUST_STR class Str final { public: - Str() noexcept; - Str(const String &) noexcept; - Str(const std::string &); - Str(const char *); - Str(const char *, std::size_t); + Str() noexcept; + Str(const String &) noexcept; + Str(const std::string &); + Str(const char *); + Str(const char *, std::size_t); - Str &operator=(const Str &) &noexcept = default; + Str &operator=(const Str &) & noexcept = default; - explicit operator std::string() const; + explicit operator std::string() const; - const char *data() const noexcept; - std::size_t size() const noexcept; - std::size_t length() const noexcept; - bool empty() const noexcept; + const char *data() const noexcept; + std::size_t size() const noexcept; + std::size_t length() const noexcept; + bool empty() const noexcept; - Str(const Str &) noexcept = default; - ~Str() noexcept = default; + Str(const Str &) noexcept = default; + ~Str() noexcept = default; - using iterator = const char *; - using const_iterator = const char *; - const_iterator begin() const noexcept; - const_iterator end() const noexcept; - const_iterator cbegin() const noexcept; - const_iterator cend() const noexcept; + using iterator = const char *; + using const_iterator = const char *; + const_iterator begin() const noexcept; + const_iterator end() const noexcept; + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; - bool operator==(const Str &) const noexcept; - bool operator!=(const Str &) const noexcept; - bool operator<(const Str &) const noexcept; - bool operator<=(const Str &) const noexcept; - bool operator>(const Str &) const noexcept; - bool operator>=(const Str &) const noexcept; + bool operator==(const Str &) const noexcept; + bool operator!=(const Str &) const noexcept; + bool operator<(const Str &) const noexcept; + bool operator<=(const Str &) const noexcept; + bool operator>(const Str &) const noexcept; + bool operator>=(const Str &) const noexcept; - void swap(Str &) noexcept; + void swap(Str &) noexcept; private: - class uninit; - Str(uninit) noexcept; - friend impl; + class uninit; + Str(uninit) noexcept; + friend impl; - std::array repr; + std::array repr; }; #endif // CXXBRIDGE1_RUST_STR } // namespace cxxbridge1 } // namespace rust namespace rustutils { - struct ParsedColor; +struct ParsedColor; } namespace rustutils { #ifndef CXXBRIDGE1_STRUCT_rustutils$ParsedColor #define CXXBRIDGE1_STRUCT_rustutils$ParsedColor struct ParsedColor final { - bool success; - float r; - float g; - float b; - float a; + bool success; + float r; + float g; + float b; + float a; - using IsRelocatable = ::std::true_type; + using IsRelocatable = ::std::true_type; }; #endif // CXXBRIDGE1_STRUCT_rustutils$ParsedColor From a2fb48c3a0951984d46024f452a1c37b1f817c11 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 10 Jan 2025 17:13:06 +0100 Subject: [PATCH 27/56] PR comments --- .github/workflows/linux-ci.yml | 4 +++- rustutils/BUILD.bazel | 2 +- rustutils/cpp/generate.sh | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linux-ci.yml b/.github/workflows/linux-ci.yml index 6c09c01abbf..83dc47299bb 100644 --- a/.github/workflows/linux-ci.yml +++ b/.github/workflows/linux-ci.yml @@ -202,7 +202,9 @@ jobs: - name: Install cxxbridge-cmd (compile) if: ${{ github.ref == 'refs/heads/rust' || github.event.pull_request.base.ref == 'rust' }} - run: cargo install cxxbridge-cmd + uses: baptiste0928/cargo-install@v3 + with: + crate: cxxbridge-cmd - name: Cache Bazel uses: actions/cache@v4 diff --git a/rustutils/BUILD.bazel b/rustutils/BUILD.bazel index 6fe1fb4b093..b350d6e2ecc 100644 --- a/rustutils/BUILD.bazel +++ b/rustutils/BUILD.bazel @@ -30,4 +30,4 @@ cc_library( ":rustutils", ], visibility = ["//visibility:public"], -) \ No newline at end of file +) diff --git a/rustutils/cpp/generate.sh b/rustutils/cpp/generate.sh index 1f842c2706d..74f8a3c67ab 100755 --- a/rustutils/cpp/generate.sh +++ b/rustutils/cpp/generate.sh @@ -5,4 +5,4 @@ set -e cxxbridge rustutils/src/lib.rs --header > rustutils/lib.h -cxxbridge rustutils/src/lib.rs > rustutils/cpp/src/lib.rs.cc \ No newline at end of file +cxxbridge rustutils/src/lib.rs > rustutils/cpp/src/lib.rs.cc From fca316391c67f2ff5af39ef87c6a55e2ec38d429 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 10 Jan 2025 17:17:15 +0100 Subject: [PATCH 28/56] fix merge oops --- .github/workflows/android-ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/android-ci.yml b/.github/workflows/android-ci.yml index 3bdcb7d142f..a2bb0a11877 100644 --- a/.github/workflows/android-ci.yml +++ b/.github/workflows/android-ci.yml @@ -297,6 +297,11 @@ jobs: submodules: recursive fetch-depth: 0 + - uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: "17" + - uses: hendrikmuhs/ccache-action@v1.2 with: key: ${{ github.job }} From 643de09684813d8e39d6ef6b7030137a28b979bb Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 10 Jan 2025 17:20:07 +0100 Subject: [PATCH 29/56] fix setup-java --- .github/workflows/android-ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/android-ci.yml b/.github/workflows/android-ci.yml index a2bb0a11877..0616a303272 100644 --- a/.github/workflows/android-ci.yml +++ b/.github/workflows/android-ci.yml @@ -231,6 +231,11 @@ jobs: submodules: recursive fetch-depth: 0 + - uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: "17" + - name: Add aarch64-linux-android for Rust toolchian if: ${{ github.ref == 'refs/heads/rust' || github.event.pull_request.base.ref == 'rust' }} run: rustup target add --toolchain stable-x86_64-unknown-linux-gnu aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android @@ -314,11 +319,6 @@ jobs: cmakeVersion: 3.24.1 ninjaVersion: latest - - uses: actions/setup-java@v4 - with: - distribution: "temurin" - java-version: "17" - - name: Add aarch64-linux-android for Rust toolchian if: ${{ github.ref == 'refs/heads/rust' || github.event.pull_request.base.ref == 'rust' }} run: rustup target add --toolchain stable-x86_64-unknown-linux-gnu aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android From 29a2bb20d363a24d359c32ade6003fd27847c6ab Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 10 Jan 2025 19:00:14 +0100 Subject: [PATCH 30/56] PR comments, fix CMake --- .github/workflows/android-ci.yml | 8 +++++--- CMakeLists.txt | 2 ++ docker/startup.sh | 2 +- docs/mdbook/src/rust.md | 22 +++++++++++++++++++--- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/.github/workflows/android-ci.yml b/.github/workflows/android-ci.yml index 0616a303272..d6842020e50 100644 --- a/.github/workflows/android-ci.yml +++ b/.github/workflows/android-ci.yml @@ -71,8 +71,10 @@ jobs: distribution: "temurin" java-version: "17" - - name: Add aarch64-linux-android for Rust toolchian + - name: Add aarch64-linux-android for Rust toolchain + if: ${{ github.ref == 'refs/heads/rust' || github.event.pull_request.base.ref == 'rust' }} 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: @@ -236,7 +238,7 @@ jobs: distribution: "temurin" java-version: "17" - - name: Add aarch64-linux-android for Rust toolchian + - name: Add aarch64-linux-android for Rust toolchain if: ${{ github.ref == 'refs/heads/rust' || github.event.pull_request.base.ref == 'rust' }} run: rustup target add --toolchain stable-x86_64-unknown-linux-gnu aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android @@ -319,7 +321,7 @@ jobs: cmakeVersion: 3.24.1 ninjaVersion: latest - - name: Add aarch64-linux-android for Rust toolchian + - name: Add aarch64-linux-android for Rust toolchain if: ${{ github.ref == 'refs/heads/rust' || github.event.pull_request.base.ref == 'rust' }} run: rustup target add --toolchain stable-x86_64-unknown-linux-gnu aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android diff --git a/CMakeLists.txt b/CMakeLists.txt index 904c4b3ec7f..3c6b1da70de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1459,7 +1459,9 @@ include(${PROJECT_SOURCE_DIR}/vendor/vector-tile.cmake) include(${PROJECT_SOURCE_DIR}/vendor/wagyu.cmake) include(${PROJECT_SOURCE_DIR}/vendor/metal-cpp.cmake) +if(MLN_USE_RUST) include(${PROJECT_SOURCE_DIR}/rustutils/rustutils.cmake) +endif() target_link_libraries( mbgl-core diff --git a/docker/startup.sh b/docker/startup.sh index 6f59dbad338..3a60b8e63e0 100644 --- a/docker/startup.sh +++ b/docker/startup.sh @@ -6,7 +6,7 @@ if [ ! -d /app/.github ] || [ ! -d ~/.cache ]; then echo " From the root of this repo, run the following command." echo " You may add any command to perform in the container at the end of this command." echo " " - echo " docker run --rm -it -v \"$PWD:/app/\" -v \"$PWD/docker/.cache:/home/$USERNAME/.cache\" maplibre-native-image" + echo ' docker run --rm -it -v "$PWD:/app/" -v "$PWD/docker/.cache:/home/'"$USERNAME"'/.cache" maplibre-native-image' exit 1 fi diff --git a/docs/mdbook/src/rust.md b/docs/mdbook/src/rust.md index 634d5bb2ca2..31169b1f626 100644 --- a/docs/mdbook/src/rust.md +++ b/docs/mdbook/src/rust.md @@ -14,14 +14,30 @@ Check in the generated files under `rustutils/cpp`. We might intergrate this generation process into the build, but the tools to do so are experimental and immature as of January 2025. +You can use `rustup` to manage toolchains. Which toolchain you needs depends on your host platform and for what platform you are trying to build. If your host and target platform are the same, you probably have the correct toolchain installed after installing Rust. For example when building for **Android** and building on a **x84 Linux** host you would use the following command: + +``` +rustup target add --toolchain stable-x86_64-unknown-linux-gnu aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android +``` + +See [Platform Support](https://doc.rust-lang.org/nightly/rustc/platform-support.html) in the Rust documentation for more details. You will get a descriptive error message when the correct toolchain is not available, so we don't list all possible combinations here. + ## Building -You need to have the correct Rust toolchain(s) installed. +You need to have the correct Rust toolchain(s) installed. See [Install Rust](https://www.rust-lang.org/tools/install) to install Rust. + +You can manage toolchains with rus ### CMake -Set `MLN_USE_RUST` to `ON`. +Set `MLN_USE_RUST=ON` when generating a configuration with CMake. ### Bazel -Pass `--//:use_rust` to Bazel. \ No newline at end of file +Pass the `--//:use_rust` flag to Bazel commands. + +Note that when [generating an Xcode project](./ios/README.md) you should not pass this option to Bazel directly, but as follows: + +``` +bazel run //platform/ios:xcodeproj --@rules_xcodeproj//xcodeproj:extra_common_flags="--//:renderer=metal --//:use_rust" +``` \ No newline at end of file From bfafa2bd8b7492ac698b02bc54083f41a29b5905 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 10 Jan 2025 19:05:33 +0100 Subject: [PATCH 31/56] Add rustfmt to pre-commit hooks --- .pre-commit-config.yaml | 5 +++++ BUILD.bazel | 6 +++--- MODULE.bazel | 4 +--- bazel/core.bzl | 2 +- rustutils/BUILD.bazel | 8 ++++---- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5482b7ab088..95ca84e566e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,6 +24,11 @@ repos: hooks: - id: swiftformat args: [--swiftversion, "5.8"] +- repo: https://github.com/doublify/pre-commit-rust + rev: master + hooks: + - id: fmt + - id: cargo-check ci: # sometimes fails https://github.com/keith/pre-commit-buildifier/issues/13 skip: [buildifier] diff --git a/BUILD.bazel b/BUILD.bazel index fc59dd2a766..9b387f5a613 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,5 +1,5 @@ load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_library", "js_run_binary") -load("@bazel_skylib//rules:common_settings.bzl", "string_flag", "bool_flag") +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") load("@npm//:defs.bzl", "npm_link_all_packages") load( "//bazel:core.bzl", @@ -154,8 +154,8 @@ cc_library( ], "//conditions:default": [ "//vendor:csscolorparser", - ] - }) + ], + }), ) genrule( diff --git a/MODULE.bazel b/MODULE.bazel index c0b578d5c05..c4ad6f65442 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -64,17 +64,15 @@ darwin_config( bazel_dep(name = "rules_rust", version = "0.56.0") rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") - rust.toolchain( edition = "2021", - versions = ["1.80.0"] + versions = ["1.80.0"], ) use_repo(rust, "rust_toolchains") register_toolchains("@rust_toolchains//:all") crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate") - crate.from_cargo( name = "crates", cargo_lockfile = "//rustutils:Cargo.lock", diff --git a/bazel/core.bzl b/bazel/core.bzl index 6f31b587e1a..75a30b5b152 100644 --- a/bazel/core.bzl +++ b/bazel/core.bzl @@ -657,7 +657,7 @@ MLN_CORE_SOURCE = [ ], "//conditions:default": [ "src/mbgl/util/color.cpp", - ] + ], }) MLN_CORE_HEADERS = [ diff --git a/rustutils/BUILD.bazel b/rustutils/BUILD.bazel index b350d6e2ecc..4c6bcd30ec9 100644 --- a/rustutils/BUILD.bazel +++ b/rustutils/BUILD.bazel @@ -18,16 +18,16 @@ rust_static_library( cc_library( name = "rustutilslib", srcs = [ - "cpp/src/lib.rs.cc" + "cpp/src/lib.rs.cc", ], hdrs = [ - "cpp/include/rustutils/lib.hpp" + "cpp/include/rustutils/lib.hpp", ], includes = [ - "cpp/include" + "cpp/include", ], + visibility = ["//visibility:public"], deps = [ ":rustutils", ], - visibility = ["//visibility:public"], ) From 3e06aa308bce37b4e245c8918ac57522339f6c4b Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 10 Jan 2025 19:05:43 +0100 Subject: [PATCH 32/56] change CMake file --- rustutils/rustutils.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rustutils/rustutils.cmake b/rustutils/rustutils.cmake index 2e86a441580..116f3157490 100644 --- a/rustutils/rustutils.cmake +++ b/rustutils/rustutils.cmake @@ -1,5 +1,5 @@ # Include guard -if(TARGET rustutils AND MLN_USE_RUST) +if(TARGET rustutils) return() endif() From 6d848bbbe984ad5db8ff98ba4e60ade271cc47f5 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 10 Jan 2025 19:06:32 +0100 Subject: [PATCH 33/56] put docs under right heading --- docs/mdbook/src/rust.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/mdbook/src/rust.md b/docs/mdbook/src/rust.md index 31169b1f626..49284415efc 100644 --- a/docs/mdbook/src/rust.md +++ b/docs/mdbook/src/rust.md @@ -14,6 +14,10 @@ Check in the generated files under `rustutils/cpp`. We might intergrate this generation process into the build, but the tools to do so are experimental and immature as of January 2025. +## Building + +You need to have the correct Rust toolchain(s) installed. See [Install Rust](https://www.rust-lang.org/tools/install) to install Rust. + You can use `rustup` to manage toolchains. Which toolchain you needs depends on your host platform and for what platform you are trying to build. If your host and target platform are the same, you probably have the correct toolchain installed after installing Rust. For example when building for **Android** and building on a **x84 Linux** host you would use the following command: ``` @@ -22,12 +26,6 @@ rustup target add --toolchain stable-x86_64-unknown-linux-gnu aarch64-linux-andr See [Platform Support](https://doc.rust-lang.org/nightly/rustc/platform-support.html) in the Rust documentation for more details. You will get a descriptive error message when the correct toolchain is not available, so we don't list all possible combinations here. -## Building - -You need to have the correct Rust toolchain(s) installed. See [Install Rust](https://www.rust-lang.org/tools/install) to install Rust. - -You can manage toolchains with rus - ### CMake Set `MLN_USE_RUST=ON` when generating a configuration with CMake. From f74e5bb8c4cadf45c67887a7014fb972820c1ec6 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 10 Jan 2025 21:48:16 +0100 Subject: [PATCH 34/56] fix .pre-commit.yaml --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 95ca84e566e..a7855707385 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,7 +25,7 @@ repos: - id: swiftformat args: [--swiftversion, "5.8"] - repo: https://github.com/doublify/pre-commit-rust - rev: master + rev: v1.0 hooks: - id: fmt - id: cargo-check From a6162cbbea459f62310391c0b6922d1bc5e0fc18 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Mon, 13 Jan 2025 12:59:22 +0100 Subject: [PATCH 35/56] Update docker/Dockerfile --- docker/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index c3b7ed5851f..58a4e6ab55b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,3 @@ -# Ubuntu version should match SWIFT version below FROM ubuntu:22.04 # Install build tools and dependencies From 2ebf02aee8d905b732959f2eb6e6245f6b7d8a94 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Mon, 13 Jan 2025 13:02:15 +0100 Subject: [PATCH 36/56] Update rustutils/cpp/generate.sh Co-authored-by: Ian Wagner --- rustutils/cpp/generate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rustutils/cpp/generate.sh b/rustutils/cpp/generate.sh index 74f8a3c67ab..117a3f31b31 100755 --- a/rustutils/cpp/generate.sh +++ b/rustutils/cpp/generate.sh @@ -4,5 +4,5 @@ set -e -cxxbridge rustutils/src/lib.rs --header > rustutils/lib.h +cxxbridge rustutils/src/lib.rs --header > rustutils/cpp/include/rustutils/lib.hpp cxxbridge rustutils/src/lib.rs > rustutils/cpp/src/lib.rs.cc From 4d6477171f74e59242b25abe241ed985db879ad2 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Mon, 13 Jan 2025 13:27:04 +0100 Subject: [PATCH 37/56] Update src/mbgl/util/color.rs.cpp Co-authored-by: Ian Wagner --- src/mbgl/util/color.rs.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mbgl/util/color.rs.cpp b/src/mbgl/util/color.rs.cpp index e1ff57996cd..44f482197ab 100644 --- a/src/mbgl/util/color.rs.cpp +++ b/src/mbgl/util/color.rs.cpp @@ -1,3 +1,5 @@ +// This is an interface-compatible file analogous to color.cpp +// which is conditionally compiled when the optional Rust build flag is enabled. #include #include From 0101522a91980935e2f9080dad306c7cfa2c2c22 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Mon, 13 Jan 2025 21:51:39 +0100 Subject: [PATCH 38/56] allow modules, remove generates sources, update license --- .pre-commit-config.yaml | 10 +-- MODULE.bazel | 6 +- docs/mdbook/src/rust.md | 44 +++++++++--- rustutils/BUILD.bazel | 22 ++++-- rustutils/Cargo.toml | 4 +- rustutils/cpp/generate.sh | 8 --- rustutils/cpp/include/rustutils/lib.hpp | 86 ----------------------- rustutils/cpp/src/lib.rs.cc | 91 ------------------------- rustutils/generate.sh | 32 +++++++++ rustutils/rustutils.cmake | 43 ++++++++++-- rustutils/src/color.rs | 35 ++++++++++ rustutils/src/lib.rs | 37 +--------- src/mbgl/util/color.rs.cpp | 2 +- 13 files changed, 172 insertions(+), 248 deletions(-) delete mode 100755 rustutils/cpp/generate.sh delete mode 100644 rustutils/cpp/include/rustutils/lib.hpp delete mode 100644 rustutils/cpp/src/lib.rs.cc create mode 100755 rustutils/generate.sh create mode 100644 rustutils/src/color.rs diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a7855707385..fba750866e7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,11 +24,13 @@ repos: hooks: - id: swiftformat args: [--swiftversion, "5.8"] -- repo: https://github.com/doublify/pre-commit-rust - rev: v1.0 +- repo: local hooks: - - id: fmt - - id: cargo-check + - id: rustfmt + name: rustfmt + entry: rustfmt --edition 2021 + language: rust + types: [rust] ci: # sometimes fails https://github.com/keith/pre-commit-buildifier/issues/13 skip: [buildifier] diff --git a/MODULE.bazel b/MODULE.bazel index c4ad6f65442..919ca0e063b 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,6 +1,6 @@ module(name = "maplibre") -bazel_dep(name = "apple_support", version = "1.17.0", repo_name = "build_bazel_apple_support") +bazel_dep(name = "apple_support", version = "1.17.1", repo_name = "build_bazel_apple_support") bazel_dep(name = "bazel_skylib", version = "1.7.1") bazel_dep(name = "platforms", version = "0.0.10") bazel_dep(name = "rules_apple", version = "3.16.1", repo_name = "build_bazel_rules_apple") @@ -66,7 +66,9 @@ bazel_dep(name = "rules_rust", version = "0.56.0") rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") rust.toolchain( edition = "2021", - versions = ["1.80.0"], + versions = [ + "1.79.0" + ], ) use_repo(rust, "rust_toolchains") diff --git a/docs/mdbook/src/rust.md b/docs/mdbook/src/rust.md index 49284415efc..854bb45d276 100644 --- a/docs/mdbook/src/rust.md +++ b/docs/mdbook/src/rust.md @@ -4,15 +4,9 @@ We have added experimental support for intergrating Rust code into the source tr ## Rust Bridge -The Rust bridge lives in `rustutils`. To regenerate the C++ bridge run the following script from the root of the repository. +The Rust bridge lives in the root `rustutils` directory. -``` -rustutils/cpp/generate.sh -``` - -Check in the generated files under `rustutils/cpp`. - -We might intergrate this generation process into the build, but the tools to do so are experimental and immature as of January 2025. +We use [CXX](https://cxx.rs/) to allow interop between Rust and C++. ## Building @@ -26,6 +20,12 @@ rustup target add --toolchain stable-x86_64-unknown-linux-gnu aarch64-linux-andr See [Platform Support](https://doc.rust-lang.org/nightly/rustc/platform-support.html) in the Rust documentation for more details. You will get a descriptive error message when the correct toolchain is not available, so we don't list all possible combinations here. +You also need to have cxxbridge installed: + +``` +cargo install cxxbridge +``` + ### CMake Set `MLN_USE_RUST=ON` when generating a configuration with CMake. @@ -38,4 +38,30 @@ Note that when [generating an Xcode project](./ios/README.md) you should not pas ``` bazel run //platform/ios:xcodeproj --@rules_xcodeproj//xcodeproj:extra_common_flags="--//:renderer=metal --//:use_rust" -``` \ No newline at end of file +``` + +## Creating a new Module + +To create a new module: + +1. Add a new source file to `rustutils/src/example.rs`. +2. Implement it, see the [CXX documentation](https://cxx.rs/index.html) or see `rustutils/src/color.rs` for an example. +3. Create a C++ source file that will use the generated C++ header. See `src/mbgl/util/color.rs.cpp` for an example. Import the generated header with + ``` + #include + ``` +4. Conditionally include either the `*.rs.cpp` file or the `*.cpp` file it replaces in CMake and Bazel. Here is what it looks like for CMake: + ``` + ${PROJECT_SOURCE_DIR}/src/mbgl/util/color$,.rs.cpp,.cpp> + ``` + And here for Bazel: + ``` + select({ + "//:rust": [ + "src/mbgl/util/color.rs.cpp", + ], + "//conditions:default": [ + "src/mbgl/util/color.cpp", + ], + }) + ``` \ No newline at end of file diff --git a/rustutils/BUILD.bazel b/rustutils/BUILD.bazel index 4c6bcd30ec9..4d55f70c5f5 100644 --- a/rustutils/BUILD.bazel +++ b/rustutils/BUILD.bazel @@ -1,10 +1,26 @@ load("@rules_cc//cc:defs.bzl", "cc_library") load("@rules_rust//rust:defs.bzl", "rust_static_library") +genrule( + name = "cpp_bindings", + srcs = [ + "src/color.rs", + ], + outs = [ + "cpp/include/rustutils/color.hpp", + "cpp/src/color.rs.cpp" + ], + cmd = "./$(location generate.sh) $(@D) $(SRCS)", + tools = [ + ":generate.sh", + ], +) + rust_static_library( name = "rustutils", srcs = [ "src/lib.rs", + "src/color.rs" ], crate_name = "rustutils", visibility = ["//visibility:public"], @@ -14,14 +30,10 @@ rust_static_library( ], ) -# Link the Rust static library to the C++ library cc_library( name = "rustutilslib", srcs = [ - "cpp/src/lib.rs.cc", - ], - hdrs = [ - "cpp/include/rustutils/lib.hpp", + ":cpp_bindings" ], includes = [ "cpp/include", diff --git a/rustutils/Cargo.toml b/rustutils/Cargo.toml index cea6240b2d6..8d98a0d03c4 100644 --- a/rustutils/Cargo.toml +++ b/rustutils/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "rustutils" version = "0.1.0" -authors = ["Yuri Astrakhan ", "MapLibre contributors"] +authors = ["MapLibre contributors"] description = "Core Rust utilities for MapLibre Native" edition = "2021" -license = "MIT OR Apache-2.0" +license = "BSD-2-Clause" repository = "https://github.com/maplibre/maplibre-native" [lib] diff --git a/rustutils/cpp/generate.sh b/rustutils/cpp/generate.sh deleted file mode 100755 index 117a3f31b31..00000000000 --- a/rustutils/cpp/generate.sh +++ /dev/null @@ -1,8 +0,0 @@ -# Run this script from the repository root -# Install cxxbridge with: -# $ cargo install cxxbridge-cmd - -set -e - -cxxbridge rustutils/src/lib.rs --header > rustutils/cpp/include/rustutils/lib.hpp -cxxbridge rustutils/src/lib.rs > rustutils/cpp/src/lib.rs.cc diff --git a/rustutils/cpp/include/rustutils/lib.hpp b/rustutils/cpp/include/rustutils/lib.hpp deleted file mode 100644 index b6f6d244e71..00000000000 --- a/rustutils/cpp/include/rustutils/lib.hpp +++ /dev/null @@ -1,86 +0,0 @@ -#pragma once -#include -#include -#include -#include - -namespace rust { -inline namespace cxxbridge1 { -// #include "rust/cxx.h" - -namespace { -template -class impl; -} // namespace - -class String; - -#ifndef CXXBRIDGE1_RUST_STR -#define CXXBRIDGE1_RUST_STR -class Str final { -public: - Str() noexcept; - Str(const String &) noexcept; - Str(const std::string &); - Str(const char *); - Str(const char *, std::size_t); - - Str &operator=(const Str &) & noexcept = default; - - explicit operator std::string() const; - - const char *data() const noexcept; - std::size_t size() const noexcept; - std::size_t length() const noexcept; - bool empty() const noexcept; - - Str(const Str &) noexcept = default; - ~Str() noexcept = default; - - using iterator = const char *; - using const_iterator = const char *; - const_iterator begin() const noexcept; - const_iterator end() const noexcept; - const_iterator cbegin() const noexcept; - const_iterator cend() const noexcept; - - bool operator==(const Str &) const noexcept; - bool operator!=(const Str &) const noexcept; - bool operator<(const Str &) const noexcept; - bool operator<=(const Str &) const noexcept; - bool operator>(const Str &) const noexcept; - bool operator>=(const Str &) const noexcept; - - void swap(Str &) noexcept; - -private: - class uninit; - Str(uninit) noexcept; - friend impl; - - std::array repr; -}; -#endif // CXXBRIDGE1_RUST_STR -} // namespace cxxbridge1 -} // namespace rust - -namespace rustutils { -struct ParsedColor; -} - -namespace rustutils { -#ifndef CXXBRIDGE1_STRUCT_rustutils$ParsedColor -#define CXXBRIDGE1_STRUCT_rustutils$ParsedColor -struct ParsedColor final { - bool success; - float r; - float g; - float b; - float a; - - using IsRelocatable = ::std::true_type; -}; -#endif // CXXBRIDGE1_STRUCT_rustutils$ParsedColor - -::rustutils::ParsedColor parse_css_color(::rust::Str css_str) noexcept; -} // namespace rustutils diff --git a/rustutils/cpp/src/lib.rs.cc b/rustutils/cpp/src/lib.rs.cc deleted file mode 100644 index 76f36bb6ef5..00000000000 --- a/rustutils/cpp/src/lib.rs.cc +++ /dev/null @@ -1,91 +0,0 @@ -#include -#include -#include -#include - -namespace rust { -inline namespace cxxbridge1 { -// #include "rust/cxx.h" - -namespace { -template -class impl; -} // namespace - -class String; - -#ifndef CXXBRIDGE1_RUST_STR -#define CXXBRIDGE1_RUST_STR -class Str final { -public: - Str() noexcept; - Str(const String &) noexcept; - Str(const std::string &); - Str(const char *); - Str(const char *, std::size_t); - - Str &operator=(const Str &) &noexcept = default; - - explicit operator std::string() const; - - const char *data() const noexcept; - std::size_t size() const noexcept; - std::size_t length() const noexcept; - bool empty() const noexcept; - - Str(const Str &) noexcept = default; - ~Str() noexcept = default; - - using iterator = const char *; - using const_iterator = const char *; - const_iterator begin() const noexcept; - const_iterator end() const noexcept; - const_iterator cbegin() const noexcept; - const_iterator cend() const noexcept; - - bool operator==(const Str &) const noexcept; - bool operator!=(const Str &) const noexcept; - bool operator<(const Str &) const noexcept; - bool operator<=(const Str &) const noexcept; - bool operator>(const Str &) const noexcept; - bool operator>=(const Str &) const noexcept; - - void swap(Str &) noexcept; - -private: - class uninit; - Str(uninit) noexcept; - friend impl; - - std::array repr; -}; -#endif // CXXBRIDGE1_RUST_STR -} // namespace cxxbridge1 -} // namespace rust - -namespace rustutils { - struct ParsedColor; -} - -namespace rustutils { -#ifndef CXXBRIDGE1_STRUCT_rustutils$ParsedColor -#define CXXBRIDGE1_STRUCT_rustutils$ParsedColor -struct ParsedColor final { - bool success; - float r; - float g; - float b; - float a; - - using IsRelocatable = ::std::true_type; -}; -#endif // CXXBRIDGE1_STRUCT_rustutils$ParsedColor - -extern "C" { -::rustutils::ParsedColor rustutils$cxxbridge1$parse_css_color(::rust::Str css_str) noexcept; -} // extern "C" - -::rustutils::ParsedColor parse_css_color(::rust::Str css_str) noexcept { - return rustutils$cxxbridge1$parse_css_color(css_str); -} -} // namespace rustutils diff --git a/rustutils/generate.sh b/rustutils/generate.sh new file mode 100755 index 00000000000..37aeb2a9578 --- /dev/null +++ b/rustutils/generate.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# Run this script from the repository root +# Install cxxbridge with: +# $ cargo install cxxbridge-cmd + +set -e + +if [ "$#" -lt 2 ]; then + echo "Error: output_dir and at least one input file are required." >&2 + echo "Usage: $0 [input_file2 ...]" >&2 + exit 1 +fi + +output_dir="$1" +shift + +for input_file in "$@"; do + if [[ "$input_file" != *.rs ]]; then + echo "Error: All input files must have a .rs extension. Invalid file: $input_file" >&2 + exit 1 + fi +done + +mkdir -p "$output_dir/cpp/include/rustutils" +mkdir -p "$output_dir/cpp/src" + +for input_file in "$@"; do + base_name=$(basename "$input_file" .rs) + cxxbridge "$input_file" --header > "$output_dir/cpp/include/rustutils/${base_name}.hpp" + cxxbridge "$input_file" > "$output_dir/cpp/src/${base_name}.rs.cpp" +done \ No newline at end of file diff --git a/rustutils/rustutils.cmake b/rustutils/rustutils.cmake index 116f3157490..146ee61fb42 100644 --- a/rustutils/rustutils.cmake +++ b/rustutils/rustutils.cmake @@ -14,15 +14,50 @@ FetchContent_MakeAvailable(Corrosion) corrosion_import_crate(MANIFEST_PATH ${CMAKE_CURRENT_LIST_DIR}/Cargo.toml) -set(RUSTUTILS_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/cpp/include") -set(RUSTUTILS_SRC "${CMAKE_CURRENT_LIST_DIR}/cpp/src/lib.rs.cc") +# Define output directories for generated bindings +set(RUSTUTILS_OUTPUT_DIR "${CMAKE_BINARY_DIR}/rustutils_bindings") +set(RUSTUTILS_INCLUDE_DIR "${RUSTUTILS_OUTPUT_DIR}/cpp/include") +set(RUSTUTILS_SRC_DIR "${RUSTUTILS_OUTPUT_DIR}/cpp/src") + +# Ensure the output directories exist +file(MAKE_DIRECTORY ${RUSTUTILS_INCLUDE_DIR}) +file(MAKE_DIRECTORY ${RUSTUTILS_SRC_DIR}) + +set(RUSTUTILS_RS_FILES + ${CMAKE_CURRENT_LIST_DIR}/src/color.rs +) + +# Initialize variables for generated files +set(RUSTUTILS_GENERATED_SOURCES) +set(RUSTUTILS_GENERATED_HEADERS) + +# Transform .rs to .rs.cpp and .hpp +foreach(rs_file ${RUSTUTILS_RS_FILES}) + get_filename_component(base_name ${rs_file} NAME_WE) + list(APPEND RUSTUTILS_GENERATED_SOURCES "${RUSTUTILS_SRC_DIR}/${base_name}.rs.cpp") + list(APPEND RUSTUTILS_GENERATED_HEADERS "${RUSTUTILS_INCLUDE_DIR}/rustutils/${base_name}.hpp") +endforeach() + +add_custom_command( + OUTPUT ${RUSTUTILS_OUTPUT_DIR} + COMMAND ${CMAKE_COMMAND} -E env + ${CMAKE_CURRENT_LIST_DIR}/generate.sh ${RUSTUTILS_OUTPUT_DIR} ${RUSTUTILS_RS_FILES} + DEPENDS ${CMAKE_CURRENT_LIST_DIR}/generate.sh ${RUSTUTILS_RS_FILES} + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + COMMENT "Generating C++ bindings for Rust sources" + VERBATIM +) + +add_custom_target(rustutils_bindings DEPENDS ${RUSTUTILS_GENERATED_SOURCES} ${RUSTUTILS_GENERATED_HEADERS}) add_library(mbgl-rustutils STATIC - ${RUSTUTILS_SRC} + ${RUSTUTILS_GENERATED_SOURCES} ) +add_dependencies(mbgl-rustutils rustutils_bindings) + target_include_directories(mbgl-rustutils PUBLIC ${RUSTUTILS_INCLUDE_DIR} ) -target_link_libraries(mbgl-rustutils PUBLIC rustutils) +target_link_libraries(mbgl-rustutils PUBLIC rustutils) \ No newline at end of file diff --git a/rustutils/src/color.rs b/rustutils/src/color.rs new file mode 100644 index 00000000000..31740ee06eb --- /dev/null +++ b/rustutils/src/color.rs @@ -0,0 +1,35 @@ +use csscolorparser::Color; + +#[cxx::bridge(namespace = "rustutils")] +mod ffi { + struct ParsedColor { + pub success: bool, + pub r: f32, + pub g: f32, + pub b: f32, + pub a: f32, + } + + extern "Rust" { + fn parse_css_color(css_str: &str) -> ParsedColor; + } +} + +pub fn parse_css_color(css_str: &str) -> ffi::ParsedColor { + css_str + .parse::() + .map(|color| ffi::ParsedColor { + success: true, + r: color.r as f32, + g: color.g as f32, + b: color.b as f32, + a: color.a as f32, + }) + .unwrap_or_else(|_| ffi::ParsedColor { + success: false, + r: 0.0, + g: 0.0, + b: 0.0, + a: 0.0, + }) +} \ No newline at end of file diff --git a/rustutils/src/lib.rs b/rustutils/src/lib.rs index 5841c4daab3..2499321453a 100644 --- a/rustutils/src/lib.rs +++ b/rustutils/src/lib.rs @@ -1,36 +1 @@ -use crate::ffi::ParsedColor; -use csscolorparser::Color; - -#[cxx::bridge(namespace = "rustutils")] -mod ffi { - struct ParsedColor { - pub success: bool, - pub r: f32, - pub g: f32, - pub b: f32, - pub a: f32, - } - - extern "Rust" { - fn parse_css_color(css_str: &str) -> ParsedColor; - } -} - -fn parse_css_color(css_str: &str) -> ParsedColor { - css_str - .parse::() - .map(|color| ParsedColor { - success: true, - r: color.r as f32, - g: color.g as f32, - b: color.b as f32, - a: color.a as f32, - }) - .unwrap_or_else(|_| ParsedColor { - success: false, - r: 0.0, - g: 0.0, - b: 0.0, - a: 0.0, - }) -} +mod color; \ No newline at end of file diff --git a/src/mbgl/util/color.rs.cpp b/src/mbgl/util/color.rs.cpp index 44f482197ab..98a6028bad8 100644 --- a/src/mbgl/util/color.rs.cpp +++ b/src/mbgl/util/color.rs.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include namespace mbgl { From cc5bf2a194c5d92a0a1b96aa90d2a5f3082a7791 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 Jan 2025 20:52:38 +0000 Subject: [PATCH 39/56] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- rustutils/src/color.rs | 2 +- rustutils/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rustutils/src/color.rs b/rustutils/src/color.rs index 31740ee06eb..090bb76a878 100644 --- a/rustutils/src/color.rs +++ b/rustutils/src/color.rs @@ -32,4 +32,4 @@ pub fn parse_css_color(css_str: &str) -> ffi::ParsedColor { b: 0.0, a: 0.0, }) -} \ No newline at end of file +} diff --git a/rustutils/src/lib.rs b/rustutils/src/lib.rs index 2499321453a..459f9e1c997 100644 --- a/rustutils/src/lib.rs +++ b/rustutils/src/lib.rs @@ -1 +1 @@ -mod color; \ No newline at end of file +mod color; From 5ae0610c73d5f5ea1cf5a211d88e693d877b6a33 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Tue, 14 Jan 2025 16:59:41 +0100 Subject: [PATCH 40/56] remove rust from android-ci workflow --- .github/workflows/android-ci.yml | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/.github/workflows/android-ci.yml b/.github/workflows/android-ci.yml index d6842020e50..c121ca7bc01 100644 --- a/.github/workflows/android-ci.yml +++ b/.github/workflows/android-ci.yml @@ -71,10 +71,6 @@ jobs: distribution: "temurin" java-version: "17" - - name: Add aarch64-linux-android for Rust toolchain - if: ${{ github.ref == 'refs/heads/rust' || github.event.pull_request.base.ref == 'rust' }} - 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: @@ -238,10 +234,6 @@ jobs: distribution: "temurin" java-version: "17" - - name: Add aarch64-linux-android for Rust toolchain - if: ${{ github.ref == 'refs/heads/rust' || github.event.pull_request.base.ref == 'rust' }} - 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: @@ -304,11 +296,6 @@ jobs: submodules: recursive fetch-depth: 0 - - uses: actions/setup-java@v4 - with: - distribution: "temurin" - java-version: "17" - - uses: hendrikmuhs/ccache-action@v1.2 with: key: ${{ github.job }} @@ -321,9 +308,10 @@ jobs: cmakeVersion: 3.24.1 ninjaVersion: latest - - name: Add aarch64-linux-android for Rust toolchain - if: ${{ github.ref == 'refs/heads/rust' || github.event.pull_request.base.ref == 'rust' }} - run: rustup target add --toolchain stable-x86_64-unknown-linux-gnu aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android + - uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: "17" - name: Build and Upload Render Test APKs (${{ matrix.flavor }}) uses: ./.github/actions/android-build-and-upload-render-test From 96757f3c1c9cab3681cec692eb86740a3fe6d75a Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Tue, 14 Jan 2025 17:00:09 +0100 Subject: [PATCH 41/56] add extra_target_triples to configure Rust toolchain iOS --- MODULE.bazel | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 919ca0e063b..61aade0fd07 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -66,8 +66,11 @@ bazel_dep(name = "rules_rust", version = "0.56.0") rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") rust.toolchain( edition = "2021", - versions = [ - "1.79.0" + extra_target_triples = [ + "aarch64-apple-ios-sim", + "x86_64-apple-ios", + "aarch64-apple-darwin", + "x86_64-apple-darwin", ], ) use_repo(rust, "rust_toolchains") From 11dafe6add35f97f8110b9963b617fa5e29a0822 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Tue, 14 Jan 2025 17:01:32 +0100 Subject: [PATCH 42/56] add basic CI for Rust --- .github/workflows/linux-ci.yml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/linux-ci.yml b/.github/workflows/linux-ci.yml index 83dc47299bb..fbb6da60daf 100644 --- a/.github/workflows/linux-ci.yml +++ b/.github/workflows/linux-ci.yml @@ -52,7 +52,7 @@ jobs: strategy: fail-fast: true matrix: - renderer: [legacy, drawable, vulkan] + renderer: [legacy, drawable, vulkan, drawable-rust] runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 @@ -91,6 +91,11 @@ jobs: - if: matrix.renderer == 'drawable' run: echo renderer_flag_cmake=-DMLN_DRAWABLE_RENDERER=ON >> "$GITHUB_ENV" + - if: matrix.renderer == 'drawable-rust' + run: | + echo renderer_flag_cmake=-DMLN_DRAWABLE_RENDERER=ON MLN_WITH_RUST=ON >> "$GITHUB_ENV" + cargo install cxxbridge-cmd + - if: matrix.renderer == 'legacy' run: echo renderer_flag_cmake=-DMLN_LEGACY_RENDERER=ON >> "$GITHUB_ENV" @@ -200,12 +205,6 @@ jobs: xvfb \ x11-xserver-utils - - name: Install cxxbridge-cmd (compile) - if: ${{ github.ref == 'refs/heads/rust' || github.event.pull_request.base.ref == 'rust' }} - uses: baptiste0928/cargo-install@v3 - with: - crate: cxxbridge-cmd - - name: Cache Bazel uses: actions/cache@v4 with: @@ -239,6 +238,14 @@ jobs: name: coverage-report path: ${{ env.coverage_report }} + linux-rust: + if: needs.pre_job.outputs.should_skip != 'true' + needs: pre_job + - uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + linux-ci-result: name: Linux CI Result if: needs.pre_job.outputs.should_skip != 'true' && always() From 8d016f324ad1776861c53a15e4468966f5075bf4 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Tue, 14 Jan 2025 17:03:56 +0100 Subject: [PATCH 43/56] yaml oopsie --- .github/workflows/linux-ci.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/linux-ci.yml b/.github/workflows/linux-ci.yml index fbb6da60daf..59abf821496 100644 --- a/.github/workflows/linux-ci.yml +++ b/.github/workflows/linux-ci.yml @@ -238,14 +238,6 @@ jobs: name: coverage-report path: ${{ env.coverage_report }} - linux-rust: - if: needs.pre_job.outputs.should_skip != 'true' - needs: pre_job - - uses: actions/checkout@v4 - with: - submodules: recursive - fetch-depth: 0 - linux-ci-result: name: Linux CI Result if: needs.pre_job.outputs.should_skip != 'true' && always() From 7355d6b6cc902c93649ce2f02c12f9a6a2742873 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Tue, 14 Jan 2025 17:04:09 +0100 Subject: [PATCH 44/56] formatting --- rustutils/BUILD.bazel | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rustutils/BUILD.bazel b/rustutils/BUILD.bazel index 4d55f70c5f5..612b1bcef24 100644 --- a/rustutils/BUILD.bazel +++ b/rustutils/BUILD.bazel @@ -8,7 +8,7 @@ genrule( ], outs = [ "cpp/include/rustutils/color.hpp", - "cpp/src/color.rs.cpp" + "cpp/src/color.rs.cpp", ], cmd = "./$(location generate.sh) $(@D) $(SRCS)", tools = [ @@ -19,8 +19,8 @@ genrule( rust_static_library( name = "rustutils", srcs = [ + "src/color.rs", "src/lib.rs", - "src/color.rs" ], crate_name = "rustutils", visibility = ["//visibility:public"], @@ -33,7 +33,7 @@ rust_static_library( cc_library( name = "rustutilslib", srcs = [ - ":cpp_bindings" + ":cpp_bindings", ], includes = [ "cpp/include", From 1f2aeb9a825c2d2c04960f784af93424400b878d Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Tue, 14 Jan 2025 19:22:13 +0100 Subject: [PATCH 45/56] fix linux-ci --- .github/workflows/linux-ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linux-ci.yml b/.github/workflows/linux-ci.yml index 59abf821496..220c4e945a5 100644 --- a/.github/workflows/linux-ci.yml +++ b/.github/workflows/linux-ci.yml @@ -163,7 +163,12 @@ jobs: - name: Run render test id: render_test - run: xvfb-run -a build/mbgl-render-test-runner --manifestPath=metrics/linux-${{ matrix.renderer }}.json + run: | + renderer="${{ matrix.renderer }}" + if [[ "$renderer" == *-rust ]]; then + renderer=${renderer%-rust} + fi + xvfb-run -a build/mbgl-render-test-runner --manifestPath=metrics/linux-"$renderer".json - name: Upload render test result if: always() && steps.render_test.outcome == 'failure' From 32f3f1cf7f1bea9b57e681ea90c841a0c3236d06 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Tue, 14 Jan 2025 19:22:30 +0100 Subject: [PATCH 46/56] improve rust.md --- docs/mdbook/src/rust.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/mdbook/src/rust.md b/docs/mdbook/src/rust.md index 854bb45d276..ff2a05321db 100644 --- a/docs/mdbook/src/rust.md +++ b/docs/mdbook/src/rust.md @@ -10,7 +10,9 @@ We use [CXX](https://cxx.rs/) to allow interop between Rust and C++. ## Building -You need to have the correct Rust toolchain(s) installed. See [Install Rust](https://www.rust-lang.org/tools/install) to install Rust. +### CMake + +When building with CMake, need to have the correct Rust toolchain(s) installed. See [Install Rust](https://www.rust-lang.org/tools/install) to install Rust. You can use `rustup` to manage toolchains. Which toolchain you needs depends on your host platform and for what platform you are trying to build. If your host and target platform are the same, you probably have the correct toolchain installed after installing Rust. For example when building for **Android** and building on a **x84 Linux** host you would use the following command: @@ -23,12 +25,10 @@ See [Platform Support](https://doc.rust-lang.org/nightly/rustc/platform-support. You also need to have cxxbridge installed: ``` -cargo install cxxbridge +cargo install cxxbridge-cmd ``` -### CMake - -Set `MLN_USE_RUST=ON` when generating a configuration with CMake. +Set `-DMLN_USE_RUST=ON` when generating a configuration with CMake. ### Bazel From 06b4bef3c9019bed7b3091a1f18639fcba809726 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Tue, 14 Jan 2025 19:22:43 +0100 Subject: [PATCH 47/56] improve rustutils.cmake --- rustutils/rustutils.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rustutils/rustutils.cmake b/rustutils/rustutils.cmake index 146ee61fb42..9ea9e548fb9 100644 --- a/rustutils/rustutils.cmake +++ b/rustutils/rustutils.cmake @@ -39,7 +39,7 @@ foreach(rs_file ${RUSTUTILS_RS_FILES}) endforeach() add_custom_command( - OUTPUT ${RUSTUTILS_OUTPUT_DIR} + OUTPUT ${RUSTUTILS_GENERATED_SOURCES} ${RUSTUTILS_GENERATED_HEADERS} COMMAND ${CMAKE_COMMAND} -E env ${CMAKE_CURRENT_LIST_DIR}/generate.sh ${RUSTUTILS_OUTPUT_DIR} ${RUSTUTILS_RS_FILES} DEPENDS ${CMAKE_CURRENT_LIST_DIR}/generate.sh ${RUSTUTILS_RS_FILES} From 4228b6e349a911ee79f7ef107a920b09a827ddc3 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Tue, 14 Jan 2025 19:23:39 +0100 Subject: [PATCH 48/56] improve linux-ci --- .github/workflows/linux-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linux-ci.yml b/.github/workflows/linux-ci.yml index 220c4e945a5..8c52454a0f4 100644 --- a/.github/workflows/linux-ci.yml +++ b/.github/workflows/linux-ci.yml @@ -93,7 +93,7 @@ jobs: - if: matrix.renderer == 'drawable-rust' run: | - echo renderer_flag_cmake=-DMLN_DRAWABLE_RENDERER=ON MLN_WITH_RUST=ON >> "$GITHUB_ENV" + echo "renderer_flag_cmake=-DMLN_DRAWABLE_RENDERER=ON MLN_WITH_RUST=ON" >> "$GITHUB_ENV" cargo install cxxbridge-cmd - if: matrix.renderer == 'legacy' From 2f608a6514d9a93a3594cc180fa426a1861a9d7d Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Tue, 14 Jan 2025 20:29:14 +0100 Subject: [PATCH 49/56] use cargo fmt --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fba750866e7..25392ab37d5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: hooks: - id: rustfmt name: rustfmt - entry: rustfmt --edition 2021 + entry: bash -c 'cd rustutils && cargo fmt' -- language: rust types: [rust] ci: From 991f1e1c549e2bb9ed60acd8ec3b7e5faebcdd19 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Tue, 14 Jan 2025 20:29:27 +0100 Subject: [PATCH 50/56] add newlines --- rustutils/generate.sh | 2 +- rustutils/rustutils.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rustutils/generate.sh b/rustutils/generate.sh index 37aeb2a9578..679464156a5 100755 --- a/rustutils/generate.sh +++ b/rustutils/generate.sh @@ -29,4 +29,4 @@ for input_file in "$@"; do base_name=$(basename "$input_file" .rs) cxxbridge "$input_file" --header > "$output_dir/cpp/include/rustutils/${base_name}.hpp" cxxbridge "$input_file" > "$output_dir/cpp/src/${base_name}.rs.cpp" -done \ No newline at end of file +done diff --git a/rustutils/rustutils.cmake b/rustutils/rustutils.cmake index 9ea9e548fb9..94decf5cd03 100644 --- a/rustutils/rustutils.cmake +++ b/rustutils/rustutils.cmake @@ -60,4 +60,4 @@ target_include_directories(mbgl-rustutils PUBLIC ${RUSTUTILS_INCLUDE_DIR} ) -target_link_libraries(mbgl-rustutils PUBLIC rustutils) \ No newline at end of file +target_link_libraries(mbgl-rustutils PUBLIC rustutils) From af5b67b1d012c4686f67ec339b084546b2e2e31f Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Tue, 14 Jan 2025 23:21:07 +0100 Subject: [PATCH 51/56] Fix issue in linux-ci --- .github/workflows/linux-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linux-ci.yml b/.github/workflows/linux-ci.yml index 8c52454a0f4..36305eaac53 100644 --- a/.github/workflows/linux-ci.yml +++ b/.github/workflows/linux-ci.yml @@ -93,7 +93,7 @@ jobs: - if: matrix.renderer == 'drawable-rust' run: | - echo "renderer_flag_cmake=-DMLN_DRAWABLE_RENDERER=ON MLN_WITH_RUST=ON" >> "$GITHUB_ENV" + echo "renderer_flag_cmake=-DMLN_DRAWABLE_RENDERER=ON MLN_USE_RUST=ON" >> "$GITHUB_ENV" cargo install cxxbridge-cmd - if: matrix.renderer == 'legacy' From 6afef70454719124a5c5752d0043d17850792edc Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Wed, 15 Jan 2025 00:36:10 +0100 Subject: [PATCH 52/56] fix typo in linux-ci --- .github/workflows/linux-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linux-ci.yml b/.github/workflows/linux-ci.yml index 36305eaac53..9293f241065 100644 --- a/.github/workflows/linux-ci.yml +++ b/.github/workflows/linux-ci.yml @@ -37,6 +37,7 @@ jobs: - name: Get all Linux files that have changed if: github.event_name != 'workflow_dispatch' id: changed-files + uses: tj-actions/changed-files@v45 with: files_yaml_from_source_file: .github/changed-files.yml @@ -93,7 +94,7 @@ jobs: - if: matrix.renderer == 'drawable-rust' run: | - echo "renderer_flag_cmake=-DMLN_DRAWABLE_RENDERER=ON MLN_USE_RUST=ON" >> "$GITHUB_ENV" + echo "renderer_flag_cmake=-DMLN_DRAWABLE_RENDERER=ON -DMLN_USE_RUST=ON" >> "$GITHUB_ENV" cargo install cxxbridge-cmd - if: matrix.renderer == 'legacy' From 014f2bab80dcc01ea42c7540e046b8b22eb69d3e Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Wed, 15 Jan 2025 21:43:01 +0100 Subject: [PATCH 53/56] Fix color.rs.cpp impl, add test --- src/mbgl/util/color.cpp | 2 +- src/mbgl/util/color.rs.cpp | 5 +++-- test/util/color.test.cpp | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/mbgl/util/color.cpp b/src/mbgl/util/color.cpp index 44fb65f732a..cd4258aa44a 100644 --- a/src/mbgl/util/color.cpp +++ b/src/mbgl/util/color.cpp @@ -6,7 +6,7 @@ namespace mbgl { std::optional Color::parse(const std::string& s) { - auto css_color = CSSColorParser::parse(s); + const auto css_color = CSSColorParser::parse(s); // Premultiply the color. if (css_color) { diff --git a/src/mbgl/util/color.rs.cpp b/src/mbgl/util/color.rs.cpp index 98a6028bad8..62a561a7350 100644 --- a/src/mbgl/util/color.rs.cpp +++ b/src/mbgl/util/color.rs.cpp @@ -10,9 +10,10 @@ namespace mbgl { std::optional Color::parse(const std::string& s) { - auto css_color = rustutils::parse_css_color(s); + const auto css_color = rustutils::parse_css_color(s); if (css_color.success) { - return {{css_color.r, css_color.g, css_color.b, css_color.a}}; + const float factor = css_color.a / 255; + return {{css_color.r * factor, css_color.g * factor, css_color.b * factor, css_color.a}}; } else { return {}; } diff --git a/test/util/color.test.cpp b/test/util/color.test.cpp index dd3f67df8ba..ef217ec3389 100644 --- a/test/util/color.test.cpp +++ b/test/util/color.test.cpp @@ -25,6 +25,7 @@ const std::map> testCases = { {"#123", Color(0.067f, 0.133f, 0.2f, 1.0f)}, // Short hex format {"rgb(-10, 0, 0)", Color(0.0f, 0.0f, 0.0f, 1.0f)}, // Clamped to 0 {"rgba(300, 0, 0, 1.0)", Color(1.0f, 0.0f, 0.0f, 1.0f)}, // Clamped to 1 + {"rgba(100,100,100,0.2)", Color(20.0f / 255, 20.0f / 255, 20.0f / 255, 0.2f)}, // {"#GGGGGG", Color(0.0f, 0.0f, 0.0f, 1.0f)}, // Treated as fallback black // not supported right now // {"#0F0F", Color(0.0f, 1.0f, 0.0f, 1.0f)}, From 04091e015595b90d5257e5b8f8c1677b1ee93401 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Thu, 16 Jan 2025 02:54:14 +0100 Subject: [PATCH 54/56] fix factor premultiplication --- src/mbgl/util/color.rs.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mbgl/util/color.rs.cpp b/src/mbgl/util/color.rs.cpp index 62a561a7350..4dd537015b7 100644 --- a/src/mbgl/util/color.rs.cpp +++ b/src/mbgl/util/color.rs.cpp @@ -12,8 +12,7 @@ namespace mbgl { std::optional Color::parse(const std::string& s) { const auto css_color = rustutils::parse_css_color(s); if (css_color.success) { - const float factor = css_color.a / 255; - return {{css_color.r * factor, css_color.g * factor, css_color.b * factor, css_color.a}}; + return {{css_color.r * css_color.a, css_color.g * css_color.a, css_color.b * css_color.a, css_color.a}}; } else { return {}; } From e671d2321d5ecb6978ea182f34f53e25a02015a8 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Thu, 16 Jan 2025 12:55:52 +0100 Subject: [PATCH 55/56] Add Rust toolchains for iOS, build cxxbridge with Bazel --- MODULE.bazel | 7 +++++++ rustutils/BUILD.bazel | 4 +++- rustutils/generate.sh | 9 ++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 61aade0fd07..e71dc40ae56 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -62,6 +62,12 @@ darwin_config( ) bazel_dep(name = "rules_rust", version = "0.56.0") +bazel_dep(name = "cxx.rs", version = "1.0.136") +git_override( + module_name = "cxx.rs", + commit = "d54e44698c3fa5833a861cb3ae502533b92f2f57", + remote = "https://github.com/dtolnay/cxx.git", +) rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") rust.toolchain( @@ -69,6 +75,7 @@ rust.toolchain( extra_target_triples = [ "aarch64-apple-ios-sim", "x86_64-apple-ios", + "aarch64-apple-ios", "aarch64-apple-darwin", "x86_64-apple-darwin", ], diff --git a/rustutils/BUILD.bazel b/rustutils/BUILD.bazel index 612b1bcef24..0bce0241fd0 100644 --- a/rustutils/BUILD.bazel +++ b/rustutils/BUILD.bazel @@ -10,9 +10,11 @@ genrule( "cpp/include/rustutils/color.hpp", "cpp/src/color.rs.cpp", ], - cmd = "./$(location generate.sh) $(@D) $(SRCS)", + cmd = "CXXBRIDGE_CMD=$(location @cxx.rs//:codegen) ./$(location :generate.sh) $(@D) $(SRCS)", + # Using the cxxbridge binary built by Bazel tools = [ ":generate.sh", + "@cxx.rs//:codegen", ], ) diff --git a/rustutils/generate.sh b/rustutils/generate.sh index 679464156a5..7b0b3c29e0a 100755 --- a/rustutils/generate.sh +++ b/rustutils/generate.sh @@ -12,6 +12,9 @@ if [ "$#" -lt 2 ]; then exit 1 fi +# Use CXXBRIDGE_CMD environment variable if set, otherwise fallback to "cxxbridge" +CXXBRIDGE_CMD="${CXXBRIDGE_CMD:-cxxbridge}" + output_dir="$1" shift @@ -27,6 +30,6 @@ mkdir -p "$output_dir/cpp/src" for input_file in "$@"; do base_name=$(basename "$input_file" .rs) - cxxbridge "$input_file" --header > "$output_dir/cpp/include/rustutils/${base_name}.hpp" - cxxbridge "$input_file" > "$output_dir/cpp/src/${base_name}.rs.cpp" -done + "$CXXBRIDGE_CMD" "$input_file" --header > "$output_dir/cpp/include/rustutils/${base_name}.hpp" + "$CXXBRIDGE_CMD" "$input_file" > "$output_dir/cpp/src/${base_name}.rs.cpp" +done \ No newline at end of file From 22df4ded95dd7fcfe4ad9fb7e34f202eabed6528 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Thu, 16 Jan 2025 14:02:38 +0100 Subject: [PATCH 56/56] fix rustutils/BUILD.bazel --- .bazelversion | 2 +- rustutils/BUILD.bazel | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.bazelversion b/.bazelversion index 643916c03f1..ae9a76b9249 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -7.3.1 +8.0.0 diff --git a/rustutils/BUILD.bazel b/rustutils/BUILD.bazel index 0bce0241fd0..9c8480dcdd5 100644 --- a/rustutils/BUILD.bazel +++ b/rustutils/BUILD.bazel @@ -1,4 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") load("@rules_rust//rust:defs.bzl", "rust_static_library") genrule(