From 8fbd6295bf5d1b1ddd90ad2886f419041da8e400 Mon Sep 17 00:00:00 2001 From: "Hui, Chunyang" Date: Thu, 17 Sep 2020 09:07:51 +0000 Subject: [PATCH] Add Golang installer --- tools/installer/README.md | 22 ++++-- tools/installer/deb/Makefile | 13 ++++ tools/installer/deb/toolchains/gcc/rules | 1 - .../installer/deb/toolchains/golang/changelog | 5 ++ tools/installer/deb/toolchains/golang/compat | 1 + tools/installer/deb/toolchains/golang/control | 12 ++++ tools/installer/deb/toolchains/golang/rules | 64 +++++++++++++++++ .../deb/toolchains/golang/source/format | 1 + tools/installer/rpm/Makefile | 23 +++++- .../rpm/toolchains/golang/occlum-go.sh | 1 + .../golang/occlum-toolchains-golang.spec | 70 +++++++++++++++++++ 11 files changed, 206 insertions(+), 7 deletions(-) create mode 100644 tools/installer/deb/toolchains/golang/changelog create mode 100644 tools/installer/deb/toolchains/golang/compat create mode 100644 tools/installer/deb/toolchains/golang/control create mode 100755 tools/installer/deb/toolchains/golang/rules create mode 100644 tools/installer/deb/toolchains/golang/source/format create mode 100644 tools/installer/rpm/toolchains/golang/occlum-go.sh create mode 100644 tools/installer/rpm/toolchains/golang/occlum-toolchains-golang.spec diff --git a/tools/installer/README.md b/tools/installer/README.md index b3c88fcc..0349d926 100644 --- a/tools/installer/README.md +++ b/tools/installer/README.md @@ -26,7 +26,7 @@ If a user wants to build his application on a platform installed with Occlum ins cd tools/installer/rpm make ``` -Now, only `c/c++` option is supported. And the installer can be found under `build/rpms`. +Now, only `c/c++` and `golang` options are supported. And the installer can be found under `build/rpms`. ### How to Use @@ -59,11 +59,19 @@ rpm -i occlum-pal-*.rpm rpm -i occlum-runtime-*.rpm ``` -Toolchains are needed when compiling applications and also during runtime. Choose to install the toolchain installer based on the application's language. Currently, we only supports `C/C++`. More language toolchain installers are on the way. To install `C/C++` toolchain, just run the command: +Toolchains are needed when compiling applications and also during runtime. C/C++ toolchain is a must for Occlum commands. +To install C/C++ toolchain, just run the command: ``` rpm -i occlum-toolchains-gcc-*.rpm ``` +Besides, users can choose to install the toolchain installer based on the application's language. Currently, we also supports Golang. More language toolchain installers are on the way. To install Golang toolchain, run the below commands: +``` +yum install -y epel-release +yum install -y rc +rpm -i occlum-toolchains-golang-*.rpm +``` + At last, install `occlum` package to get complete support of Occlum: ``` rpm -i occlum_*.rpm @@ -99,7 +107,7 @@ If a user wants to build his application on a platform installed with Occlum ins cd tools/installer/deb make ``` -Now, only `c/c++` option is supported. And the installer can be found under `build/debs`. +Now, only `c/c++` and `golang` options are supported. And the installer can be found under `build/debs`. ### How to Use @@ -137,11 +145,17 @@ apt install -y ./occlum-pal*.deb apt install -y ./occlum-sgx-tools*.deb ``` -Currently, we only supports `C/C++`. More language toolchain installers are on the way. To install `C/C++` toolchain, just run the command: +Toolchains are needed when compiling applications and also during runtime. C/C++ toolchain is a must for Occlum commands. +To install C/C++ toolchain, just run the command: ``` apt install -y ./occlum-toolchains-gcc*.deb ``` +Besides, users can choose to install the toolchain installer based on the application's language. Currently, we also supports Golang. More language toolchain installers are on the way. To install Golang toolchain, run the below commands: +``` +apt install -y ./occlum-toolchains-golang*.deb +``` + At last, install `occlum` package to get complete support of Occlum: ``` apt install -y ./occlum_*.deb diff --git a/tools/installer/deb/Makefile b/tools/installer/deb/Makefile index ee064b55..88a64a3a 100644 --- a/tools/installer/deb/Makefile +++ b/tools/installer/deb/Makefile @@ -10,6 +10,8 @@ VERSION_NUM = $(MAJOR_VER_NUM).$(MINOR_VER_NUM).$(PATCH_VER_NUM) DEB_BUILD_DIR := /tmp/deb_build PACKAGE_DIR := /tmp +GO_PATCH = $(PROJECT_DIR)/tools/toolchains/golang/adapt-golang-to-occlum.patch + .PHONY: all main config_files main_deps c/c++ deps_c clean clean-build all: main @@ -53,6 +55,17 @@ deps_c: cp $(PROJECT_DIR)/tools/installer/rpm/toolchains/gcc/occlum-gcc.sh $(DEB_BUILD_DIR)/occlum-toolchains-gcc/debian echo " echo 'Please execute command \"source /etc/profile\" to validate envs immediately' " > $(DEB_BUILD_DIR)/occlum-toolchains-gcc/debian/occlum-gcc.postinst +golang: deps_golang + cd $(DEB_BUILD_DIR)/occlum-toolchains-golang ; \ + dpkg-buildpackage -us -uc + cp -t $(TARGET_DIR) $(DEB_BUILD_DIR)/occlum-toolchains-golang*.deb + +deps_golang: + mkdir -p $(TARGET_DIR) + mkdir -p $(DEB_BUILD_DIR)/occlum-toolchains-golang + cp -r toolchains/golang $(DEB_BUILD_DIR)/occlum-toolchains-golang/debian + cp -t $(DEB_BUILD_DIR)/occlum-toolchains-golang/debian $(GO_PATCH) $(PROJECT_DIR)/tools/installer/rpm/toolchains/golang/occlum-go.sh + clean-build: rm -rf $(DEB_BUILD_DIR) clean: clean-build diff --git a/tools/installer/deb/toolchains/gcc/rules b/tools/installer/deb/toolchains/gcc/rules index 836c9653..d51f6fd3 100755 --- a/tools/installer/deb/toolchains/gcc/rules +++ b/tools/installer/deb/toolchains/gcc/rules @@ -40,7 +40,6 @@ prepare_musl: EOF override_dh_auto_build: prepare_musl - cd $(tmp_build_dir)/musl-cross-make cd $(tmp_build_dir)/musl-cross-make; \ make -j$(nproc) diff --git a/tools/installer/deb/toolchains/golang/changelog b/tools/installer/deb/toolchains/golang/changelog new file mode 100644 index 00000000..e5429c40 --- /dev/null +++ b/tools/installer/deb/toolchains/golang/changelog @@ -0,0 +1,5 @@ +occlum-toolchains-golang (0.16.0-1) unstable; urgency=medium + + * Initial release + + -- Chunyang Hui Tue, 18 Aug 2020 14:37:39 +0000 diff --git a/tools/installer/deb/toolchains/golang/compat b/tools/installer/deb/toolchains/golang/compat new file mode 100644 index 00000000..f599e28b --- /dev/null +++ b/tools/installer/deb/toolchains/golang/compat @@ -0,0 +1 @@ +10 diff --git a/tools/installer/deb/toolchains/golang/control b/tools/installer/deb/toolchains/golang/control new file mode 100644 index 00000000..9b948eee --- /dev/null +++ b/tools/installer/deb/toolchains/golang/control @@ -0,0 +1,12 @@ +Source: occlum-toolchains-golang +Section: libs +Priority: optional +Maintainer: Chunyang Hui +Build-Depends: debhelper (>=9), libfile-stripnondeterminism-perl (>= 0.028~), autoconf, automake, cmake, libtool, ocaml, ocamlbuild, python, libssl-dev, libcurl4-openssl-dev, libprotobuf-dev, git, protobuf-compiler +Standards-Version: 4.1.2 +Homepage: https://github.com/golang/go + +Package: occlum-toolchains-golang +Architecture: amd64 +Depends: ${misc:Depends}, ${shlibs:Depends} +Description: Occlum go toolchains diff --git a/tools/installer/deb/toolchains/golang/rules b/tools/installer/deb/toolchains/golang/rules new file mode 100755 index 00000000..18799d6c --- /dev/null +++ b/tools/installer/deb/toolchains/golang/rules @@ -0,0 +1,64 @@ +#!/usr/bin/make -f +export DH_VERBOSE = 1 +export deb_build_dir = /tmp/deb_build +export name = occlum-toolchains-golang +export buildroot := $(deb_build_dir)/$(name)/debian/$(name) + +export tmp_build_dir = $(deb_build_dir)/$(name)/tmp_build +export install_dir = $(buildroot)/opt/occlum/toolchains/golang + +SHELL = /bin/bash + +# Needed by musl-cross-make config +TARGET = x86_64-linux-musl +GCC_VER = 8.3.0 +GO_VERSION = 1.13.7 +GO_REPO = https://github.com/golang/go/archive/go$(GO_VERSION).tar.gz +GO_PATCH = adapt-golang-to-occlum.patch + +.ONESHELL: prepare override_dh_install + +%: + dh $@ + +# All rules executed in one shell +prepare: + rm -rf $(tmp_build_dir) + rm -rf $(install_dir) + mkdir -p $(tmp_build_dir) + cd $(tmp_build_dir) + wget $(GO_REPO) + tar -xvzf go$(GO_VERSION).tar.gz + cd go-go$(GO_VERSION) + patch -p1 < $(deb_build_dir)/$(name)/debian/$(GO_PATCH) + +override_dh_auto_build: prepare + cd $(tmp_build_dir)/go-go$(GO_VERSION)/src; \ + export GO_LDFLAGS="-compressdwarf=false"; \ + ./make.bash + +override_dh_install: + mkdir -p $(buildroot)/opt/occlum/toolchains + mv $(tmp_build_dir)/go-go$(GO_VERSION)/ $(install_dir) + rm -rf $(install_dir)/.git* + cat > $(install_dir)/bin/occlum-go < %{buildroot}%{INSTALL_DIR}/golang/bin/occlum-go < - 0.15.1-1 +- package init +* Wed Jul 22 2020 Chunmei Xu - 0.14.0-1 +- package init