Skip to content

Commit

Permalink
Add compatibility feature to our public crates
Browse files Browse the repository at this point in the history
We want to be able to put existing functionality behind a feature flag while keeping
the semver compatibility.
This is only possible if that new feature flag is enabled by default, but this is not
working if the users have done `default-features = false` in their Cargo.toml.
So we add new `compat-x-y-z` feature that is mandatory to have and which is
enforced with a `compile_error!`

Now, users that whishes to not have the default features must enable it explicitly.
Say we want only x11 but not qt and wayland, the user will do
```toml
sixtyfps = { version = "0.2", default-features = false, features = ["x11", "compat-0-2-0"] }
```

Now, imagine that in the version 0.2.3, we put the SVG support behind a feature flag.
we will do this in out Cargo.toml:

```toml
[features]
default = ["compat-0-2-0", "x11", "wayland"]
compat-0-2-0 = ["compat-0-2-3", "svg"]
compat-0-2-3 = []

svg = [...]
...
```

That way, the svg feature will be enabled by default for all the users who used previous version
of SixtyFPS, and people that want to disable "svg" can just change from compat-0-2-0 to
compat-0-2-3 in their Cargo.toml
  • Loading branch information
ogoffart committed Jan 31, 2022
1 parent 8762582 commit 38d7ac4
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/sixtyfps-cpp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ default = ["backend-gl", "x11", "backend-qt"]

[dependencies]
sixtyfps-corelib = { version = "=0.2.0", path="../../internal/core", features = ["ffi"] }
sixtyfps-interpreter = { version = "=0.2.0", path="../../internal/interpreter", default-features = false, features = ["ffi"], optional = true }
sixtyfps-interpreter = { version = "=0.2.0", path="../../internal/interpreter", default-features = false, features = ["ffi", "compat-0-2-0"], optional = true }
sixtyfps-rendering-backend-selector = { version = "=0.2.0", path="../../internal/backends/selector" }
sixtyfps-rendering-backend-testing = { version = "=0.2.0", path="../../internal/backends/testing", optional = true }

Expand Down
8 changes: 7 additions & 1 deletion api/sixtyfps-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ path = "lib.rs"

[features]

default = ["backend-gl", "x11", "backend-qt"]
default = ["std", "backend-gl", "x11", "backend-qt", "compat-0-2-0"]

## Mandatory feature:
## This feature is required to keep the compatibility with SixtyFPS 0.2.0
## Newer patch version may put current functionality behind a new feature
## that would be enabled by default only if this feature was added
compat-0-2-0 = []

## Enable use of the Rust standard library.
std = ["sixtyfps-corelib/std"]
Expand Down
8 changes: 8 additions & 0 deletions api/sixtyfps-rs/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,15 @@ See the [documentation of the `Global` trait](Global) for an example.
#![deny(unsafe_code)]
#![doc(html_logo_url = "https://sixtyfps.io/resources/logo.drawio.svg")]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

#[cfg(not(feature = "compat-0-2-0"))]
compile_error!(
"The feature `compat-0-2-0` must be enabled to ensure \
forward compatibility with future version of this crate"
);

pub use sixtyfps_macros::sixtyfps;

pub use sixtyfps_corelib::api::*;
Expand Down
3 changes: 3 additions & 0 deletions api/sixtyfps-rs/sixtyfps-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ homepage = "https://sixtyfps.io"
[lib]
path = "lib.rs"

[features]
default = []

[dependencies]
sixtyfps-compilerlib = { version = "=0.2.0", path = "../../../internal/compiler", features = ["rust", "display-diagnostics"] }

Expand Down
6 changes: 6 additions & 0 deletions api/sixtyfps-rs/sixtyfps-build/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ fn main() {
#![doc(html_logo_url = "https://sixtyfps.io/resources/logo.drawio.svg")]
#![warn(missing_docs)]

#[cfg(not(feature = "default"))]
compile_error!(
"The feature `default` must be enabled to ensure \
forward compatibility with future version of this crate"
);

use std::env;
use std::io::Write;
use std::path::Path;
Expand Down
8 changes: 7 additions & 1 deletion internal/interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ path = "lib.rs"

[features]

default = ["backend-gl", "x11", "backend-qt"]
default = ["std", "backend-gl", "x11", "backend-qt", "compat-0-2-0"]

## Mandatory feature:
## This feature is required to keep the compatibility with SixtyFPS 0.2.0
## Newer patch version may put current functionality behind a new feature
## that would be enabled by default only if this feature was added
compat-0-2-0 = []

## enable the [`print_diagnostics`] function to show diagnostic in the console output
display-diagnostics = ["sixtyfps-compilerlib/display-diagnostics"]
Expand Down
6 changes: 6 additions & 0 deletions internal/interpreter/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ instance.run();
#![warn(missing_docs)]
#![doc(html_logo_url = "https://sixtyfps.io/resources/logo.drawio.svg")]

#[cfg(not(feature = "compat-0-2-0"))]
compile_error!(
"The feature `compat-0-2-0` must be enabled to ensure \
forward compatibility with future version of this crate"
);

mod api;
mod dynamic_component;
mod dynamic_type;
Expand Down
2 changes: 1 addition & 1 deletion tests/driver/interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ path = "main.rs"
name = "test-driver-interpreter"

[dev-dependencies]
sixtyfps-interpreter = { path = "../../../internal/interpreter", default-features = false, features = ["display-diagnostics"] }
sixtyfps-interpreter = { path = "../../../internal/interpreter", default-features = false, features = ["display-diagnostics", "compat-0-2-0"] }
sixtyfps-rendering-backend-testing = { path = "../../../internal/backends/testing" }

itertools = "0.10"
Expand Down
2 changes: 1 addition & 1 deletion tools/lsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ default = ["sixtyfps-backend-qt", "sixtyfps-backend-gl", "x11"]
[dependencies]
sixtyfps-compilerlib = { version = "=0.2.0", path = "../../internal/compiler"}
sixtyfps-corelib = { version = "=0.2.0", path = "../../internal/core"}
sixtyfps-interpreter = { version = "=0.2.0", path = "../../internal/interpreter", default-features = false }
sixtyfps-interpreter = { version = "=0.2.0", path = "../../internal/interpreter", default-features = false, features = ["compat-0-2-0"] }
sixtyfps-rendering-backend-selector = { version = "=0.2.0", path="../../internal/backends/selector" }

clap = { version = "3.0.5", features=["derive", "wrap_help"] }
Expand Down
2 changes: 1 addition & 1 deletion tools/viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ default = ["sixtyfps-backend-qt", "sixtyfps-backend-gl", "x11"]

[dependencies]
sixtyfps-corelib = { version = "=0.2.0", path="../../internal/core" }
sixtyfps-interpreter = { version = "=0.2.0", path = "../../internal/interpreter", default-features = false, features = ["display-diagnostics"] }
sixtyfps-interpreter = { version = "=0.2.0", path = "../../internal/interpreter", default-features = false, features = ["display-diagnostics", "compat-0-2-0"] }
sixtyfps-rendering-backend-selector = { version = "=0.2.0", path="../../internal/backends/selector" }

vtable = { version = "0.1", path="../../helper_crates/vtable" }
Expand Down

0 comments on commit 38d7ac4

Please sign in to comment.