Split most of the masonry crate into masonry_core sub-crate. (#910)

This change is done very carefully to minimize the number of changed
files, and use almost only file renames.
This is both for avoiding merge conflicts, keeping file history
unbroken, and keeping the PR easy to review.

A future PR will rename masonry to masonry_core, masonry_winit to
masonry change all the doc tests and snapshots that depend on those
names, etc.

After *that*, future PRs will have actual code changes splitting winit
away from masonry_core.
This commit is contained in:
Olivier FAURE 2025-03-26 13:00:46 +01:00 committed by GitHub
parent fadea88afa
commit 6fe84201b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
237 changed files with 424 additions and 62 deletions

5
.gitattributes vendored
View File

@ -1,3 +1,4 @@
# LFS settings
# If changing, also change in .github/workflows/ci.yml
masonry/**/screenshots/*.png filter=lfs diff=lfs merge=lfs -text
# If changed, also change in .github/workflows/ci.yml
# We assume that any PNG file in a folder named "screenshots/" is a screenshot test output.
**/screenshots/*.png filter=lfs diff=lfs merge=lfs -text

View File

@ -10,14 +10,13 @@ env:
# plus all the README.md files of the affected packages.
RUST_MIN_VER: "1.85"
# List of packages that can not target Wasm.
NO_WASM_PKGS: "--exclude masonry --exclude xilem"
NO_WASM_PKGS: "--exclude masonry --exclude masonry_winit --exclude xilem"
# Only some of our examples support Android (primarily due to extra required boilerplate).
ANDROID_TARGETS: "-p xilem --example mason_android --example calc_android --example stopwatch_android --example variable_clock_android --example http_cats_android --example to_do_mvc_android"
# Whether the workspace contains Rust code using the debug_assertions configuration option.
USING_DEBUG_ASSERTIONS: "true"
# The files stored in LFS the tests need to access
# This should mirror the values in .gitattributes
LFS_FILES: "masonry/**/screenshots/*.png"
LFS_FILES: "**/screenshots/*.png"
# Rationale
@ -109,6 +108,9 @@ jobs:
- name: Run cargo rdme (masonry)
run: cargo rdme --check --heading-base-level=0 --workspace-project=masonry
- name: Run cargo rdme (masonry_winit)
run: cargo rdme --check --heading-base-level=0 --workspace-project=masonry_winit
- name: Run cargo rdme (tree_arena)
run: cargo rdme --check --heading-base-level=0 --workspace-project=tree_arena

View File

@ -28,7 +28,7 @@ seeked = "seeked" # Part of the HTML standard
# Include .github, .cargo, etc.
ignore-hidden = false
extend-exclude = [
"masonry/resources/i18n",
"masonry_core/resources/i18n",
# /.git isn't in .gitignore, because git never tracks it.
# Typos doesn't know that, though.
"/.git",

View File

@ -87,3 +87,14 @@ An implementation of Xilem running on the DOM.
### `masonry/`
See `ARCHITECTURE.md` file located under `crates/masonry/doc`
## Screenshot tests
Multiple crates in this repository use screenshot tests to ensure the UI renders as expected.
Screenshots are all saved as PNG files in `screenshots/` folders at different places in the repo.
Because of this, we assume that any file matching `**/screenshots/*.png` is a saved screenshot.
The screenshots are stored using git LFS, which adds some minor complications but avoids the overhead of committing files directly to Git.
In theory, using LFS gives us a stronger dependency on Github.
In practice, the screenshots can be re-generated at any point by running the test suite, and they're guaranteed to be valid since only commits passing the test suite are merged.

35
Cargo.lock generated
View File

@ -1966,6 +1966,41 @@ dependencies = [
"winit",
]
[[package]]
name = "masonry_winit"
version = "0.2.0"
dependencies = [
"accesskit",
"accesskit_winit",
"anymap3",
"assert_matches",
"cursor-icon",
"dpi",
"float-cmp",
"futures-intrusive",
"image",
"insta",
"keyboard-types",
"masonry",
"once_cell",
"parley",
"pollster",
"profiling",
"serde",
"serde_json",
"smallvec",
"time",
"tracing",
"tracing-subscriber",
"tracing_android_trace",
"tree_arena",
"vello",
"web-time",
"wgpu",
"wgpu-profiler",
"winit",
]
[[package]]
name = "matchers"
version = "0.1.0"

View File

@ -4,6 +4,7 @@ members = [
"xilem",
"xilem_core",
"masonry",
"masonry_core",
"xilem_web",
"xilem_web/web_examples/counter",
@ -84,7 +85,7 @@ clippy.wildcard_dependencies = "warn"
# END LINEBENDER LINT SET
[workspace.dependencies]
masonry = { version = "0.2.0", path = "masonry" }
masonry = { version = "0.2.0", path = "masonry_core" }
xilem_core = { version = "0.1.0", path = "xilem_core" }
tree_arena = { version = "0.1.0", path = "tree_arena" }
vello = "0.4.0"

View File

@ -1,5 +1,5 @@
[package]
name = "masonry"
name = "masonry_winit"
version = "0.2.0"
description = "Data-oriented Rust UI design toolkit."
keywords = ["gui", "ui", "toolkit"]
@ -21,20 +21,14 @@ cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
[features]
default = []
# Enables tracing using tracy if the default Masonry tracing is used.
# https://github.com/wolfpld/tracy can be connected to when this feature is enabled.
tracy = [
"tracing-tracy/enable",
"dep:tracing-tracy",
"dep:wgpu-profiler",
"wgpu-profiler/tracy",
"vello/wgpu-profiler",
]
tracy = ["masonry/tracy"]
[lints]
workspace = true
[dependencies]
# TODO - Rename this dependency to masonry_core
masonry.workspace = true
vello.workspace = true
wgpu.workspace = true
parley.workspace = true
@ -54,11 +48,9 @@ accesskit_winit.workspace = true
time = { workspace = true, features = ["macros", "formatting"] }
cursor-icon = "1.1.0"
dpi.workspace = true
tracing-tracy = { version = "0.11.3", optional = true }
wgpu-profiler = { optional = true, version = "0.19.0", default-features = false }
anymap3 = "1.0.1"
keyboard-types = "0.7.0"
oxipng = { version = "9.1.4", default-features = false }
[target.'cfg(target_arch = "wasm32")'.dependencies]
web-time.workspace = true

View File

@ -100,7 +100,7 @@ fn main() {
}
```
For more information, see [the documentation module](https://docs.rs/masonry/latest/masonry/doc/).
For more information, see [the documentation module](masonry::doc).
### Crate feature flags

View File

@ -1,4 +1,4 @@
// Copyright 2018 the Xilem Authors and the Druid Authors
// Copyright 2025 the Xilem Authors
// SPDX-License-Identifier: Apache-2.0
//! Masonry gives you a platform to create windows (using [winit] as a backend) each with a tree of widgets. It also gives you tools to inspect that widget tree at runtime, write unit tests on it, and generally have an easier time debugging and maintaining your app.
@ -78,7 +78,7 @@
//! }
//! ```
//!
//! For more information, see [the documentation module](crate::doc).
//! For more information, see [the documentation module](masonry::doc).
//!
//! ### Crate feature flags
//!
@ -117,47 +117,15 @@
reason = "False-positive with dev-dependencies only used in examples"
)
)]
#![expect(clippy::allow_attributes_without_reason, reason = "Deferred: Noisy")]
// TODO: Remove any items listed as "Deferred"
#![cfg_attr(
not(test),
expect(
unused_crate_dependencies,
reason = "TODO - Remove masonry_core dependencies from masonry_winit"
)
)]
#![expect(clippy::needless_doctest_main, reason = "Deferred: Noisy")]
#![expect(clippy::should_implement_trait, reason = "Deferred: Noisy")]
#![cfg_attr(not(debug_assertions), expect(unused, reason = "Deferred: Noisy"))]
#![expect(missing_debug_implementations, reason = "Deferred: Noisy")]
#![expect(clippy::cast_possible_truncation, reason = "Deferred: Noisy")]
#![expect(clippy::missing_assert_message, reason = "Deferred: Noisy")]
#![expect(elided_lifetimes_in_paths, reason = "Deferred: Noisy")]
#![expect(unreachable_pub, reason = "Potentially controversial code style")]
#![expect(
unnameable_types,
reason = "Requires lint_reasons rustc feature for exceptions"
)]
#![expect(clippy::todo, reason = "We have a lot of 'real' todos")]
#![expect(
clippy::shadow_unrelated,
reason = "Potentially controversial code style"
)]
#![expect(clippy::single_match, reason = "General policy not decided")]
// TODO - Add logo
#[macro_use]
pub mod util;
#[cfg(doc)]
pub mod doc;
mod passes;
pub mod app;
pub mod core;
pub mod properties;
pub mod testing;
pub mod theme;
pub mod widgets;
pub use vello::peniko::color::palette;
pub use vello::{kurbo, peniko};
pub use {cursor_icon, dpi, parley, vello};
// TODO - Move to core?
pub use util::{AsAny, Handled, UnitPoint};
pub use masonry::*;

3
masonry_core/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Visual snapshots
**/screenshots/*.diff.png
**/screenshots/*.new.png

77
masonry_core/Cargo.toml Normal file
View File

@ -0,0 +1,77 @@
[package]
name = "masonry"
version = "0.2.0"
description = "Traits and types of the Masonry toolkit."
keywords = ["gui", "ui", "toolkit"]
categories = ["gui", "internationalization", "accessibility"]
edition.workspace = true
license.workspace = true
repository.workspace = true
homepage.workspace = true
exclude = ["/doc/", ".gitignore"]
rust-version.workspace = true
[package.metadata.docs.rs]
all-features = true
# There are no platform specific docs.
default-target = "x86_64-unknown-linux-gnu"
targets = []
# rustdoc-scrape-examples tracking issue https://github.com/rust-lang/rust/issues/88791
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
[features]
default = []
# Enables tracing using tracy if the default Masonry tracing is used.
# https://github.com/wolfpld/tracy can be connected to when this feature is enabled.
tracy = [
"tracing-tracy/enable",
"dep:tracing-tracy",
"dep:wgpu-profiler",
"wgpu-profiler/tracy",
"vello/wgpu-profiler",
]
[lints]
workspace = true
[dependencies]
vello.workspace = true
wgpu.workspace = true
parley.workspace = true
winit.workspace = true
tree_arena.workspace = true
smallvec.workspace = true
tracing = { workspace = true, features = ["default"] }
image.workspace = true
once_cell = "1.19.0"
serde = { version = "1.0.204", features = ["derive"] }
serde_json = "1.0.120"
futures-intrusive = "0.5.0"
pollster = "0.4.0"
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "time"] }
accesskit.workspace = true
accesskit_winit.workspace = true
time = { workspace = true, features = ["macros", "formatting"] }
cursor-icon = "1.1.0"
dpi.workspace = true
tracing-tracy = { version = "0.11.3", optional = true }
wgpu-profiler = { optional = true, version = "0.19.0", default-features = false }
anymap3 = "1.0.1"
keyboard-types = "0.7.0"
oxipng = { version = "9.1.4", default-features = false }
[target.'cfg(target_arch = "wasm32")'.dependencies]
web-time.workspace = true
[dev-dependencies]
float-cmp = { version = "0.10.0", features = ["std"], default-features = false }
image = { workspace = true, features = ["png"] }
insta = { version = "1.39.0" }
assert_matches = "1.5.0"
# Make wgpu use tracing for its spans.
profiling = { version = "1.0.15", features = ["profile-with-tracing"] }
[target.'cfg(target_os = "android")'.dependencies]
tracing_android_trace = "0.1.0"

4
masonry_core/README.md Normal file
View File

@ -0,0 +1,4 @@
# `masonry_core`
Traits and types of the Masonry toolkit.
See Masonry documentation for more details, examples and resources.

View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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.

66
masonry_core/src/lib.rs Normal file
View File

@ -0,0 +1,66 @@
// Copyright 2018 the Xilem Authors and the Druid Authors
// SPDX-License-Identifier: Apache-2.0
//! Traits and types of the Masonry toolkit.
//! See Masonry documentation for more details, examples and resources.
// LINEBENDER LINT SET - lib.rs - v3
// See https://linebender.org/wiki/canonical-lints/
// These lints shouldn't apply to examples or tests.
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
// These lints shouldn't apply to examples.
#![warn(clippy::print_stdout, clippy::print_stderr)]
// Targeting e.g. 32-bit means structs containing usize can give false positives for 64-bit.
#![cfg_attr(target_pointer_width = "64", warn(clippy::trivially_copy_pass_by_ref))]
// END LINEBENDER LINT SET
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![cfg_attr(
test,
expect(
unused_crate_dependencies,
reason = "False-positive with dev-dependencies only used in examples"
)
)]
#![expect(clippy::allow_attributes_without_reason, reason = "Deferred: Noisy")]
// TODO: Remove any items listed as "Deferred"
#![expect(clippy::should_implement_trait, reason = "Deferred: Noisy")]
#![cfg_attr(not(debug_assertions), expect(unused, reason = "Deferred: Noisy"))]
#![expect(missing_debug_implementations, reason = "Deferred: Noisy")]
#![expect(clippy::cast_possible_truncation, reason = "Deferred: Noisy")]
#![expect(clippy::missing_assert_message, reason = "Deferred: Noisy")]
#![expect(elided_lifetimes_in_paths, reason = "Deferred: Noisy")]
#![expect(unreachable_pub, reason = "Potentially controversial code style")]
#![expect(
unnameable_types,
reason = "Requires lint_reasons rustc feature for exceptions"
)]
#![expect(clippy::todo, reason = "We have a lot of 'real' todos")]
#![expect(
clippy::shadow_unrelated,
reason = "Potentially controversial code style"
)]
#![expect(clippy::single_match, reason = "General policy not decided")]
// TODO - Add logo
#[macro_use]
pub mod util;
// TODO - re-add #[doc(hidden)]
pub mod doc;
mod passes;
pub mod app;
pub mod core;
pub mod properties;
pub mod testing;
pub mod theme;
pub mod widgets;
pub use vello::peniko::color::palette;
pub use vello::{kurbo, peniko};
pub use {cursor_icon, dpi, parley, vello};
// TODO - Move to core?
pub use util::{AsAny, Handled, UnitPoint};

Some files were not shown because too many files have changed in this diff Show More