-
Notifications
You must be signed in to change notification settings - Fork 1
/
linux.sh
101 lines (71 loc) · 2.57 KB
/
linux.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
#!/bin/sh
set +e # Exit on failure
# Check if docker is installed
if [ ! -x "$(command -v docker)" ]; then
echo "docker is not installed"
echo "installation instructions might be here: https://docs.docker.com/engine/install/"
exit 0
fi
# Function to extract the package version from Cargo.toml
# Use grep to find the line containing 'version' in Cargo.toml
cd src/*/rust
echo "Checked into rust folder"
version_line=$(grep -E '^version = .*' Cargo.toml)
# Extract the version string after the '='
if [ ! -z "$version_line" ]; then
version=$(echo "$version_line" | cut -d '=' -f2 | tr -d '[:space:]')
package_version=$(echo "$version" | sed 's/^"//' | sed 's/"$//')
else
echo "Error: Could not find 'version' in Cargo.toml"
fi
# Extract the name from the [package] section
package_name_line=$(grep -m 1 -E '^name = .*' Cargo.toml)
# Extract the second name from the [lib] section
lib_name_line=$(grep -E '^\[lib\]' -A 5 Cargo.toml | grep -E '^name = .*')
# Extract the package name string after the '='
if [ ! -z "$package_name_line" ]; then
package_name=$(echo "$package_name_line" | cut -d '=' -f2 | tr -d '[:space:]' | sed 's/^"//' | sed 's/"$//')
else
echo "Error: Could not find 'name' in [package] section"
exit 1
fi
# Extract the lib name string after the '=' if it exists
if [ ! -z "$lib_name_line" ]; then
lib_name=$(echo "$lib_name_line" | cut -d '=' -f2 | tr -d '[:space:]' | sed 's/^"//' | sed 's/"$//')
else
lib_name=""
fi
# Print the final package name
echo "Package name: $package_name"
cd ../../../
# Print the version or handle errors
if [ ! -z "$package_version" ]; then
echo "Package version: $package_version"
else
echo "An error occurred while reading the version."
exit 1
fi
# Define target architectures
echo "Starting $target build..."
docker build -t build-$target -f Dockerfile.$target .
echo "Build completed!"
echo "Running build-$target docker"
container_id=$(docker run -d build-$target) || fail "Failed to run container"
current_dir=$(pwd)
folder_name="lib/$target"
if [ -d "$folder_name" ]; then
rm -rf "$folder_name"
fi
mkdir "$folder_name"
architecture="x86_64-unknown-linux-gnu"
if [ ! -z "$lib_name" ]; then
a_file="/app/target/$architecture/release/lib$lib_name.a"
else
a_file="/app/target/$architecture/release/lib$package_name.a"
fi
full_path="/$current_dir/$folder_name"
docker cp -a $container_id:$a_file "$full_path/lib$package_name-$package_version.a"
echo "File copied"
docker kill $container_id
echo "build-$target container stoppped"
echo "Build completed! Library in lib/linux folder."