Skip to content

Commit

Permalink
stormlicht: use features instead of cfg to select chromes
Browse files Browse the repository at this point in the history
Technically features are supposed to be additive, which the
chrome selection is not. However, the interaction between
cfg parameters and cargo is so incredibly annoying that
its better to just use them anyways.

Fixes #21
  • Loading branch information
simonwuelker committed Aug 10, 2024
1 parent 17b171c commit fa3f0cf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
9 changes: 4 additions & 5 deletions python/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@ def run_stormlicht(args, unknown_args):
if not args.no_backtrace:
environment["RUST_BACKTRACE"] = "1"

environment["RUSTFLAGS"] = (
environment.get("RUSTFLAGS", "") + f'--cfg chrome="{args.chrome}"'
)

if args.miri:
arguments = ["miri", "run"]
else:
arguments = ["run"]

if args.chrome == "glazier":
arguments += ["--no-default-features", "--features=chrome-glazier"]

cmd = (
util.Command.create("cargo")
Expand Down Expand Up @@ -167,7 +166,7 @@ def run():
parser_run.add_argument(
"--chrome",
choices=["glazier", "gtk"],
default="glazier",
default="gtk",
help="Which browser chrome to use",
)
parser_run.set_defaults(handler=run_stormlicht)
Expand Down
24 changes: 16 additions & 8 deletions stormlicht/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,24 @@ image = { workspace = true }
sl-std = { workspace = true }
settings = { workspace = true }

[target.'cfg(chrome = "glazier")'.dependencies]
glazier = { git = "https://github.com/linebender/glazier" }
softbuffer = { version = "0.2" }
# Glazier-only dependencies
glazier = { git = "https://github.com/linebender/glazier", optional = true }
softbuffer = { version = "0.2", optional = true }

[target.'cfg(chrome = "gtk")'.dependencies]
gtk = { package = "gtk4", version = "0.8", features = ["v4_10"] }
adw = { version = "0.6", package = "libadwaita" }
# GTK-only dependencies
gtk = { package = "gtk4", version = "0.8", features = [
"v4_10",
], optional = true }
adw = { version = "0.6", package = "libadwaita", optional = true }

[target.'cfg(chrome = "gtk")'.build-dependencies]
glib-build-tools = "0.18.0"
[features]
default = ["chrome-gtk"]
chrome-gtk = ["dep:gtk", "dep:adw", "dep:glib-build-tools"]
chrome-glazier = ["dep:glazier", "dep:softbuffer"]


[build-dependencies]
glib-build-tools = { version = "0.18.0", optional = true }

[lints]
workspace = true
4 changes: 2 additions & 2 deletions stormlicht/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn main() {

get_environment_info();

#[cfg(chrome = "gtk")]
#[cfg(feature = "chrome-gtk")]
compile_glib_resources();
}

Expand All @@ -28,7 +28,7 @@ fn get_environment_info() {
);
}

#[cfg(chrome = "gtk")]
#[cfg(feature = "chrome-gtk")]
fn compile_glib_resources() {
glib_build_tools::compile_resources(
&["resources"],
Expand Down
4 changes: 2 additions & 2 deletions stormlicht/src/chrome/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cfg_match! {
cfg(chrome = "glazier") => {
cfg(feature = "chrome-glazier") => {
mod glazier;
pub use glazier::run;
}
cfg(chrome = "gtk") => {
cfg(feature = "chrome-gtk") => {
mod gtk;
pub use gtk::run;
}
Expand Down

0 comments on commit fa3f0cf

Please sign in to comment.