Skip to content

Commit

Permalink
Replace more code-initiated builds with justfile commands
Browse files Browse the repository at this point in the history
Change-Id: I7a2bb92900b231ce7c786905dfaf0050b08c8088
  • Loading branch information
jblebrun committed Jul 4, 2024
1 parent 7df2e40 commit d59fcfe
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 125 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

16 changes: 15 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ run_oak_functions_containers_launcher wasm_path port lookup_data_path communicat
--virtio-guest-cid={{virtio_guest_cid}} \
--communication-channel={{communication_channel}}

run_oak_functions_launcher wasm_path port lookup_data_path:
target/x86_64-unknown-linux-gnu/debug/oak_functions_launcher \
--bios-binary=stage0_bin/target/x86_64-unknown-none/release/stage0_bin \
--kernel=oak_restricted_kernel_wrapper/target/x86_64-unknown-none/release/oak_restricted_kernel_wrapper_bin \
--vmm-binary=$(which qemu-system-x86_64) \
--app-binary=enclave_apps/target/x86_64-unknown-none/release/oak_functions_enclave_app \
--initrd=enclave_apps/target/x86_64-unknown-none/release/oak_orchestrator \
--memory-size=256M \
--wasm={{wasm_path}} \
--port={{port}} \
--lookup-data={{lookup_data_path}} \



# Builds a variant of the restricted kernel and creates a bzImage of it.
# Then creates provenance subjects for it.
restricted_kernel_bzimage_and_provenance_subjects kernel_bin_prefix:
Expand Down Expand Up @@ -222,7 +236,7 @@ kokoro_build_binaries_rust: all_enclave_apps oak_restricted_kernel_bin \
kokoro_oak_containers: all_oak_containers_binaries oak_functions_containers_container_bundle_tar
OAK_CONTAINERS_BINARIES_ALREADY_BUILT=1 RUST_LOG="debug" cargo nextest run --all-targets --hide-progress-bar --package='oak_containers_hello_world_untrusted_app'

kokoro_run_tests: all_ensure_no_std all_oak_functions_containers_binaries oak_restricted_kernel_wrapper oak_orchestrator stage0_bin
kokoro_run_tests: all_ensure_no_std all_oak_functions_containers_binaries oak_restricted_kernel_wrapper oak_orchestrator stage0_bin oak_functions_enclave_app
RUST_LOG="debug" cargo nextest run --all-targets --hide-progress-bar --workspace --exclude='oak_containers_hello_world_untrusted_app'

clang-tidy:
Expand Down
1 change: 0 additions & 1 deletion xtask/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ rust_library(
"@oak_crates_index//:tokio",
"@oak_crates_index//:toml",
"@oak_crates_index//:walkdir",
"@oak_crates_index//:which",
],
)

Expand Down
1 change: 0 additions & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ tokio = { version = "*", features = [
] }
toml = "*"
walkdir = "*"
which = "*"
126 changes: 5 additions & 121 deletions xtask/src/launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

pub static MOCK_LOOKUP_DATA_PATH: Lazy<PathBuf> =
Lazy::new(|| workspace_path(&["oak_functions_launcher", "mock_lookup_data"]));
static OAK_FUNCTIONS_LAUNCHER_BIN: Lazy<PathBuf> = Lazy::new(|| {
workspace_path(&["target", "x86_64-unknown-linux-gnu", "debug", "oak_functions_launcher"])
});
pub static OAK_RESTRICTED_KERNEL_WRAPPER_BIN: Lazy<PathBuf> = Lazy::new(|| {
workspace_path(&[
"oak_restricted_kernel_wrapper",
Expand All @@ -31,127 +28,22 @@ pub static OAK_RESTRICTED_KERNEL_WRAPPER_BIN: Lazy<PathBuf> = Lazy::new(|| {
"oak_restricted_kernel_wrapper_bin",
])
});
static OAK_RESTRICTED_KERNEL_ORCHESTRATOR: Lazy<PathBuf> = Lazy::new(|| {
workspace_path(&[
"enclave_apps",
"target",
"x86_64-unknown-none",
"release",
"oak_orchestrator",
])
});

use std::path::{Path, PathBuf};
use std::path::PathBuf;

use once_cell::sync::Lazy;

use crate::{internal::*, workspace_path};

#[derive(Debug, Clone, PartialEq)]
pub struct App {
/// app binary crate name.
crate_name: String,
}

impl App {
pub fn from_crate_name(crate_name: &str) -> Self {
Self { crate_name: crate_name.to_string() }
}

/// Get the crate name of respective enclave binary variant
pub fn enclave_crate_name(&self) -> String {
self.crate_name.clone()
}

/// Get the path to the respective enclave binary variant that should be
/// launched
pub fn enclave_crate_path(&self) -> String {
workspace_path(&["enclave_apps", &self.enclave_crate_name()]).to_str().unwrap().to_string()
}

/// Get the path to the respective enclave binary variant that should be
/// launched
pub fn enclave_binary_path(&self) -> String {
workspace_path(&[
"enclave_apps",
"target",
"x86_64-unknown-none",
"debug",
&self.enclave_crate_name(),
])
.to_str()
.unwrap()
.to_string()
}

/// Get the subcommand for launching in this mode
pub fn subcommand(&self) -> Vec<String> {
vec![
format!("--kernel={}", OAK_RESTRICTED_KERNEL_WRAPPER_BIN.to_str().unwrap()),
format!(
"--vmm-binary={}",
which::which("qemu-system-x86_64").unwrap().to_str().unwrap()
),
"--memory-size=256M".to_string(),
format!("--app-binary={}", &self.enclave_binary_path()),
format!("--initrd={}", OAK_RESTRICTED_KERNEL_ORCHESTRATOR.to_str().unwrap()),
format!(
"--bios-binary={}",
workspace_path(&[
"stage0_bin",
"target",
"x86_64-unknown-none",
"release",
"stage0_bin",
])
.to_str()
.unwrap()
),
]
}
}

pub fn build_binary(name: &str, directory: &str) -> Step {
Step::Single {
name: name.to_string(),
command: Cmd::new_in_dir("cargo", vec!["build"], Path::new(directory)),
}
}

/// Runs the Oak Functions launcher configured with a default Wasm module for
/// key / value lookups and mock lookup data.
pub fn run_oak_functions_launcher_example(
app: &App,
wasm_path: &str,
port: u16,
) -> Box<dyn Runnable> {
run_oak_functions_launcher_example_with_lookup_data(
app,
wasm_path,
port,
MOCK_LOOKUP_DATA_PATH.to_str().unwrap(),
)
}

pub fn run_oak_functions_launcher_example_with_lookup_data(
app: &App,
wasm_path: &str,
port: u16,
lookup_data_path: &str,
) -> Box<dyn Runnable> {
let mut args = vec![
format!("--wasm={}", wasm_path),
format!("--port={}", port),
format!("--lookup-data={}", lookup_data_path),
];
args.append(&mut app.subcommand());
Cmd::new(OAK_FUNCTIONS_LAUNCHER_BIN.to_str().unwrap(), args)
}

pub fn run_launcher(launcher_bin: &str, app: &App) -> Box<dyn Runnable> {
let mut args = vec![];
args.append(&mut app.subcommand());
Cmd::new(launcher_bin, args)
Cmd::new(
"just",
vec!["run_oak_functions_launcher", wasm_path, &format!("{port}"), lookup_data_path],
)
}

/// Runs the specified example as a background task. Returns a reference to the
Expand All @@ -160,21 +52,13 @@ pub async fn run_oak_functions_example_in_background(
wasm_path: &str,
lookup_data_path: &str,
) -> (crate::testing::BackgroundStep, u16) {
let variant = crate::launcher::App::from_crate_name("oak_functions_enclave_app");
crate::testing::run_step(crate::launcher::build_binary(
"build Oak Functions enclave app",
&variant.enclave_crate_path(),
))
.await;

eprintln!("using Wasm module {}", wasm_path);

let port = portpicker::pick_unused_port().expect("failed to pick a port");
eprintln!("using port {}", port);

let background = crate::testing::run_background(
crate::launcher::run_oak_functions_launcher_example_with_lookup_data(
&variant,
wasm_path,
port,
lookup_data_path,
Expand Down

0 comments on commit d59fcfe

Please sign in to comment.