-
Notifications
You must be signed in to change notification settings - Fork 1
/
set.sh
executable file
·148 lines (127 loc) · 4.38 KB
/
set.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#Building glibc to wasm
cd /home
apt-get update
apt update
apt install -y build-essential
apt install -y git
apt install -y wget
apt install -y gcc-i686-linux-gnu g++-i686-linux-gnu
apt install -y bison
apt install -y gawk
apt install -y vim
apt install -y libxml2
apt install -y python3
#Install clang-16
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-16.0.4/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04.tar.xz
tar -xf clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04.tar.xz
cd /home/lind-wasm/glibc
git switch main
cd /home
mv /home/lind-wasm/glibc/wasi /home/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/lib/clang/16/lib
#Configure(config.sh)
cd /home/lind-wasm/glibc
echo '#!/bin/bash
set -e
BUILDDIR=build
mkdir -p $BUILDDIR
cd $BUILDDIR
../configure --disable-werror --disable-hidden-plt --with-headers=/usr/i686-linux-gnu/include --prefix=/home/lind-wasm/glibc/target --host=i686-linux-gnu --build=i686-linux-gnu\
CFLAGS=" -O2 -g" \
CC="/home/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin/clang-16 --target=wasm32-unkown-wasi -v -Wno-int-conversion"
' > config.sh
unset LD_LIBRARY_PATH
chmod +x config.sh
./config.sh
#Compiling to object file
cd build
make --keep-going -j4
#Installing
make install --keep-going
#Generating wasm sysroot
cd ..
rm -r gen_sysroot.sh
echo'
#!/bin/bash
# Define the source directory for object files (change ./build to your desired path)
src_dir="./build"
# Define paths for copying additional resources
include_source_dir="/home/lind-wasm/glibc/target/include"
crt1_source_path="/home/lind-wasm/glibc/lind_syscall/crt1.o"
lind_syscall_path="/home/lind-wasm/glibc/lind_syscall/lind_syscall.o" # Path to the lind_syscall.o file
# Define the output archive and sysroot directory
output_archive="sysroot/lib/wasm32-wasi/libc.a"
sysroot_dir="sysroot"
# First, remove the existing sysroot directory to start cleanly
rm -rf "$sysroot_dir"
# Find all .o files recursively in the source directory, ignoring stamp.o
object_files=$(find "$src_dir" -type f -name "*.o" ! \( -name "stamp.o" -o -name "argp-pvh.o" -o -name "repertoire.o" \))
# Add the lind_syscall.o file to the list of object files
object_files="$object_files $lind_syscall_path"
# Check if object files were found
if [ -z "$object_files" ]; then
echo "No suitable .o files found in '$src_dir'."
exit 1
fi
# Create the sysroot directory structure
mkdir -p "$sysroot_dir/include/wasm32-wasi" "$sysroot_dir/lib/wasm32-wasi"
# Pack all found .o files into a single .a archive
/home/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin/llvm-ar rcs "$output_archive" $object_files
# Check if llvm-ar succeeded
if [ $? -eq 0 ]; then
echo "Successfully created $output_archive with the following .o files:"
echo "$object_files"
else
echo "Failed to create the archive."
exit 1
fi
# Copy all files from the external include directory to the new sysroot include directory
cp -r "$include_source_dir"/* "$sysroot_dir/include/wasm32-wasi/"
# Copy the crt1.o file into the new sysroot lib directory
cp "$crt1_source_path" "$sysroot_dir/lib/wasm32-wasi/"
' > gen_sysroot.sh
chmod +x gen_sysroot.sh
./gen_sysroot.sh
#Building safeposix-rust
cd /home
apt install -y curl
apt install -y gcc
git clone --recurse-submodules https://github.com/yzhang71/safeposix-rust.git
cd safeposix-rust
git switch 3i-dev
cargo build
#Building wasmtime
cd /home/lind-wasm/wasmtime
git submodule update --init
git switch add-lind
cd /home/lind-wasm/wasmtime/crates/rustposix/src
rm -r build.rs
cat << 'EOF' > build.rs
fn main() {
println!("cargo:rustc-link-search=native=/home/lind-wasm/wasmtime/crates/rustposix");
println!("cargo:rustc-link-lib=dylib=rustposix");
}
EOF
chmod +x build.rs
cd /home/lind-wasm/wasmtime
export LD_LIBRARY_PATH=/home/lind-wasm/wasmtime/crates/rustposix:$LD_LIBRARY_PATH
cp /home/safeposix-rust/target/debug/librustposix.so /home/lind-wasm/wasmtime/crates/rustposix
cargo build
#Modify stubs.h
cd /home/lind-wasm/glibc/target/include/gnu
rm -r stubs.h
echo '/* This file is automatically generated.
This file selects the right generated file of `__stub_FUNCTION` macros based on the architecture being compiled for. */
//#if !defined __x86_64__
//# include <gnu/stubs-32.h>
//#endif
#if defined __x86_64__ && defined __LP64__
# include <gnu/stubs-64.h>
#endif
#if defined __x86_64__ && defined __ILP32__
# include <gnu/stubs-x32.h>
#endif
' > stubs.h
chmod +x stubs.h
cd /home/lind-wasm/glibc
./gen_sysroot.sh
cd /home