occlum/tools/toolchains/golang/build.sh
LI Qing 6d72e10fc1 Add Golang toolchain and the demo
This commit provides a modified Go runtime in Docker image.
Now we can build a Go program using `occlum-go`, then run it
in SGX enclaves by Occlum.
The Golang demo demonstrates how to build and run a web server
program written in Go.
2020-05-15 03:02:42 +00:00

40 lines
938 B
Bash
Executable File

#!/bin/bash
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
BUILD_DIR=/tmp/occlum_golang_toolchain
INSTALL_DIR=/opt/occlum/toolchains/golang
# Exit if any command fails
set -e
# Clean previous build and installation if any
rm -rf ${BUILD_DIR}
rm -rf ${INSTALL_DIR}
# Create the build directory
mkdir -p ${BUILD_DIR}
cd ${BUILD_DIR}
# Download Golang
git clone https://github.com/golang/go .
# Swtich to Golang 1.13.4
git checkout -b go1.13.4 tags/go1.13.4
# Apply the patch to adapt Golang to Occlum
git apply ${THIS_DIR}/0001-adapt-golang-to-occlum-libos.patch
# Build Golang
cd src
./make.bash
mv ${BUILD_DIR} ${INSTALL_DIR}
# Generate the wrappers for Go
cat > ${INSTALL_DIR}/bin/occlum-go <<EOF
#!/bin/bash
OCCLUM_GCC="\$(which occlum-gcc)"
CC=\$OCCLUM_GCC ${INSTALL_DIR}/bin/go "\$@"
EOF
chmod +x ${INSTALL_DIR}/bin/occlum-go
# Make symbolic links
ln -sf ${INSTALL_DIR} /usr/local/occlum/golang