-
Notifications
You must be signed in to change notification settings - Fork 132
tool: add cargo xflowey custom-vmfirmwareigvm-dll
#291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
daprilik
merged 3 commits into
microsoft:main
from
daprilik:user/daprilik/custom-vmfirmwareigvm-dll
Nov 20, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
flowey/flowey_hvlite/src/pipelines/custom_vmfirmwareigvm_dll.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
//! See [`CustomVmfirmwareigvmDllCli`] | ||
|
||
use crate::pipelines_shared::cfg_common_params::CommonArchCli; | ||
use anyhow::Context; | ||
use flowey::node::prelude::ReadVar; | ||
use flowey::pipeline::prelude::*; | ||
use std::path::PathBuf; | ||
|
||
/// Encapsulate an existing pre-built IGVM file into *unsigned* | ||
/// `vmfirmwareigvm.dll` resource DLL. | ||
/// | ||
/// Unlike `build-igvm`, this tool will NOT build OpenHCL from scratch. This | ||
/// tool streamlines the process of building the in-tree `vmfirmwareigvm_dll` | ||
/// crate (which requires setting various env vars, installing certain | ||
/// dependencies, etc...). | ||
/// | ||
/// NOTE: This tool is primarily intended for use by Microsoft employees, as | ||
/// open-source deployments of OpenHCL typically load the IGVM file directly | ||
/// (rather than being encapsulated in a resource-DLL). | ||
#[derive(clap::Args)] | ||
pub struct CustomVmfirmwareigvmDllCli { | ||
/// Path to IGVM payload to encapsulate in the vmfirmwareigvm resource DLL. | ||
pub igvm_payload: PathBuf, | ||
|
||
/// Architecture the DLL should be built for. | ||
/// | ||
/// Defaults to the current host architecture. | ||
#[clap(long)] | ||
pub arch: Option<CommonArchCli>, | ||
} | ||
|
||
impl IntoPipeline for CustomVmfirmwareigvmDllCli { | ||
fn into_pipeline(self, backend_hint: PipelineBackendHint) -> anyhow::Result<Pipeline> { | ||
if !matches!(backend_hint, PipelineBackendHint::Local) { | ||
anyhow::bail!("build-igvm is for local use only") | ||
} | ||
|
||
// DEVNOTE: it would be nice to figure out what sort of magic is | ||
// required for the WSL2 case to work. The tricky part is dealing with | ||
// the underlying invocations to `rc.exe` via WSL2. | ||
if !matches!(FlowPlatform::host(backend_hint), FlowPlatform::Windows) { | ||
anyhow::bail!("custom-vmfirmwareigvm-dll only runs on Windows (WSL2 is NOT supported)") | ||
} | ||
|
||
let CustomVmfirmwareigvmDllCli { arch, igvm_payload } = self; | ||
|
||
let arch = match arch { | ||
Some(arch) => arch, | ||
None => FlowArch::host(backend_hint).try_into()?, | ||
}; | ||
let igvm_payload = std::path::absolute(igvm_payload) | ||
.context("could not make path to igvm payload absolute")?; | ||
|
||
let openvmm_repo = flowey_lib_common::git_checkout::RepoSource::ExistingClone( | ||
ReadVar::from_static(crate::repo_root()), | ||
); | ||
|
||
let mut pipeline = Pipeline::new(); | ||
|
||
let (pub_out_dir, _) = pipeline.new_artifact("custom-vmfirmwareigvm-dll"); | ||
|
||
pipeline | ||
.new_job( | ||
FlowPlatform::host(backend_hint), | ||
FlowArch::host(backend_hint), | ||
"custom-vmfirmwareigvm-dll", | ||
) | ||
.dep_on(|_| flowey_lib_hvlite::_jobs::cfg_versions::Request {}) | ||
.dep_on( | ||
|_| flowey_lib_hvlite::_jobs::cfg_hvlite_reposource::Params { | ||
hvlite_repo_source: openvmm_repo, | ||
}, | ||
) | ||
.dep_on(|_| flowey_lib_hvlite::_jobs::cfg_common::Params { | ||
local_only: Some(flowey_lib_hvlite::_jobs::cfg_common::LocalOnlyParams { | ||
interactive: true, | ||
auto_install: false, | ||
force_nuget_mono: false, // no oss nuget packages | ||
external_nuget_auth: false, | ||
ignore_rust_version: true, | ||
}), | ||
verbose: ReadVar::from_static(false), | ||
locked: false, | ||
deny_warnings: false, | ||
}) | ||
.dep_on( | ||
|ctx| flowey_lib_hvlite::_jobs::local_custom_vmfirmwareigvm_dll::Params { | ||
arch: arch.into(), | ||
igvm_payload, | ||
artifact_dir: ctx.publish_artifact(pub_out_dir), | ||
done: ctx.new_done_handle(), | ||
}, | ||
) | ||
.finish(); | ||
|
||
Ok(pipeline) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
flowey/flowey_lib_hvlite/src/_jobs/local_custom_vmfirmwareigvm_dll.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
use crate::run_cargo_build::common::CommonArch; | ||
use flowey::node::prelude::*; | ||
|
||
flowey_request! { | ||
pub struct Params { | ||
pub igvm_payload: PathBuf, | ||
pub arch: CommonArch, | ||
|
||
pub artifact_dir: ReadVar<PathBuf>, | ||
pub done: WriteVar<SideEffect>, | ||
} | ||
} | ||
|
||
new_simple_flow_node!(struct Node); | ||
|
||
impl SimpleFlowNode for Node { | ||
type Request = Params; | ||
|
||
fn imports(ctx: &mut ImportCtx<'_>) { | ||
ctx.import::<crate::build_vmfirmwareigvm_dll::Node>(); | ||
} | ||
|
||
fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> { | ||
let Params { | ||
arch, | ||
igvm_payload, | ||
|
||
artifact_dir, | ||
done, | ||
} = request; | ||
|
||
let built_dll = ctx.reqv(|v| crate::build_vmfirmwareigvm_dll::Request { | ||
arch, | ||
igvm: ReadVar::from_static(crate::run_igvmfilegen::IgvmOutput { | ||
igvm_bin: igvm_payload, | ||
igvm_map: None, | ||
igvm_tdx_json: None, | ||
igvm_snp_json: None, | ||
igvm_vbs_json: None, | ||
}), | ||
// fixed version to signal that this is a custom dll | ||
dll_version: ReadVar::from_static((1, 0, 1337, 0)), | ||
internal_dll_name: "vmfirmwareigvm.dll".into(), | ||
vmfirmwareigvm_dll: v, | ||
}); | ||
|
||
ctx.emit_rust_step("copy resulting vmfirmwareigvm.dll", |ctx| { | ||
done.claim(ctx); | ||
let artifact_dir = artifact_dir.claim(ctx); | ||
let built_dll = built_dll.claim(ctx); | ||
|rt| { | ||
let artifact_dir = rt.read(artifact_dir); | ||
let built_dll = rt.read(built_dll); | ||
|
||
fs_err::copy(built_dll.dll, artifact_dir.join("vmfirmwareigvm.dll"))?; | ||
|
||
for e in fs_err::read_dir(artifact_dir)? { | ||
let e = e?; | ||
log::info!("{}", e.path().display()); | ||
} | ||
Ok(()) | ||
} | ||
}); | ||
|
||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.