Skip to content

Commit

Permalink
Add Mizar build support for arm64 CPU architecture (#652)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinaykul committed May 9, 2022
1 parent 3f0cbdf commit 66a6c75
Show file tree
Hide file tree
Showing 5 changed files with 320 additions and 263 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ SANITIZE += -fno-omit-frame-pointer
## CFLAGS
CFLAGS += -I.
CFLAGS += -Ilib/usr/include
ifeq (${ARCH},aarch64)
CFLAGS += -I/usr/include/tirpc
endif
CFLAGS += -g -O3 -DDEBUG -Llib
CFLAGS += -std=c11
CFLAGS += -D_POSIX_C_SOURCE
Expand All @@ -61,12 +64,19 @@ LDFLAGS += -l:libbpf.a
LDFLAGS += -l:libelf.a
LDFLAGS += -lz
LDFLAGS += -lnsl
ifeq (${ARCH},aarch64)
LDFLAGS += -ltirpc
endif
LDFLAGS += -static-liblsan
LDFLAGS += -static-libubsan
$(info LDFLAGS=$(LDFLAGS))

LLC=llc-7 -march=bpf -filetype=obj
CLANG=clang-7
ifeq (${ARCH},aarch64)
LLC=llc -march=bpf -filetype=obj
CLANG=clang
endif
CLANGFLAGS= -I.\
-Wno-unused-value -Wno-pointer-sign\
-Wno-compare-distinct-pointer-types \
Expand Down
136 changes: 81 additions & 55 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,28 @@
# THE USE OR OTHER DEALINGS IN THE SOFTWARE.

logout_needed=false
cpu_arch="amd64"
clang_pkg="clang-7"
llvm_pkg="llvm-7"

function install-dev-packages {
echo ""
echo "Installing dev packages ..."
sudo apt-get update -y
sudo apt-get install -y \
build-essential \
clang-7 \
llvm-7 \
libelf-dev \
libcmocka-dev \
lcov \
scapy \
pkg-config
sudo apt-get install -y \
${llvm_pkg} \
${clang_pkg}
if [[ "$(arch)" == "aarch64" ]]; then
sudo apt-get install -y \
libtirpc-dev
fi
}

function install-python {
Expand Down Expand Up @@ -66,9 +74,9 @@ function install-python-ubuntu-18 {
function install-go-for-mizar {
echo ""
echo "Installing go 1.13.9 ..."
wget -O /tmp/go1.13.9.linux-amd64.tar.gz https://dl.google.com/go/go1.13.9.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf /tmp/go1.13.9.linux-amd64.tar.gz
rm -rf /tmp/go1.13.9.linux-amd64.tar.gz
wget -O /tmp/go1.13.9.linux-${cpu_arch}.tar.gz https://dl.google.com/go/go1.13.9.linux-${cpu_arch}.tar.gz
sudo tar -C /usr/local -xzf /tmp/go1.13.9.linux-${cpu_arch}.tar.gz
rm -rf /tmp/go1.13.9.linux-${cpu_arch}.tar.gz
export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin
cat ~/.profile | grep "PATH" | egrep "/usr/local/go/bin"
if [ $? -ne 0 ]; then
Expand Down Expand Up @@ -97,7 +105,7 @@ function install-docker {
function install-kubectl {
echo ""
echo "Installing kubectl ..."
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/${cpu_arch}/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
}
Expand All @@ -107,7 +115,7 @@ function install-kind {
echo "Installing kind ..."
pushd /tmp
ver=$(curl -s https://api.github.com/repos/kubernetes-sigs/kind/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')
curl -Lo kind "https://github.com/kubernetes-sigs/kind/releases/download/$ver/kind-$(uname)-amd64"
curl -Lo kind "https://github.com/kubernetes-sigs/kind/releases/download/$ver/kind-$(uname)-${cpu_arch}"
chmod +x kind
sudo mv kind /usr/local/bin
popd
Expand All @@ -128,62 +136,80 @@ function install-protobuf-and-pip-deps {
}

# Main bootstrap script
tput setaf 1
echo "NOTE: This script will reboot the system if you opt to allow kernel update."
echo " If reboot is not required, it will log you out and require re-login for new permissions to take effect."
echo ""
read -n 1 -s -r -p "Press Ctrl-c to quit, any key to continue..."
tput sgr0
echo " "

# Install dev packages
install-dev-packages

# Install python
install-python
cat /etc/os-release | grep VERSION_ID | grep "18.04"
if [ $? -eq 0 ]; then
install-python-ubuntu-18
fi
function main {
tput setaf 1
echo "NOTE: This script will reboot the system if you opt to allow kernel update."
echo " If reboot is not required, it will log you out and require re-login for new permissions to take effect."
echo ""
read -n 1 -s -r -p "Press Ctrl-c to quit, any key to continue..."
tput sgr0
echo " "

# Install dev packages
install-dev-packages

# Install python
install-python
cat /etc/os-release | grep VERSION_ID | grep "18.04"
if [ $? -eq 0 ]; then
install-python-ubuntu-18
fi

# Install go
which go
if [ $? -ne 0 ]; then
install-go-for-mizar
else
go_ver=$(go version | go version | awk '{print $3}')
if [[ "${go_ver}" != "go1.13.9" ]]; then
# Install go
which go
if [ $? -ne 0 ]; then
install-go-for-mizar
else
go_ver=$(go version | go version | awk '{print $3}')
if [[ "${go_ver}" != "go1.13.9" ]]; then
install-go-for-mizar
fi
fi
fi

# Install docker
which docker
if [ $? -ne 0 ]; then
install-docker
fi
# Install docker
which docker
if [ $? -ne 0 ]; then
install-docker
fi

# Install kind
which kind
if [ $? -ne 0 ]; then
install-kind
fi
# Install kind
which kind
if [ $? -ne 0 ]; then
install-kind
fi

# Install kubectl
which kubectl
if [ $? -ne 0 ]; then
install-kubectl
fi
# Install kubectl
which kubectl
if [ $? -ne 0 ]; then
install-kubectl
fi

git submodule update --init --recursive
git submodule update --init --recursive

# Install protobuf dependecies
install-protobuf-and-pip-deps
# Install protobuf dependecies
install-protobuf-and-pip-deps

# Install kernel needed for Mizar (if required)
source ${PWD}/kernelupdate.sh
# Install kernel needed for Mizar (if required)
source ${PWD}/kernelupdate.sh

if [ "$logout_needed" = true ]; then
PPPID=$(awk '{print $4}' "/proc/$PPID/stat")
kill $PPPID
if [ "$logout_needed" = true ]; then
PPPID=$(awk '{print $4}' "/proc/$PPID/stat")
kill $PPPID
fi
}

if [[ "$(arch)" == "x86_64" ]]; then
main
elif [[ "$(arch)" == "aarch64" ]]; then
cat /etc/os-release | grep VERSION_ID | grep "2[1-9].04"
if [ $? -eq 0 ]; then
cpu_arch="arm64"
llvm_pkg="llvm"
clang_pkg="clang"
main
else
echo "CPU architecture $(arch) not supported below Ubuntu 22.04"
fi
else
echo "CPU architecture $(arch) not supported."
fi
6 changes: 5 additions & 1 deletion kernelupdate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ function check-and-install-mizar-kernel {
}

# Main
check-and-install-mizar-kernel
if [[ "$(arch)" == "x86_64" ]]; then
check-and-install-mizar-kernel
else
echo "CPU architecture $(arch) not supported."
fi
24 changes: 16 additions & 8 deletions replace-containerd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
# THE USE OR OTHER DEALINGS IN THE SOFTWARE.

cd $HOME/go/src/k8s.io/arktos
wget -qO- https://github.com/CentaurusInfra/containerd/releases/download/tenant-cni-args/containerd.zip | zcat > /tmp/containerd
sudo chmod +x /tmp/containerd
sudo systemctl stop containerd
sudo mv /usr/bin/containerd /usr/bin/containerd.bak
sudo mv /tmp/containerd /usr/bin/
sudo systemctl restart containerd
sudo systemctl restart docker
function main {
cd $HOME/go/src/k8s.io/arktos
wget -qO- https://github.com/CentaurusInfra/containerd/releases/download/tenant-cni-args/containerd.zip | zcat > /tmp/containerd
sudo chmod +x /tmp/containerd
sudo systemctl stop containerd
sudo mv /usr/bin/containerd /usr/bin/containerd.bak
sudo mv /tmp/containerd /usr/bin/
sudo systemctl restart containerd
sudo systemctl restart docker
}

if [[ "$(arch)" == "x86_64" ]]; then
main
else
echo "CPU architecture $(arch) not supported."
fi
Loading

0 comments on commit 66a6c75

Please sign in to comment.