From 370967d27dfcd30d4789acb215a90bec8bc4def1 Mon Sep 17 00:00:00 2001 From: Ludvig Liljenberg Date: Tue, 10 Dec 2024 11:49:30 -0800 Subject: [PATCH] Update justfiles, build.rs and readme for musl subtree Signed-off-by: Ludvig Liljenberg --- Cargo.lock | 4 +- Justfile | 2 +- c.just | 2 +- src/hyperlight_guest/Cargo.toml | 1 + src/hyperlight_guest/build.rs | 101 ++++++--------------- src/hyperlight_guest/third_party/README.md | 4 +- src/hyperlight_host/Cargo.toml | 2 +- 7 files changed, 34 insertions(+), 82 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 707a1963..4e654af1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1429,9 +1429,9 @@ dependencies = [ [[package]] name = "kvm-ioctls" -version = "0.19.0" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "337d1afa126368bbd6a5c328048f71a69a737e9afe7e436b392a8f8d770c9171" +checksum = "e013ae7fcd2c6a8f384104d16afe7ea02969301ea2bb2a56e44b011ebc907cab" dependencies = [ "bitflags 2.6.0", "kvm-bindings", diff --git a/Justfile b/Justfile index ff655b9e..31904a3c 100644 --- a/Justfile +++ b/Justfile @@ -26,7 +26,7 @@ install-flatbuffers-with-vcpkg: install-vcpkg cd ../vcpkg && ./vcpkg install flatbuffers || cd - tar-headers: (build-rust-capi) # build-rust-capi is a dependency because we need the hyperlight_guest.h to be built - tar -zcvf include.tar.gz -C {{root}}/src/hyperlight_guest/third_party/ libc/musl/include libc/musl/arch/x86_64 printf/printf.h -C {{root}}/src/hyperlight_guest_capi include + tar -zcvf include.tar.gz -C {{root}}/src/hyperlight_guest/third_party/ musl/include musl/arch/x86_64 printf/printf.h -C {{root}}/src/hyperlight_guest_capi include tar-static-lib: (build-rust-capi "release") (build-rust-capi "debug") tar -zcvf hyperlight-guest-c-api-windows.tar.gz -C {{root}}/target/x86_64-pc-windows-msvc/ release/hyperlight_guest_capi.lib -C {{root}}/target/x86_64-pc-windows-msvc/ debug/hyperlight_guest_capi.lib diff --git a/c.just b/c.just index d0b3c33d..75aa3f90 100644 --- a/c.just +++ b/c.just @@ -3,7 +3,7 @@ mkdir := if os() == "windows" { "mkdir -f -p" } else { "mkdir -p"} # PE options c-compile-options-pe := '/GS /W3 /Zi /Od /fp:precise /WX- /std:c17 /showIncludes /MT /EHsc /nologo /diagnostics:column' c-linker-options-pe := '/MANIFEST:NO /NXCOMPAT /HEAP:131072,131072 /STACK:65536,65536 /DEBUG /RELEASE /ENTRY:"entrypoint" /ALIGN:4096 /FILEALIGN:4096 /NODEFAULTLIB /SAFESEH:NO /driver /SUBSYSTEM:NATIVE /MACHINE:x64 /DYNAMICBASE /TSAWARE:no /section:.text,ERP /section:.rdata,RP /section:.data,RWP /section:.pdata,RP' -c-include-flags-pe := "/I " + root / "src/hyperlight_guest_capi/include/" + " /I " + root / "src/hyperlight_guest/third_party/libc/musl/include/" + " /I " + root / "src/hyperlight_guest/third_party/libc/musl/arch/x86_64" + " /I " + root / "src/hyperlight_guest/third_party/printf" +c-include-flags-pe := "/I " + root / "src/hyperlight_guest_capi/include/" + " /I " + root / "src/hyperlight_guest/third_party/musl/include/" + " /I " + root / "src/hyperlight_guest/third_party/musl/arch/x86_64" + " /I " + root / "src/hyperlight_guest/third_party/printf" c-flags-debug-pe := '/Od /Ob0 /Z7' c-flags-release-pe := '/O2 /Gy' diff --git a/src/hyperlight_guest/Cargo.toml b/src/hyperlight_guest/Cargo.toml index d70559c9..710bd76d 100644 --- a/src/hyperlight_guest/Cargo.toml +++ b/src/hyperlight_guest/Cargo.toml @@ -29,3 +29,4 @@ log = { version = "0.4", default-features = false } [build-dependencies] cc = "1.2" cfg-if = "1.0" +glob = "0.3.1" \ No newline at end of file diff --git a/src/hyperlight_guest/build.rs b/src/hyperlight_guest/build.rs index 34ecbe89..71d1e81a 100644 --- a/src/hyperlight_guest/build.rs +++ b/src/hyperlight_guest/build.rs @@ -52,63 +52,16 @@ fn cargo_main() { } if cfg!(feature = "libc") { - cfg.file("third_party/libc/musl/src/ctype/isalpha.c") - .file("third_party/libc/musl/src/ctype/isalnum.c") - .file("third_party/libc/musl/src/ctype/isdigit.c") - .file("third_party/libc/musl/src/ctype/isgraph.c") - .file("third_party/libc/musl/src/ctype/islower.c") - .file("third_party/libc/musl/src/ctype/isprint.c") - .file("third_party/libc/musl/src/ctype/isspace.c") - .file("third_party/libc/musl/src/ctype/isupper.c") - .file("third_party/libc/musl/src/ctype/isxdigit.c") - .file("third_party/libc/musl/src/ctype/tolower.c") - .file("third_party/libc/musl/src/ctype/toupper.c") - .file("third_party/libc/musl/src/errno/__errno_location.c") - .file("third_party/libc/musl/src/internal/floatscan.c") - .file("third_party/libc/musl/src/internal/intscan.c") - .file("third_party/libc/musl/src/internal/shgetc.c") - .file("third_party/libc/musl/src/math/copysign.c") - .file("third_party/libc/musl/src/math/copysignl.c") - .file("third_party/libc/musl/src/math/fabs.c") - .file("third_party/libc/musl/src/math/fabsl.c") - .file("third_party/libc/musl/src/math/fmod.c") - .file("third_party/libc/musl/src/math/fmodl.c") - .file("third_party/libc/musl/src/math/scalbnl.c") - .file("third_party/libc/musl/src/math/__signbit.c") - .file("third_party/libc/musl/src/math/__signbitl.c") - .file("third_party/libc/musl/src/math/__fpclassify.c") - .file("third_party/libc/musl/src/math/__fpclassifyl.c") - .file("third_party/libc/musl/src/stdio/__toread.c") - .file("third_party/libc/musl/src/stdio/__uflow.c") - .file("third_party/libc/musl/src/stdlib/atoi.c") - .file("third_party/libc/musl/src/stdlib/strtod.c") - .file("third_party/libc/musl/src/stdlib/strtol.c") - .file("third_party/libc/musl/src/stdlib/qsort.c") - .file("third_party/libc/musl/src/stdlib/qsort_nr.c") - .file("third_party/libc/musl/src/stdlib/bsearch.c") - .file("third_party/libc/musl/src/string/memchr.c") - .file("third_party/libc/musl/src/string/memcmp.c") - .file("third_party/libc/musl/src/string/memcpy.c") - .file("third_party/libc/musl/src/string/memmove.c") - .file("third_party/libc/musl/src/string/memset.c") - .file("third_party/libc/musl/src/string/stpncpy.c") - .file("third_party/libc/musl/src/string/strchr.c") - .file("third_party/libc/musl/src/string/strchrnul.c") - .file("third_party/libc/musl/src/string/strcmp.c") - .file("third_party/libc/musl/src/string/strcspn.c") - .file("third_party/libc/musl/src/string/strlen.c") - .file("third_party/libc/musl/src/string/strncasecmp.c") - .file("third_party/libc/musl/src/string/strncat.c") - .file("third_party/libc/musl/src/string/strncmp.c") - .file("third_party/libc/musl/src/string/strncpy.c") - .file("third_party/libc/musl/src/string/strspn.c") - .file("third_party/libc/musl/src/string/strstr.c") - .file("third_party/libc/musl/src/prng/rand.c") - .include("third_party/libc/musl/src/include") - .include("third_party/libc/musl/include") - .include("third_party/libc/musl/src/internal") - .include("third_party/libc/musl/arch/generic") - .include("third_party/libc/musl/arch/x86_64"); + let entries = glob::glob("third_party/musl/**/*.[cs]") // .c and .s files + .expect("glob pattern should be valid") + .filter_map(Result::ok); + cfg.files(entries); + + cfg.include("third_party/musl/src/include") + .include("third_party/musl/include") + .include("third_party/musl/src/internal") + .include("third_party/musl/arch/generic") + .include("third_party/musl/arch/x86_64"); } if cfg!(feature = "alloca") { @@ -124,24 +77,22 @@ fn cargo_main() { feature = "libc", feature = "alloca" )) { - if is_pe { - cfg.define("hidden", ""); - cfg.define("weak_alias(old, new) ", " "); - cfg.define("__DEFINED_va_list", None); - cfg.define("__DEFINED___isoc_va_list", None); - } - cfg.define("__x86_64__", None); - cfg.define("__LITTLE_ENDIAN__", None); + cfg.define("HYPERLIGHT", None); // used in certain musl files for conditional compilation // silence compiler warnings - cfg.flag("-Wno-sign-compare"); - cfg.flag("-Wno-bitwise-op-parentheses"); - cfg.flag("-Wno-unknown-pragmas"); - cfg.flag("-Wno-shift-op-parentheses"); - cfg.flag("-Wno-logical-op-parentheses"); - cfg.flag("-Wno-unused-but-set-variable"); + cfg.flag("-Wno-unused-command-line-argument") // including .s files makes clang believe arguments are unused + .flag("-Wno-sign-compare") + .flag("-Wno-bitwise-op-parentheses") + .flag("-Wno-unknown-pragmas") + .flag("-Wno-shift-op-parentheses") + .flag("-Wno-logical-op-parentheses") + .flag("-Wno-unused-but-set-variable") + .flag("-Wno-unused-parameter") + .flag("-Wno-string-plus-int"); if is_pe { + cfg.flag("-Wno-unused-label"); + cfg.flag("-Wno-unused-variable"); cfg.compiler("clang-cl"); } else { cfg.flag("-fPIC"); @@ -182,10 +133,10 @@ fn cargo_main() { } if cfg!(feature = "libc") { copy_includes(&include_dir, "include"); - copy_includes(&include_dir, "third_party/libc/musl/include"); - copy_includes(&include_dir, "third_party/libc/musl/arch/generic"); - copy_includes(&include_dir, "third_party/libc/musl/arch/x86_64"); - copy_includes(&include_dir, "third_party/libc/musl/src/internal"); + copy_includes(&include_dir, "third_party/musl/include"); + copy_includes(&include_dir, "third_party/musl/arch/generic"); + copy_includes(&include_dir, "third_party/musl/arch/x86_64"); + copy_includes(&include_dir, "third_party/musl/src/internal"); } /* do not canonicalize: clang has trouble with UNC paths */ let include_str = include_dir diff --git a/src/hyperlight_guest/third_party/README.md b/src/hyperlight_guest/third_party/README.md index 9a7864bf..deaf7ba5 100644 --- a/src/hyperlight_guest/third_party/README.md +++ b/src/hyperlight_guest/third_party/README.md @@ -11,6 +11,6 @@ Changes have been applied to the original code for Hyperlight using this [patch] ## libc -A partial version of musl libc is used by hyperlight and is located in the [musl](./libc/musl) directory. +A partial version of musl libc is used by hyperlight and is located in the [musl](./musl) directory as a git subtree. -The current version is release [v1.2.3](https://git.musl-libc.org/cgit/musl/tag/?h=v1.2.3). Many files have been deleted and changes have been made to some of the remaining files, those deletions and changes can be applied using [this](./libc/musl-libc.patch) patch. +The current version is release [v1.2.5](https://git.musl-libc.org/cgit/musl/tag/?h=v1.2.5). Many files have been deleted and changes have been made to some of the remaining files. diff --git a/src/hyperlight_host/Cargo.toml b/src/hyperlight_host/Cargo.toml index d25062ff..29f2b5ec 100644 --- a/src/hyperlight_host/Cargo.toml +++ b/src/hyperlight_host/Cargo.toml @@ -74,7 +74,7 @@ seccompiler = { version = "0.4.0", optional = true } mshv-bindings = { workspace = true, optional = true } mshv-ioctls = { workspace = true, optional = true } kvm-bindings = { version = "0.10.0", features = ["fam-wrappers"], optional = true } -kvm-ioctls = { version = "0.19.0", optional = true } +kvm-ioctls = { version = "0.19.1", optional = true } [dev-dependencies] uuid = { version = "1.4.1", features = ["v4"] }