Skip to content

Commit

Permalink
Sfaety things
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Jul 23, 2024
1 parent 568d4ed commit 458a918
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 142 deletions.
15 changes: 13 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,16 @@
check:
cargo hack --each-feature --exclude-all-features clippy --manifest-path rubicon/Cargo.toml

test:
SOPRINTLN=1 cargo run --manifest-path test-crates/bin/Cargo.toml
test *args:
#!/usr/bin/env bash -eux
BIN_CHANNEL="${BIN_CHANNEL:-stable}"
BIN_FLAGS="${BIN_FLAGS:-}"
SOPRINTLN=1 cargo "+${BIN_CHANNEL}" build --manifest-path test-crates/bin/Cargo.toml "${BIN_FLAGS}"

export DYLD_LIBRARY_PATH=$(rustc "+stable" --print sysroot)/lib
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$(rustc "+nightly" --print sysroot)/lib
export LD_LIBRARY_PATH=$(rustc "+stable" --print sysroot)/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(rustc "+nightly" --print sysroot)/lib

./test-crates/bin/target/debug/bin {{args}}
7 changes: 7 additions & 0 deletions rubicon/Cargo.lock

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

3 changes: 2 additions & 1 deletion rubicon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ crate-type = ["dylib"]

[dependencies]
ctor = { version = "0.2.8", optional = true }
libc = { version = "0.2.155", optional = true }
paste = { version = "1.0.15", optional = true }

[build-dependencies]
Expand All @@ -23,5 +24,5 @@ rustc_version = { version = "0.4.0", optional = true }
[features]
default = []
export-globals = ["dep:paste", "dep:rustc_version"]
import-globals = ["dep:paste", "dep:rustc_version", "dep:ctor"]
import-globals = ["dep:paste", "dep:rustc_version", "dep:ctor", "dep:libc"]
ctor = ["dep:ctor"]
306 changes: 179 additions & 127 deletions rubicon/src/lib.rs

Large diffs are not rendered by default.

82 changes: 74 additions & 8 deletions test-crates/bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,64 @@ use exports::{self as _, mokio};
use soprintln::soprintln;

fn main() {
struct ModuleSpec {
name: &'static str,
channel: String,
features: Vec<String>,
}

let mut modules = [
ModuleSpec {
name: "mod_a",
channel: "stable".to_string(),
features: Default::default(),
},
ModuleSpec {
name: "mod_b",
channel: "stable".to_string(),
features: Default::default(),
},
];

for arg in std::env::args().skip(1) {
if let Some(rest) = arg.strip_prefix("--features:") {
let parts: Vec<&str> = rest.splitn(2, '=').collect();
if parts.len() != 2 {
panic!("Invalid argument format: expected --features:module=feature1,feature2");
}
let mod_name = parts[0];
let features = parts[1].split(',').map(|s| s.to_owned());
let module = modules
.iter_mut()
.find(|m| m.name == mod_name)
.unwrap_or_else(|| panic!("Unknown module: {}", mod_name));

for feature in features {
module.features.push(feature);
}
} else if let Some(rest) = arg.strip_prefix("--channel:") {
let parts: Vec<&str> = rest.splitn(2, '=').collect();
if parts.len() != 2 {
panic!("Invalid argument format: expected --channel:module=(stable|nightly)");
}
let mod_name = parts[0];
let channel = parts[1];
if channel != "stable" && channel != "nightly" {
panic!(
"Invalid channel: {}. Expected 'stable' or 'nightly'",
channel
);
}
let module = modules
.iter_mut()
.find(|m| m.name == mod_name)
.unwrap_or_else(|| panic!("Unknown module: {}", mod_name));
module.channel = channel.to_string();
} else {
panic!("Unknown argument: {}", arg);
}
}

soprintln::init!();
let exe_path = std::env::current_exe().expect("Failed to get current exe path");
let project_root = exe_path
Expand All @@ -17,9 +75,12 @@ fn main() {

soprintln!("app starting up...");

let modules = ["../mod_a", "../mod_b"];
for module in modules {
soprintln!("building {module}");
soprintln!(
"building {} with features {:?}",
module.name,
module.features.join(", ")
);

cfg_if::cfg_if! {
if #[cfg(target_os = "macos")] {
Expand All @@ -31,19 +92,24 @@ fn main() {
}
}

let output = std::process::Command::new("cargo")
.arg("b")
let mut cmd = std::process::Command::new("cargo");
cmd.arg(format!("+{}", module.channel))
.arg("build")
.env("RUSTFLAGS", rustflags)
.current_dir(module)
.output()
.expect("Failed to execute cargo build");
.current_dir(format!("../{}", module.name));
if !module.features.is_empty() {
cmd.arg("--features").arg(module.features.join(","));
}

let output = cmd.output().expect("Failed to execute cargo build");

if !output.status.success() {
eprintln!(
"Error building {}: {}",
module,
module.name,
String::from_utf8_lossy(&output.stderr)
);
std::process::exit(1);
}
}

Expand Down
3 changes: 3 additions & 0 deletions test-crates/exports/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ crate-type = ["dylib"]

[dependencies]
mokio = { version = "0.1.0", path = "../mokio", features = ["export-globals"] }

[features]
mokio-timer = ["mokio/timer"]
7 changes: 7 additions & 0 deletions test-crates/mod_a/Cargo.lock

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

5 changes: 1 addition & 4 deletions test-crates/mod_a/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
mokio = { version = "0.1.0", path = "../mokio", features = [
"import-globals",
"timer",
] }
mokio = { version = "0.1.0", path = "../mokio", features = ["import-globals"] }
rubicon = { path = "../../rubicon" }
soprintln = { version = "3.0.0", features = ["print"] }
7 changes: 7 additions & 0 deletions test-crates/mod_b/Cargo.lock

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

0 comments on commit 458a918

Please sign in to comment.