-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. add optee-utee-build crate to make building process simpler 2. use optee-utee-build to build hello_world example 3. fix pipeline
- Loading branch information
Showing
15 changed files
with
1,031 additions
and
146 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,32 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
[package] | ||
name = "optee-utee-build" | ||
version = "0.2.0" | ||
authors = ["Teaclave Contributors <[email protected]>"] | ||
license = "Apache-2.0" | ||
repository = "https://github.com/apache/incubator-teaclave-trustzone-sdk.git" | ||
edition = "2018" | ||
description = "Build tool for TA" | ||
|
||
[dependencies] | ||
uuid = "1.11.0" | ||
quote = "1.0.37" | ||
proc-macro2 = "1.0.92" | ||
syn = "2.0.90" | ||
prettyplease = "0.2.25" |
This file contains 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,119 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use std::fs::File; | ||
use std::io::Write; | ||
use std::path::PathBuf; | ||
|
||
use crate::HeaderFileGenerator; | ||
use crate::Error; | ||
use crate::RustEdition; | ||
use crate::TAConfig; | ||
use crate::{Linker, LinkerType}; | ||
|
||
const DEFAULT_HEADER_FILE_NAME: &str = "user_ta_header.rs"; | ||
|
||
/// The Builder of TA, use it to handle file generation and linking stuff | ||
/// | ||
/// Usage: | ||
/// | ||
/// ```no_run | ||
/// use optee_utee_build::{TAConfig, Builder, RustEdition}; | ||
/// # use optee_utee_build::Error; | ||
/// # fn main() -> Result<(), Error> { | ||
/// let ta_config = TAConfig::new_standard("0.1.0", "example", "example"); | ||
/// let uuid = "d93c2970-b1a6-4b86-90ac-b42830e78d9b"; | ||
/// Builder::new(RustEdition::Before2024, ta_config).build(uuid)?; | ||
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
/// | ||
/// There are some difference when cargo use different linkers, we will try | ||
/// to detect the linker automatically, you can use set it manually if you | ||
/// met some problems with it. | ||
/// ```no_run | ||
/// use optee_utee_build::{TAConfig, Builder, RustEdition, LinkerType}; | ||
/// # use optee_utee_build::Error; | ||
/// # fn main() -> Result<(), Error> { | ||
/// let ta_config = TAConfig::new_standard("0.1.0", "example", "example"); | ||
/// let uuid = "d93c2970-b1a6-4b86-90ac-b42830e78d9b"; | ||
/// Builder::new(RustEdition::Before2024, ta_config).linker_type(LinkerType::LD).build(uuid)?; | ||
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
pub struct Builder { | ||
out_dir: Option<PathBuf>, | ||
edition: RustEdition, | ||
header_file_name: Option<String>, | ||
ta_config: TAConfig, | ||
linker_type: Option<LinkerType>, | ||
} | ||
|
||
impl Builder { | ||
pub fn new(edition: RustEdition, ta_config: TAConfig) -> Self { | ||
Self { | ||
out_dir: Option::None, | ||
header_file_name: Option::None, | ||
linker_type: Option::None, | ||
edition, | ||
ta_config, | ||
} | ||
} | ||
pub fn out_dir<P: Into<PathBuf>>(mut self, path: P) -> Self { | ||
self.out_dir = Option::Some(path.into()); | ||
self | ||
} | ||
pub fn header_file_name<S: Into<String>>(mut self, file_name: S) -> Self { | ||
self.header_file_name = Option::Some(file_name.into()); | ||
self | ||
} | ||
pub fn linker_type(mut self, linker_type: LinkerType) -> Self { | ||
self.linker_type = Option::Some(linker_type); | ||
self | ||
} | ||
pub fn build(self, uuid: &str) -> Result<(), Error> { | ||
let out_dir = match self.out_dir.clone() { | ||
Some(v) => v, | ||
None => PathBuf::from(std::env::var("OUT_DIR")?), | ||
}; | ||
self.write_header_file(out_dir.clone(), uuid)?; | ||
self.link(out_dir)?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Builder { | ||
fn write_header_file(&self, out: PathBuf, uuid: &str) -> Result<(), Error> { | ||
let out_header_file_name = out.join(match self.header_file_name.as_ref() { | ||
Some(v) => v.as_str(), | ||
None => DEFAULT_HEADER_FILE_NAME, | ||
}); | ||
let mut buffer = File::create(out_header_file_name.clone())?; | ||
let header_codes = | ||
HeaderFileGenerator::new(self.edition.clone()).generate(&self.ta_config, uuid)?; | ||
buffer.write_all(header_codes.as_bytes())?; | ||
Ok(()) | ||
} | ||
|
||
fn link(&self, out_dir: PathBuf) -> Result<(), Error> { | ||
let linker = match self.linker_type.as_ref() { | ||
Option::Some(v) => Linker::new(v.clone()), | ||
Option::None => Linker::auto(), | ||
}; | ||
linker.link_all(out_dir) | ||
} | ||
} |
Oops, something went wrong.