Skip to content

Commit

Permalink
build: cleanup + add notes about the feature hack
Browse files Browse the repository at this point in the history
rust-lang/cargo#1197 has more information; once rust-lang/cargo#7914 goes stable we can drop this hack.
  • Loading branch information
rrbutani committed Mar 17, 2020
1 parent c796db7 commit eb6290b
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 424 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
members = [
"tui",
]
exclude = ["wrapper-crates"]


[package] # TODO: split into another crate once web becomes a thing
Expand Down
71 changes: 8 additions & 63 deletions tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ lc3-shims = { git = "https://github.com/ut-utp/prototype", branch = "master", ve
lc3-traits = { git = "https://github.com/ut-utp/prototype", branch = "master", version = "0.1.0", default-features = false, features = [] } # Enable std features
# TODO: change all of the above to grab the crates from crates.io instead of git

# tui = { version = "0.8.0", default-features = false }
chrono = "0.4"
crossbeam = "0.7.3"
failure = "0.1.6"
log = "0.4.8"

# Version hack attempt:
# Version hack:
# No crossterm on wasm:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
crossterm = "0.16.0"
Expand All @@ -55,66 +54,8 @@ tui = { version = "0.7.0", default-features = false}
# Once this (https://github.com/rust-lang/cargo/issues/7914) hits stable, we
# won't need this anymore.


# # Source cooperation attempt (i.e. have Cargo pretend they're different crates):
# # (unfortunately this wasn't enough; we needed the wrapper crate too.. *and*, because
# # Cargo is too smart, required us to use a different version of the tui crate so that
# # Cargo would actually allow different features for "web version" of tui and the regular
# # version (that the regular version was behind a transitive dependency did not fool
# # Cargo))
# #
# # Additionally, this required some very not fun gymnastics inside lib.rs since we
# # already have something called tui.
# # No crossterm on wasm:
# [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
# crossterm = "0.16.0"
# # tui-desktop = { version = "0.8.0", package = "tui", default-features = false, features = ["crossterm"] }
# tui-desktop = { version = "0.8.0", package = "utp-tui-crossterm", path = "../wrapper-crates/tui-crossterm" }


# [target.'cfg(target_arch = "wasm32")'.dependencies]
# # tui-web = { version = "0.8.0", package = "tui", default-features = false }
# tui-web = { version = "0.7.0", package = "tui", default-features = false }
# # ^^^^^ awful hack!

# Wrapper crate attempt:
#
# Failed with:
# "Dependency 'tui' has different source paths depending on the build target. Each
# dependency must have a single canonical source path irrespective of build target."
# # No crossterm on wasm:
# [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
# crossterm = "0.16.0"
# tui = { version = "0.8.0", package = "utp-tui-crossterm", path = "../wrapper-crates/tui-crossterm" }

# [target.'cfg(target_arch = "wasm32")'.dependencies]
# tui = { version = "0.8.0", default-features = false }

# [target.]

# # No crossterm on wasm:
# [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
# crossterm = "0.16.0"
# tui = { version = "0.8.0", default-features = false, features = ["crossterm"] }

# # [target.'cfg(not(target_arch = "wasm32"))'.dependencies.tui]
# # features = ["crossterm"]
# # # version = "0.8.0"
# # # default-features = false

# # `tui` without crossterm on wasm:
# [target.'cfg(target_arch = "wasm32")'.dependencies.tui]
# version = "0.8.0"
# default-features = false
# features = []


[dev-dependencies]
pretty_assertions = "0.6.1"


# This needs to exist because we can't seem to conditionally add enable features
# for dependencies; i.e. this doesn't work:
# The above needs to exist because we can't seem to conditionally enable
# features for dependencies; i.e. this doesn't work:
# ```
# [target.'cfg(not(target_arch = "wasm32"))'.dependencies.tui]
# features = ["crossterm"]
Expand All @@ -124,8 +65,12 @@ pretty_assertions = "0.6.1"
# As a workaround we tried to do the below (use a feature to enable the feature
# and have the feature only be enabled on specific architectures), but it also
# does not work. Once this (https://github.com/rust-lang/cargo/issues/7914)
# lands, it will work.
# lands, it will work and we can ditch the above.
# ```
# [target.'cfg(not(target_arch = "wasm32"))'.features]
# default-features = ["tui/crossterm"]
# ```


[dev-dependencies]
pretty_assertions = "0.6.1"
27 changes: 6 additions & 21 deletions tui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,16 @@
#![doc(test(attr(deny(rust_2018_idioms, warnings))))]
#![doc(html_logo_url = "")] // TODO!

// macro_rules! specialize {
// (desktop => { $($d:item)* } web => { $($w:item)* }) => {
// $(
// #[cfg(not(target = "wasm32"))]
// $d
// )*

// $(
// #[cfg(target = "wasm32")]
// $w
// )*
// };
// }

// specialize!{
// desktop => { extern crate tui_desktop as tui; }
// web => { extern crate tui_web as tui; }
// }
macro_rules! specialize {
(desktop => { $($d:item)* } web => { $($w:item)* }) => {
$( #[cfg(not(target = "wasm32"))] $d )*
$( #[cfg(target = "wasm32")] $w )*
};
}

pub mod debug;
pub mod layout;
pub mod widgets;

// mod tui_lib;
// pub use crate::tui_lib::{DynTui, Tui};

mod tui;
pub use crate::tui::{DynTui, Tui};
1 change: 0 additions & 1 deletion wrapper-crates/tui-crossterm/.gitignore

This file was deleted.

Loading

0 comments on commit eb6290b

Please sign in to comment.