Skip to content

Commit

Permalink
Merge pull request #503 from Freax13/enhancement/libmstpm-cleanup
Browse files Browse the repository at this point in the history
various improvements to libmstpm
  • Loading branch information
joergroedel authored Oct 30, 2024
2 parents 91aebf4 + d29f6bf commit f49b375
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
4 changes: 0 additions & 4 deletions kernel/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ fn main() {
println!("cargo:rustc-link-arg-bin=svsm=--no-relax");
println!("cargo:rustc-link-arg-bin=svsm=-Tkernel/src/svsm.lds");
println!("cargo:rustc-link-arg-bin=svsm=-no-pie");
if std::env::var("CARGO_FEATURE_MSTPM").is_ok() && std::env::var("CARGO_CFG_TEST").is_err() {
println!("cargo:rustc-link-arg-bin=svsm=-Llibmstpm");
println!("cargo:rustc-link-arg-bin=svsm=-lmstpm");
}

// Extra linker args for tests.
println!("cargo:rerun-if-env-changed=LINK_TEST");
Expand Down
2 changes: 0 additions & 2 deletions libmstpm/.gitignore

This file was deleted.

15 changes: 6 additions & 9 deletions libmstpm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ MSTPM_MAKEFILE = $(MSTPM_DIR)/Makefile

LIBS = $(LIBCRT) $(LIBCRYPTO) $(LIBTPM) $(LIBPLATFORM)

all: libmstpm.a src/bindings.rs
OUT_DIR ?= $(CWD)

libmstpm.a: $(LIBS)
all: $(OUT_DIR)/libmstpm.a $(OUT_DIR)/bindings.rs

$(OUT_DIR)/libmstpm.a: $(LIBS)
rm -f $@
ar rcsTPD $@ $^

Expand Down Expand Up @@ -123,13 +125,8 @@ $(MSTPM_MAKEFILE):
BINDGEN_FLAGS = --use-core
CLANG_FLAGS = -Wno-incompatible-library-redeclaration

src/bindings.rs: deps/libmstpm.h $(LIBTPM)
echo "#![allow(non_upper_case_globals)]" > $@
echo "#![allow(non_camel_case_types)]" >> $@
echo "#![allow(non_snake_case)]" >> $@
echo "#![allow(unused)]" >> $@
echo "#![allow(improper_ctypes)]" >> $@
bindgen $(BINDGEN_FLAGS) deps/libmstpm.h -- $(CLANG_FLAGS) >> $@
$(OUT_DIR)/bindings.rs: deps/libmstpm.h $(LIBTPM)
bindgen $(BINDGEN_FLAGS) --output $@ deps/libmstpm.h -- $(CLANG_FLAGS)

clean: $(OPENSSL_MAKEFILE) $(MSTPM_MAKEFILE)
make -C $(LIBCRT_DIR) clean
Expand Down
20 changes: 15 additions & 5 deletions libmstpm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@
//
// Authors: Claudio Carvalho <[email protected]>

use std::env::current_dir;
use std::process::Command;
use std::process::Stdio;

fn main() {
let output = Command::new("make")
// Build libmstpm.
let status = Command::new("make")
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.status()
.unwrap();
assert!(status.success());

if !output.status.success() {
panic!();
}
// Tell cargo to link libmstpm and where to find it.
let out_dir = std::env::var("OUT_DIR").unwrap();
println!("cargo:rustc-link-search={out_dir}");
println!("cargo:rustc-link-lib=mstpm");

// Tell cargo not to rerun the build-script unless anything in this
// directory changes.
let cwd = current_dir().unwrap();
let cwd = cwd.as_os_str().to_str().unwrap();
println!("cargo:rerun-if-changed={cwd}");
}
10 changes: 9 additions & 1 deletion libmstpm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@
#![no_std]

/// C bindings
pub mod bindings;
pub mod bindings {
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(unused)]
#![allow(improper_ctypes)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
}

0 comments on commit f49b375

Please sign in to comment.