Skip to content

Commit

Permalink
Remove common as dependency form tari-features
Browse files Browse the repository at this point in the history
Features is now a frequently used build dep in most our crates. Common
actually also needs to be feature aware during build time. This means
tari-features should have little to no dependencies, and especially none
from our own crates.
  • Loading branch information
brianp committed Apr 17, 2023
1 parent 12a1ef4 commit f475e35
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
4 changes: 1 addition & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ blake2 = "0.9.1"
[dev-dependencies]
tari_test_utils = { path = "../infrastructure/test_utils"}
toml = "0.5.8"

[build-dependencies]
tari_features = { version = "0.50.0-pre.0", path = "./tari_features"}
9 changes: 9 additions & 0 deletions common/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2023 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use tari_features::resolver::build_features;

pub fn main() {
build_features();
// Build as usual
}
5 changes: 3 additions & 2 deletions common/tari_features/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tari_common = { path = "../../common" }
# So you're thinking about adding a dependency here?
# This crate is utilized in the compilation of _most_ of our other crates. You're probably about
# to create a cyclic depedency. Please think hard whether this change is actually required.
26 changes: 13 additions & 13 deletions common/tari_features/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::{fmt::Display, str::FromStr};

use tari_common::configuration::Network;
use std::fmt::Display;

use crate::{Feature, FEATURE_LIST};

Expand All @@ -40,6 +38,17 @@ impl Target {
Target::TestNet => "testnet",
}
}

pub fn from_network_str(value: &str) -> Self {
// The duplication of network names here isn't great but we're being lazy and non-exhaustive
// regarding the endless testnet possibilities. This minor MainNet, StageNet, and NextNet
// duplication allows us to leave the crate dependency free.
match value.to_lowercase().as_str() {
"mainnet" | "stagenet" => Target::MainNet,
"nextnet" => Target::NextNet,
_ => Target::TestNet,
}
}
}

impl Display for Target {
Expand All @@ -64,16 +73,7 @@ pub fn identify_target() -> Target {

pub fn check_envar(envar: &str) -> Option<Target> {
match std::env::var(envar) {
Ok(s) => {
let network =
Network::from_str(s.to_lowercase().as_str()).unwrap_or_else(|_| panic!("Unknown network, {}", s));
match network {
Network::MainNet | Network::StageNet => Some(Target::MainNet),
Network::NextNet => Some(Target::NextNet),
Network::LocalNet | Network::Igor | Network::Esmeralda => Some(Target::TestNet),
Network::Weatherwax | Network::Ridcully | Network::Stibbons | Network::Dibbler => None,
}
},
Ok(s) => Some(Target::from_network_str(s.to_lowercase().as_str())),
_ => None,
}
}
Expand Down

0 comments on commit f475e35

Please sign in to comment.