Skip to content

Commit

Permalink
Update justfiles, build.rs and readme for musl subtree
Browse files Browse the repository at this point in the history
Signed-off-by: Ludvig Liljenberg <[email protected]>
  • Loading branch information
ludfjig committed Dec 19, 2024
1 parent 42ee008 commit e79ec96
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion c.just
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
1 change: 1 addition & 0 deletions src/hyperlight_guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ log = { version = "0.4", default-features = false }
[build-dependencies]
cc = "1.2"
cfg-if = "1.0"
glob = "0.3.1"
101 changes: 26 additions & 75 deletions src/hyperlight_guest/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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");
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/hyperlight_guest/third_party/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit e79ec96

Please sign in to comment.