diff --git a/.github/workflows/bazel_example.yaml b/.github/workflows/bazel_example.yaml deleted file mode 100644 index c6e82dc529b..00000000000 --- a/.github/workflows/bazel_example.yaml +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright © 2024 OTIV B.V. -# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 - -name: Bazel Build -on: - workflow_dispatch: - workflow_call: -jobs: - ci_bazel: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/install-linux-dependencies - - uses: actions/cache@v4 - with: - path: ~/.cache/bazel - key: ${{ runner.os }}-bazel-${{ hashFiles('examples/bazel_build/.bazelversion', 'examples/bazel_build/.bazelrc', 'examples/bazel_build/MODULE.bazel.lock') }} - restore-keys: | - ${{ runner.os }}-bazel- - - - name: update packages - run: sudo apt-get update - - - name: install other system dependencies - run: sudo apt-get -y install pkg-config libssl-dev default-jre pkgconf - - - name: Bazel Build - working-directory: examples/bazel_build - run: bazelisk build --config=ci //... - - - name: Upload bazel-explain build artifact - uses: actions/upload-artifact@v4 - with: - name: bazel-explain-build-run - path: bazel-explain.log diff --git a/.github/workflows/nightly_tests.yaml b/.github/workflows/nightly_tests.yaml index 64c2fa9034a..54aee93b008 100644 --- a/.github/workflows/nightly_tests.yaml +++ b/.github/workflows/nightly_tests.yaml @@ -140,6 +140,3 @@ jobs: - name: Check run: cargo check --target=x86_64-unknown-uefi -p uefi-demo - bazel: - uses: ./.github/workflows/bazel_example.yaml - diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c775e1da8e..208c9b81690 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ All notable changes to this project are documented in this file. ### General - - Improved support for building Slint with Bazel; added an example in `examples/bazel_build`. + - Improved support for building Slint with Bazel. - Expose `PopupWindow` in the accessibility tree. - Fixed support for older android versions (Android 6). - Fixed `Flickable` not scrolling when starting slow (#7152). diff --git a/REUSE.toml b/REUSE.toml index 0da332d1de0..ffd31cf062b 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -231,13 +231,3 @@ path = [ precedence = "aggregate" SPDX-FileCopyrightText = "Copyright © Felgo GmbH " SPDX-License-Identifier = "CC-BY-ND-4.0" - -[[annotations]] -path = [ - "examples/bazel_build/.bazelignore", - "examples/bazel_build/.bazelversion", - "examples/bazel_build/MODULE.bazel.lock", -] -precedence = "aggregate" -SPDX-FileCopyrightText = "Copyright © 2024 OTIV B.V." -SPDX-License-Identifier = "MIT" diff --git a/examples/bazel_build/.bazelignore b/examples/bazel_build/.bazelignore deleted file mode 100644 index afb8b9802a5..00000000000 --- a/examples/bazel_build/.bazelignore +++ /dev/null @@ -1,5 +0,0 @@ -bazel-bin -bazel-otiv3 -bazel-out -bazel-testlogs -target \ No newline at end of file diff --git a/examples/bazel_build/.bazelrc b/examples/bazel_build/.bazelrc deleted file mode 100644 index d8127460716..00000000000 --- a/examples/bazel_build/.bazelrc +++ /dev/null @@ -1,138 +0,0 @@ -# Copyright © 2024 OTIV B.V. -# SPDX-License-Identifier: MIT - -########### -# General # -########### - -# A config file containing Bazel settings -common --enable_bzlmod - -# https://github.com/bazelbuild/bazel/pull/20855 -common --noenable_workspace - -########### -# Caching # -########### - -# Use BLAKE3 as digest function (will be the default in Bazel 8) -startup --digest_function=BLAKE3 - -# Always have Bazel output why it (re)built something, should make debugging builds easier. -# This has a small performance penalty. If builds become slow, we might want to try and turn this off. -common --explain=bazel-explain.log -common --verbose_explanations - -# This adds another folder with a cache specific to this project -# In case some rust source files are not generated, try commenting this out and building again. -common --disk_cache=~/.cache/bazel_disk_cache -build --disk_cache=~/.cache/bazel_disk_cache -fetch --disk_cache=~/.cache/bazel_disk_cache -query --disk_cache=~/.cache/bazel_disk_cache -sync --disk_cache=~/.cache/bazel_disk_cache -test --disk_cache=~/.cache/bazel_disk_cache -# Note that this cache will grow without bound currently. You should -# Periodically run `find "~/.cache/bazel_disk_cache" -type f -atime +30 -delete` -# https://github.com/bazelbuild/bazel/issues/5139 tracks fixing this issue. - -# Compresses remote cache for files larger than 100MB -# NOTE: disk_cache is a local version of remote cache -common:workflows --remote_cache_compression -common:workflows --experimental_remote_cache_compression_threshold=100 - -######### -# Build # -######### - -# Don't use legacy toolchain resolution -common --incompatible_enable_cc_toolchain_resolution -common --incompatible_enable_proto_toolchain_resolution - -# Don't leak PATH and LD_LIBRARY_PATH into the build. -build --incompatible_strict_action_env - -build --sandbox_default_allow_network=true # re-enabled to allow skia-bindings to download -build --heap_dump_on_oom -build --noexperimental_check_output_files - -# Add build annotation for clippy and rustfmt by default. -# build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect -# build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect - -build:nightly --@rules_rust//rust/toolchain/channel=nightly - -################# -# Rust-analyzer # -################# - -run:genra @rules_rust//tools/rust_analyzer:gen_rust_project - -############## -# Formatting # -############## - -# Apply formatting to all files -run:rustfmt @rules_rust//:rustfmt --output_groups=+rustfmt_checks --@rules_rust//:rustfmt.toml=//:rustfmt.toml - -# Check whether formatting has been applied correctly -build:rustfmt --output_groups=+rustfmt_checks --@rules_rust//:rustfmt.toml=//:rustfmt.toml - -########### -# Linting # -########### - -# Causes rustc to emit .rmeta files and use them for rlib -> rlib dependencies -# See https://internals.rust-lang.org/t/evaluating-pipelined-rustc-compilation/10199 -build:check --@rules_rust//rust/settings:pipelined_compilation=True - -# Ignores all outputs other than `.rmeta`, requires pipelined_compilation to be enabled! -build:check --output_groups=build_metadata - -# Linting with Clippy (stricter than build without options) -# This does not work with the option `pipelined_compilation` on all modules -build:clippy --output_groups=+clippy_checks - -# Stricter linting on top of the default checks by Clippy -build:pedantic --config=clippy --@rules_rust//:clippy_flags="-Wclippy::pedantic,-Dclippy::perf,-Dclippy::correctness,-Wclippy::suspicious,-Dclippy::complexity,-Dclippy::style,-Aclippy::missing_errors_doc,-Aclippy::missing_panics_doc,-Aclippy::semicolon_if_nothing_returned" --@rules_rust//:clippy.toml=//:clippy.toml - -# Historical shortcut used in an old version of the script in `./rust_analyzer` -build:lint_file --@rules_rust//:error_format=json --config=clippy --compile_one_dependency - -########## -# Checks # -########## - -# Combination of checks by Clippy and Rustfmt -build:lint --config=rustfmt --config=clippy - -############# -# Debugging # -############# - -build:debug -c dbg - -# Expand macros into a file `expanded.rs` -build:unpretty --aspects=@rules_rust//rust:defs.bzl%rust_unpretty_aspect -build:unpretty --output_groups=+rust_unpretty -build:unpretty --config=nightly - -########### -# Testing # -########### - -test --build_tests_only -test:verbose --test_output=all --test_arg=--nocapture - -######### -# CI/CD # -######### - -common:ci --disk_cache= -common:ci --color=yes -common:ci --build_metadata=ROLE=CI -build:ci --config=lint - -# This import should always be last to allow users to override -# Allow user-side customization -try-import %workspace%/user.bazelrc - diff --git a/examples/bazel_build/.bazelversion b/examples/bazel_build/.bazelversion deleted file mode 100644 index 815da58b7a9..00000000000 --- a/examples/bazel_build/.bazelversion +++ /dev/null @@ -1 +0,0 @@ -7.4.1 diff --git a/examples/bazel_build/.gitignore b/examples/bazel_build/.gitignore deleted file mode 100644 index 45e5849d0a1..00000000000 --- a/examples/bazel_build/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -bazel-bazel_build -bazel-bin -bazel-out -bazel-testlogs diff --git a/examples/bazel_build/BUILD.bazel b/examples/bazel_build/BUILD.bazel deleted file mode 100644 index baf5e776db6..00000000000 --- a/examples/bazel_build/BUILD.bazel +++ /dev/null @@ -1,2 +0,0 @@ -# Copyright © 2024 OTIV B.V. -# SPDX-License-Identifier: MIT diff --git a/examples/bazel_build/MODULE.bazel b/examples/bazel_build/MODULE.bazel deleted file mode 100644 index 0b78076eaee..00000000000 --- a/examples/bazel_build/MODULE.bazel +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright © 2024 OTIV B.V. -# SPDX-License-Identifier: MIT - -module(name = "slint_bazel_example") - -bazel_dep(name = "bazel_skylib", version = "1.7.1") -bazel_dep( - name = "buildifier_prebuilt", - version = "7.3.1", - dev_dependency = True, -) -bazel_dep(name = "rules_rust", version = "0.56.0") -bazel_dep(name = "toolchains_llvm", version = "1.1.2") - -llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm") - -# https://github.com/bazel-contrib/toolchains_llvm/blob/master/toolchain/internal/llvm_distributions.bzl -llvm.toolchain(name = "llvm_toolchain", llvm_versions = {"": "17.0.6"}) -use_repo(llvm, "llvm_toolchain", "llvm_toolchain_llvm") - -rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") -rust.toolchain( - edition = "2021", - versions = ["1.83.0", "nightly/2024-07-20"], - sha256s = { - "2024-07-20/rustc-nightly-x86_64-unknown-linux-gnu.tar.xz": "97750490a01fa797d93eb2ea72c6b02492cc85671ba2ca1c3fa1d1a61968b587", - "2024-07-20/clippy-nightly-x86_64-unknown-linux-gnu.tar.xz": "8ebdd6a56559a11a4863ab23d9a0c8896a2f5759d40bd6869bad857f57b85e55", - "2024-07-20/cargo-nightly-x86_64-unknown-linux-gnu.tar.xz": "3a0ab34fe9a3985b75711fafa0e5e1215904be7e70ab3e432300f7d165e8bf18", - "2024-07-20/llvm-tools-nightly-x86_64-unknown-linux-gnu.tar.xz": "b53be917d6e1f844d5c72b027751985c8c8116851cc980e92f407167aff0c9ad", - "2024-07-20/rust-std-nightly-x86_64-unknown-linux-gnu.tar.xz": "16e059cd736127f1667c1f56de17fadb8a1d31cb4fab6ca64ac11ef4c2864bc2", - }, -) -use_repo(rust, "rust_toolchains") -register_toolchains("@llvm_toolchain//:all") -register_toolchains("@rust_toolchains//:all") - -crate = use_extension( - "@rules_rust//crate_universe:extension.bzl", - "crate", -) - -crate.spec(package = "slint", git = "https://github.com/slint-ui/slint", branch = "master", default_features = False, features = ["std","backend-winit", "renderer-skia-opengl", "compat-1-10"]) -crate.spec(package = "slint-build", git = "https://github.com/slint-ui/slint", branch = "master") - -crate.annotation( - crate = "khronos_api", - patches = ["@//external_crate_builds:0001-Fix-build-with-Bazel.patch"], - patch_args = ["-p1"], -) -crate.annotation( - crate = "proc-macro-crate", - patches = ["@//external_crate_builds:0001-Fix-use-with-Bazel.patch"], - patch_args = ["-p1"], -) -# rav1e uses the built crate, which panics when CARGO_PKG_AUTHORS, etc. are not set. -crate.annotation( - crate = "rav1e", - build_script_env = { - "CARGO_PKG_AUTHORS": "Thomas Daede ", - "CARGO_PKG_DESCRIPTION": "The fastest and safest AV1 encoder", - "CARGO_PKG_HOMEPAGE": "https://github.com/xiph/rav1e/", - "CARGO_PKG_REPOSITORY": "https://github.com/xiph/rav1e/", - "CARGO_PKG_LICENSE": "BSD-2-Clause", - "RUSTDOC": "rustdoc", - }, -) - -CRATES_REPOSITORY_NAME = "crates" -crate.from_specs(name = CRATES_REPOSITORY_NAME) -use_repo(crate, CRATES_REPOSITORY_NAME) diff --git a/examples/bazel_build/README.md b/examples/bazel_build/README.md deleted file mode 100644 index 8af3d27c431..00000000000 --- a/examples/bazel_build/README.md +++ /dev/null @@ -1,22 +0,0 @@ - - -# Slint Bazel Build example - -This shows how to build a trivial slint application in the [bazel build system](https://bazel.build/) - -Requires you to have a bazel toolchain setup. Installation instructions can be found [here](https://bazel.build/install) - -This example has been tested with: -Slint 1.7.0 -Ubuntu 24.04.1 -Bazel 7.2.1 (specified in the file .bazelversion) - -This example currently does NOT use the copy of slint in this repo; it pulls it in from crates.io. - -It also pulls in a mostly hermetic rust toolchain, so expect the build to take considerably longer than the other examples the first time you build. - -To run the example, run the following command from any subdirectory of this directory (examples/bazel_build): - -```bash -bazel run //src:slint_bazel_example -``` diff --git a/examples/bazel_build/external_crate_builds/0001-Fix-build-with-Bazel.patch b/examples/bazel_build/external_crate_builds/0001-Fix-build-with-Bazel.patch deleted file mode 100644 index c2cb7bfb0c3..00000000000 --- a/examples/bazel_build/external_crate_builds/0001-Fix-build-with-Bazel.patch +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright © 2025 SixtyFPS GmbH -# SPDX-License-Identifier: MIT - -# See https://github.com/brendanzab/gl-rs/pull/549 - -From ff5fd1fa0a2416ddff942173d047e95979aa6dfd Mon Sep 17 00:00:00 2001 -From: Simon Hausmann -Date: Sun, 5 Jan 2025 10:43:59 +0100 -Subject: [PATCH] Fix build with Bazel - -When building Rust applications with Bazel instead of cargo, typically a -sandbox is in place, where each process invocation (rustc, build.rs -program, etc.) runs in its own "root", where the view on the filesystem -is the same, but the absolute paths are different. As a consequence, -CARGO_MANIFEST_DIR differs between the invocation of build.rs and rustc. - -That means that absolute paths in the generated webgl_exts.rs don't -work. Fortunately, the source files are relative to the -CARGO_MANIFEST_DIR, which, while changing between invocations, remains -valid. ---- - khronos_api/build.rs | 5 +++-- - 1 file changed, 3 insertions(+), 2 deletions(-) - -diff --git a/khronos_api/build.rs b/khronos_api/build.rs -index 160179b..f7fc439 100644 ---- a/build.rs -+++ b/build.rs -@@ -29,7 +29,8 @@ fn main() { - // The absolute path is needed, because we don't know where the output - // directory will be, and `include_bytes!(..)` resolves paths relative to the - // containing file. -- let root = env::current_dir().unwrap().join("api_webgl/extensions"); -+ let cargo_manifest_dir = PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap()); -+ let root = cargo_manifest_dir.join("api_webgl/extensions"); - - // Generate a slice literal, looking like this: - // `&[&*include_bytes!(..), &*include_bytes!(..), ..]` -@@ -53,7 +54,7 @@ fn main() { - let ext_path = path.join("extension.xml"); - if ext_path.is_file() { - // Include the XML file, making sure to use an absolute path. -- writeln!(file, "&*include_bytes!({:?}),", ext_path.to_str().unwrap()).unwrap(); -+ writeln!(file, "&*include_bytes!(concat!(env!(\"CARGO_MANIFEST_DIR\"), \"/\", {:?})),", ext_path.strip_prefix(cargo_manifest_dir.clone()).unwrap().to_str().unwrap()).unwrap(); - } - } - } --- -2.39.5 (Apple Git-154) - diff --git a/examples/bazel_build/external_crate_builds/0001-Fix-use-with-Bazel.patch b/examples/bazel_build/external_crate_builds/0001-Fix-use-with-Bazel.patch deleted file mode 100644 index e2e2b8a8219..00000000000 --- a/examples/bazel_build/external_crate_builds/0001-Fix-use-with-Bazel.patch +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright © 2025 SixtyFPS GmbH -# SPDX-License-Identifier: MIT - -# See https://github.com/bkchr/proc-macro-crate/pull/55 - -From db99213ae08c7f6cd1dadda60c3b42d16f2c0099 Mon Sep 17 00:00:00 2001 -From: Simon Hausmann -Date: Sun, 5 Jan 2025 10:12:35 +0100 -Subject: [PATCH] Fix use with Bazel - -When the application is built with Bazel as build system, environment -variables like CARGO_MANIFEST_DIR, etc. are set for compatibility, but -CARGO itself isn't, because Bazel is the tool of choice. Therefore any -attempt to invoke Cargo to locate the workspace manifest path fails. - -As a fallback, a lack of the CARGO environment variable now just means -no workspace support. ---- - src/lib.rs | 8 +++++--- - 1 file changed, 5 insertions(+), 3 deletions(-) - -diff --git a/src/lib.rs b/src/lib.rs -index fe46eb3..020d315 100644 ---- a/src/lib.rs -+++ b/src/lib.rs -@@ -100,7 +100,6 @@ use toml_edit::{DocumentMut, Item, Table, TomlError}; - pub enum Error { - NotFound(PathBuf), - CargoManifestDirNotSet, -- CargoEnvVariableNotSet, - FailedGettingWorkspaceManifestPath, - CouldNotRead { path: PathBuf, source: io::Error }, - InvalidToml { source: TomlError }, -@@ -138,7 +137,6 @@ impl fmt::Display for Error { - crate_name, - path.display(), - ), -- Error::CargoEnvVariableNotSet => f.write_str("`CARGO` env variable not set."), - Error::FailedGettingWorkspaceManifestPath => - f.write_str("Failed to get the path of the workspace manifest path."), - } -@@ -241,7 +239,11 @@ pub fn crate_name(orig_name: &str) -> Result { - } - - fn workspace_manifest_path(cargo_toml_manifest: &Path) -> Result, Error> { -- let stdout = Command::new(env::var("CARGO").map_err(|_| Error::CargoEnvVariableNotSet)?) -+ let Ok(cargo) = env::var("CARGO") else { -+ return Ok(None); -+ }; -+ -+ let stdout = Command::new(cargo) - .arg("locate-project") - .args(&["--workspace", "--message-format=plain"]) - .arg(format!("--manifest-path={}", cargo_toml_manifest.display())) --- -2.39.5 (Apple Git-154) - diff --git a/examples/bazel_build/external_crate_builds/BUILD.bazel b/examples/bazel_build/external_crate_builds/BUILD.bazel deleted file mode 100644 index baf5e776db6..00000000000 --- a/examples/bazel_build/external_crate_builds/BUILD.bazel +++ /dev/null @@ -1,2 +0,0 @@ -# Copyright © 2024 OTIV B.V. -# SPDX-License-Identifier: MIT diff --git a/examples/bazel_build/src/BUILD.bazel b/examples/bazel_build/src/BUILD.bazel deleted file mode 100644 index 5138e41691a..00000000000 --- a/examples/bazel_build/src/BUILD.bazel +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright © 2024 OTIV B.V. -# SPDX-License-Identifier: MIT - -load("@rules_rust//cargo:defs.bzl", "cargo_build_script") -load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test") - -cargo_build_script( - name = "ui_builder", - srcs = ["build.rs"], - build_script_env = { - "SLINT_INDEX_FILE_PATH": "$(location slint/index.slint)", - "SLINT_EMIT_DEBUG_INFO": "1", - }, - crate_root = "build.rs", - data = [ - "slint/index.slint", - ], - edition = "2021", - deps = [ - "@crates//:slint-build", - ], -) - -rust_binary( - name = "slint_bazel_example", - srcs = [ - "main.rs", - ], - crate_root = "main.rs", - deps = [ - "@crates//:slint", - ":ui_builder", - "@crates//:slint-build", - ], -) diff --git a/examples/bazel_build/src/build.rs b/examples/bazel_build/src/build.rs deleted file mode 100644 index 35a3a4683cc..00000000000 --- a/examples/bazel_build/src/build.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright © 2024 OTIV B.V. -// SPDX-License-Identifier: MIT - -use std::collections::HashMap; -use std::path::PathBuf; - -fn main() { - let mut library_paths = HashMap::new(); - - slint_build::compile_with_config( - std::env::var_os("SLINT_INDEX_FILE_PATH").unwrap(), - slint_build::CompilerConfiguration::new().with_library_paths(library_paths), - ) - .unwrap(); -} diff --git a/examples/bazel_build/src/main.rs b/examples/bazel_build/src/main.rs deleted file mode 100644 index c5b5819e415..00000000000 --- a/examples/bazel_build/src/main.rs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright © 2024 OTIV B.V. -// SPDX-License-Identifier: MIT - -include!(concat!(env!("OUT_DIR"), "/", "index.rs")); - -use slint::ComponentHandle; - -fn main() { - let main_window = BazelBuildExampleWindow::new().expect("could not create main window"); - main_window.show().expect("could not show main window"); - main_window.run(); -} diff --git a/examples/bazel_build/src/slint/index.slint b/examples/bazel_build/src/slint/index.slint deleted file mode 100644 index 3f999ea05f1..00000000000 --- a/examples/bazel_build/src/slint/index.slint +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright © 2024 OTIV B.V. -// SPDX-License-Identifier: MIT - -export component BazelBuildExampleWindow inherits Window { - background: black; - - Text { - text: "Bazel Build Example"; - font_size: 200px; - color: white; - } -}