-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_project.sh
executable file
·81 lines (72 loc) · 1.74 KB
/
build_project.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
#!/bin/bash
# Function to display script usage
usage() {
echo "Usage: $0 [--run] [-c]"
echo "Optional arguments:"
echo " --run Run the compiled server executable"
echo " -c Delete the build directory after running the server (only if --run is used)"
echo " --release Compile in release mode"
exit 1
}
# Variables to track flags
RUN_SERVER=false
DELETE_BUILD=false
RELEASE_MODE=false
# Check for optional --run and -c flags
while [[ "$#" -gt 0 ]]; do
case $1 in
--run)
RUN_SERVER=true
;;
-c)
DELETE_BUILD=true
;;
--release)
RELEASE_MODE=true
;;
*)
usage
;;
esac
shift
done
# Step 1: Create a new directory called `build` in the project root
mkdir -p build/static
# Step 2: Compile `server` with `cargo build --release` and copy the executable into `build`
if [ "$RELEASE_MODE" = true ]; then
echo "Compiling server in release mode..."
cd server
cargo build --release
cp target/release/server ../build/
else
echo "Compiling server..."
cd server
cargo build
cp target/debug/server ../build/
fi
cd ..
# Step 3: Compile `wasm` with `trunk build --release` and copy the necessary files into `build/static`
if [ "$RELEASE_MODE" = true ]; then
echo "Compiling wasm in release mode..."
cd wasm
trunk build --release
else
echo "Compiling wasm..."
cd wasm
trunk build
fi
cp -r dist/* ../build/static/
cd ..
# Step 4: Run the server if the --run flag is provided
if [ "$RUN_SERVER" = true ]; then
echo "Running server..."
cd build
./server
# Step 5: Delete the build directory if -c flag is used
if [ "$DELETE_BUILD" = true ]; then
echo "Deleting build directory..."
cd ..
rm -rf build
fi
fi
echo "Build process completed successfully!"