Skip to content

Commit

Permalink
Move the enclaves into the same build directory
Browse files Browse the repository at this point in the history
Moving the enclaves into the same build directory reduces compilation
times on this developer's machine from 7m45s to 6m31s. Which is ~15%
improvement. It also reduces the build directory from 76GiB to 71GiB.
  • Loading branch information
nick-mobilecoin committed Dec 11, 2023
1 parent b27a987 commit 3544587
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion consensus/enclave/measurement/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const CONSENSUS_ENCLAVE_PRODUCT_ID: u16 = 1;
const CONSENSUS_ENCLAVE_SECURITY_VERSION: u16 = 8;
const CONSENSUS_ENCLAVE_NAME: &str = "consensus-enclave";
const CONSENSUS_ENCLAVE_DIR: &str = "../trusted";
const CONSENSUS_ENCLAVE_BUILD_DIR: &str = "enclave";

fn main() {
let env = Environment::default();
Expand Down Expand Up @@ -71,7 +72,7 @@ fn main() {
}

builder
.target_dir(env.target_dir().join(CONSENSUS_ENCLAVE_NAME).as_path())
.target_dir(env.target_dir().join(CONSENSUS_ENCLAVE_BUILD_DIR).as_path())
.config_builder
.debug(sgx.sgx_mode() == SgxMode::Simulation || env.profile() != "release")
.prod_id(CONSENSUS_ENCLAVE_PRODUCT_ID)
Expand Down
3 changes: 2 additions & 1 deletion fog/ingest/enclave/measurement/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const INGEST_ENCLAVE_PRODUCT_ID: u16 = 4;
const INGEST_ENCLAVE_SECURITY_VERSION: u16 = 7;
const INGEST_ENCLAVE_NAME: &str = "ingest-enclave";
const INGEST_ENCLAVE_DIR: &str = "../trusted";
const INGEST_ENCLAVE_BUILD_DIR: &str = "enclave";

fn main() {
let env = Environment::default();
Expand Down Expand Up @@ -71,7 +72,7 @@ fn main() {
}

builder
.target_dir(env.target_dir().join(INGEST_ENCLAVE_NAME).as_path())
.target_dir(env.target_dir().join(INGEST_ENCLAVE_BUILD_DIR).as_path())
.config_builder
.debug(sgx.sgx_mode() == SgxMode::Simulation || env.profile() != "release")
.prod_id(INGEST_ENCLAVE_PRODUCT_ID)
Expand Down
3 changes: 2 additions & 1 deletion fog/ledger/enclave/measurement/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const LEDGER_ENCLAVE_PRODUCT_ID: u16 = 2;
const LEDGER_ENCLAVE_SECURITY_VERSION: u16 = 7;
const LEDGER_ENCLAVE_NAME: &str = "ledger-enclave";
const LEDGER_ENCLAVE_DIR: &str = "../trusted";
const LEDGER_ENCLAVE_BUILD_DIR: &str = "enclave";

fn main() {
let env = Environment::default();
Expand Down Expand Up @@ -71,7 +72,7 @@ fn main() {
}

builder
.target_dir(env.target_dir().join(LEDGER_ENCLAVE_NAME).as_path())
.target_dir(env.target_dir().join(LEDGER_ENCLAVE_BUILD_DIR).as_path())
.config_builder
.debug(sgx.sgx_mode() == SgxMode::Simulation || env.profile() != "release")
.prod_id(LEDGER_ENCLAVE_PRODUCT_ID)
Expand Down
3 changes: 2 additions & 1 deletion fog/view/enclave/measurement/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const VIEW_ENCLAVE_PRODUCT_ID: u16 = 3;
const VIEW_ENCLAVE_SECURITY_VERSION: u16 = 7;
const VIEW_ENCLAVE_NAME: &str = "view-enclave";
const VIEW_ENCLAVE_DIR: &str = "../trusted";
const VIEW_ENCLAVE_BUILD_DIR: &str = "enclave";

fn main() {
let env = Environment::default();
Expand Down Expand Up @@ -71,7 +72,7 @@ fn main() {
}

builder
.target_dir(env.target_dir().join(VIEW_ENCLAVE_NAME).as_path())
.target_dir(env.target_dir().join(VIEW_ENCLAVE_BUILD_DIR).as_path())
.config_builder
.debug(sgx.sgx_mode() == SgxMode::Simulation || env.profile() != "release")
.prod_id(VIEW_ENCLAVE_PRODUCT_ID)
Expand Down
8 changes: 4 additions & 4 deletions util/build/enclave/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub struct Builder {
/// The target architecture
target_arch: String,

/// The CARGO_TARGET_DIR path
/// The CARGO_TARGET_DIR path for the enclave
target_dir: PathBuf,

/// The CARGO_TARGET_DIR/profile path
Expand Down Expand Up @@ -258,7 +258,7 @@ impl Builder {
staticlib,
target_arch: env.target_arch().to_owned(),
out_dir: env.out_dir().to_owned(),
target_dir: env.target_dir().to_owned(),
target_dir: env.target_dir().join(enclave_name),
profile_target_dir: env.profile_target_dir().to_owned(),
profile: env.profile().to_owned(),
sgx_version: sgx_version.to_owned(),
Expand All @@ -279,6 +279,7 @@ impl Builder {

/// Set a new "base" target dir to use when building an enclave
pub fn target_dir(&mut self, target_dir: &Path) -> &mut Self {
self.target_dir = target_dir.to_owned();
self.cargo_builder.target_dir(target_dir);
self
}
Expand Down Expand Up @@ -650,8 +651,7 @@ impl Builder {
SgxMode::Simulation => "_sim",
};

// "target/mc_foo_enclave"
let staticlib_target_dir = self.target_dir.join(&self.name);
let staticlib_target_dir = &self.target_dir;

// e.g. "mc_foo_enclave_trusted"
let staticlib_crate_name = self.staticlib.workspace_members[0]
Expand Down

0 comments on commit 3544587

Please sign in to comment.