Skip to content

Commit

Permalink
Use musllibc wasm32 headers instead of those of my machine.
Browse files Browse the repository at this point in the history
  • Loading branch information
diekmann committed Mar 6, 2021
1 parent 7da9678 commit d37ac2d
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 13 deletions.
26 changes: 16 additions & 10 deletions doom/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ static LIBC_SRC: &str = "musl-1.2.2";
static LIBGCC_SRC: &str = "clang_compiler_rt";

fn main() {
// original Doom Sources
println!("cargo:rerun-if-changed={}", DOON_SRC);
let status = Command::new("make").args(&["-C", DOON_SRC, "linux/liblinuxxdoom.a"]).status().expect("failed to start doom make");
if !status.success(){
panic!("Failed to make: {}", status);
}
println!("cargo:rustc-link-search={}/linux", DOON_SRC);
println!("cargo:rustc-link-lib=linuxxdoom");


// libc
println!("cargo:rerun-if-changed={}", LIBC_SRC);
let status = Command::new("make").args(&["-C", LIBC_SRC, "lib/libc.a"]).status().expect("failed to start musl libc make");
Expand All @@ -24,6 +14,12 @@ fn main() {
println!("cargo:rustc-link-search={}/lib/", LIBC_SRC);
println!("cargo:rustc-link-lib=c");

// system headers for wasm32
let status = Command::new("make").args(&["-C", LIBC_SRC, "install-headers"]).status().expect("failed to start musl libc install-headers make");
if !status.success(){
panic!("Failed to make: {}", status);
}


// compiler runtime, with e.g., floating point funtcions
println!("cargo:rerun-if-changed={}", LIBGCC_SRC);
Expand All @@ -33,4 +29,14 @@ fn main() {
}
println!("cargo:rustc-link-search={}/build", LIBGCC_SRC);
println!("cargo:rustc-link-lib=clang_rt.builtins-wasm32");


// original Doom Sources
println!("cargo:rerun-if-changed={}", DOON_SRC);
let status = Command::new("make").args(&["-C", DOON_SRC, "linux/liblinuxxdoom.a"]).status().expect("failed to start doom make");
if !status.success(){
panic!("Failed to make: {}", status);
}
println!("cargo:rustc-link-search={}/linux", DOON_SRC);
println!("cargo:rustc-link-lib=linuxxdoom");
}
2 changes: 1 addition & 1 deletion doom/clang_compiler_rt/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CC=clang
AR=llvm-ar-10

CFLAGS=--target=wasm32 -m32 -O2 -Wall -nostdlib -ffreestanding -nostdinc -I../musl-1.2.2/include/ -I../musl-1.2.2/arch/wasm32/ -I../musl-1.2.2/arch/generic/
CFLAGS=--target=wasm32 -m32 -O2 -Wall -nostdlib -ffreestanding -nostdinc -I../musl-1.2.2/built_inc/include/

SOURCES = extenddftf2.c extendsftf2.c
OBJS = $(addprefix build/,$(SOURCES:.c=.o))
Expand Down
3 changes: 2 additions & 1 deletion doom/linuxdoom-1.10/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ AR=llvm-ar-10
# If your get `error: unable to execute command: Executable "wasm-ld" doesn't exist!` on Ubntu 20.04
# apt install lld
# ln -s /usr/bin/wasm-ld-10 /usr/bin/wasm-ld # ugly!
WASM32_CFLAGS=--target=wasm32 -I../musl-1.2.2/include/ -I../musl-1.2.2/arch/wasm32/ -I../musl-1.2.2/arch/generic/ #-I/usr/include
##############TODO:::: use -I musl built_inc/!!!!!
WASM32_CFLAGS=--target=wasm32 -nostdlib -ffreestanding -nostdinc -I../musl-1.2.2/built_inc/include/

# doom was written with the implicit assumption that ints and pointers are 32bit.
# Adding -m32 to make it compile on 64bit archs.
Expand Down
2 changes: 1 addition & 1 deletion doom/musl-1.2.2/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
*.a
*.so
*.so.1
config.mak
lib/musl-gcc.specs
/obj/
/built_inc/
1 change: 1 addition & 0 deletions doom/musl-1.2.2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ endif

clean:
rm -rf obj lib
rm -rf built_inc

distclean: clean
rm -f config.mak
Expand Down
32 changes: 32 additions & 0 deletions doom/musl-1.2.2/config.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This version of config.mak was generated by:
# AR=llvm-ar-10 CC=clang CFLAGS="-m32 --target=wasm32" ./configure --target=wasm32
# Any changes made here will be lost if configure is re-run
AR = llvm-ar-10
RANLIB = llvm-ranlib-10 #$(CROSS_COMPILE)ranlib
ARCH = wasm32
SUBARCH =
ASMSUBARCH =
srcdir = .
prefix = ./built_inc
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
libdir = $(prefix)/lib
includedir = $(prefix)/include
syslibdir = /lib
CC = clang
CFLAGS = -m32 --target=wasm32
CFLAGS_AUTO = -Os -pipe -fomit-frame-pointer -fno-unwind-tables -fno-asynchronous-unwind-tables -ffunction-sections -fdata-sections -w -Wno-pointer-to-int-cast -Werror=implicit-function-declaration -Werror=implicit-int -Werror=pointer-sign -Werror=pointer-arith -Werror=int-conversion -Werror=incompatible-pointer-types -Qunused-arguments -Waddress -Warray-bounds -Wchar-subscripts -Wduplicate-decl-specifier -Winit-self -Wreturn-type -Wsequence-point -Wstrict-aliasing -Wunused-function -Wunused-label -Wunused-variable
CFLAGS_C99FSE = -std=c99 -nostdinc -ffreestanding -frounding-math -Wa,--noexecstack
CFLAGS_MEMOPS =
CFLAGS_NOSSP = -fno-stack-protector
CPPFLAGS =
LDFLAGS =
LDFLAGS_AUTO = -Wl,--sort-section,alignment -Wl,--sort-common -Wl,--gc-sections -Wl,--hash-style=both -Wl,--no-undefined -Wl,--exclude-libs=ALL -Wl,--dynamic-list=./dynamic.list
CROSS_COMPILE = wasm32-
LIBCC = -lgcc -lgcc_eh
OPTIMIZE_GLOBS = internal/*.c malloc/*.c string/*.c
ALL_TOOLS = obj/musl-clang obj/ld.musl-clang
TOOL_LIBS =
ADD_CFI = no
MALLOC_DIR = mallocng
WRAPCC_CLANG = $(CC)
64 changes: 64 additions & 0 deletions doom/musl-1.2.2/tools/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/sh
#
# This is an actually-safe install command which installs the new
# file atomically in the new location, rather than overwriting
# existing files.
#

usage() {
printf "usage: %s [-D] [-l] [-m mode] src dest\n" "$0" 1>&2
exit 1
}

mkdirp=
symlink=
mode=755

while getopts Dlm: name ; do
case "$name" in
D) mkdirp=yes ;;
l) symlink=yes ;;
m) mode=$OPTARG ;;
?) usage ;;
esac
done
shift $(($OPTIND - 1))

test "$#" -eq 2 || usage
src=$1
dst=$2
tmp="$dst.tmp.$$"

case "$dst" in
*/) printf "%s: %s ends in /\n", "$0" "$dst" 1>&2 ; exit 1 ;;
esac

set -C
set -e

if test "$mkdirp" ; then
umask 022
case "$2" in
*/*) mkdir -p "${dst%/*}" ;;
esac
fi

trap 'rm -f "$tmp"' EXIT INT QUIT TERM HUP

umask 077

if test "$symlink" ; then
ln -s "$1" "$tmp"
else
cat < "$1" > "$tmp"
chmod "$mode" "$tmp"
fi

mv -f "$tmp" "$2"
test -d "$2" && {
rm -f "$2/$tmp"
printf "%s: %s is a directory\n" "$0" "$dst" 1>&2
exit 1
}

exit 0

0 comments on commit d37ac2d

Please sign in to comment.