app-emulation/containerd: fix ebuild for cross-compilation

This commit is contained in:
Nick Owens 2016-06-22 12:46:35 -07:00
parent 4b22ea1c82
commit 500038f2de
5 changed files with 365 additions and 3 deletions

View File

@ -2,8 +2,9 @@
# Distributed under the terms of the GNU General Public License v2 # Distributed under the terms of the GNU General Public License v2
# $Id$ # $Id$
EAPI=6 EAPI=5
EGO_PN="github.com/docker/${PN}" EGO_PN="github.com/docker/${PN}"
COREOS_GO_PACKAGE="${EGO_PN}"
if [[ ${PV} == *9999 ]]; then if [[ ${PV} == *9999 ]]; then
inherit golang-vcs inherit golang-vcs
@ -11,10 +12,12 @@ else
MY_PV="${PV/_/-}" MY_PV="${PV/_/-}"
EGIT_COMMIT="v${MY_PV}" EGIT_COMMIT="v${MY_PV}"
SRC_URI="https://${EGO_PN}/archive/${EGIT_COMMIT}.tar.gz -> ${P}.tar.gz" SRC_URI="https://${EGO_PN}/archive/${EGIT_COMMIT}.tar.gz -> ${P}.tar.gz"
KEYWORDS="amd64" KEYWORDS="amd64 arm64"
inherit golang-vcs-snapshot inherit golang-vcs-snapshot
fi fi
inherit coreos-go
DESCRIPTION="A daemon to control runC" DESCRIPTION="A daemon to control runC"
HOMEPAGE="https://containerd.tools" HOMEPAGE="https://containerd.tools"
@ -28,11 +31,23 @@ RDEPEND="app-emulation/runc
S=${WORKDIR}/${P}/src/${EGO_PN} S=${WORKDIR}/${P}/src/${EGO_PN}
PATCHES=(
"${FILESDIR}"/0001-Use-flag-for-aarch64-EpollCreate1.patch
"${FILESDIR}"/0002-archutils-epoll_aarch64-fix-C-formatting.patch
"${FILESDIR}"/0003-archutils-fix-build-on-aarch64.patch
"${FILESDIR}"/0004-Correct-build-flag-for-arm64.patch
)
src_prepare() { src_prepare() {
eapply_user epatch "${PATCHES[@]}"
} }
src_compile() { src_compile() {
export GOARCH=$(go_get_arch)
export CGO_ENABLED=1
export CC=$(tc-getCC)
export CXX=$(tc-getCXX)
local options=( $(usex seccomp "seccomp") ) local options=( $(usex seccomp "seccomp") )
export GOPATH="${WORKDIR}/${P}" # ${PWD}/vendor export GOPATH="${WORKDIR}/${P}" # ${PWD}/vendor
LDFLAGS= emake GIT_COMMIT="$EGIT_COMMIT" BUILDTAGS="${options[@]}" LDFLAGS= emake GIT_COMMIT="$EGIT_COMMIT" BUILDTAGS="${options[@]}"

View File

@ -0,0 +1,45 @@
From e419be223f415008f313e95d6d19f20398bdec9b Mon Sep 17 00:00:00 2001
From: Qiang Huang <h.huangqiang@huawei.com>
Date: Mon, 11 Apr 2016 15:01:36 +0800
Subject: [PATCH] Use flag for aarch64 EpollCreate1
Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
---
archutils/epoll_aarch64.go | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/archutils/epoll_aarch64.go b/archutils/epoll_aarch64.go
index b0ea48c..3984ac4 100644
--- a/archutils/epoll_aarch64.go
+++ b/archutils/epoll_aarch64.go
@@ -5,15 +5,15 @@ package archutils
// #include <sys/epoll.h>
/*
int EpollCreate1(int flag) {
- return epoll_create1(0);
+ return epoll_create1(flag);
}
-int EpollCtl(int efd, int op,int sfd, int Events, int Fd) {
+int EpollCtl(int efd, int op, int sfd, int Events, int Fd) {
struct epoll_event event;
event.events = Events;
event.data.fd = Fd;
- return epoll_ctl(efd,op,sfd,&event);
+ return epoll_ctl(efd, op, sfd, &event);
}
typedef struct Event{
@@ -41,7 +41,7 @@ import (
)
func EpollCreate1(flag int) (int, error) {
- fd := int(C.EpollCreate1(0))
+ fd := int(C.EpollCreate1(C.int(flag)))
if fd < 0 {
return fd, fmt.Errorf("failed to create epoll, errno is %d", fd)
}
--
2.8.3

View File

@ -0,0 +1,80 @@
From 1e617aaab4942faf8a354c7239f061300637e5b8 Mon Sep 17 00:00:00 2001
From: Aleksa Sarai <asarai@suse.de>
Date: Wed, 13 Apr 2016 16:08:28 +1000
Subject: [PATCH 2/2] archutils: epoll_aarch64: fix C formatting
Use proper C formatting to make the cgo code much easier to read. Also
remove the pointless typedef.
Signed-off-by: Aleksa Sarai <asarai@suse.de>
---
archutils/epoll_aarch64.go | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/archutils/epoll_aarch64.go b/archutils/epoll_aarch64.go
index 3984ac4..73cd8ed 100644
--- a/archutils/epoll_aarch64.go
+++ b/archutils/epoll_aarch64.go
@@ -5,31 +5,31 @@ package archutils
// #include <sys/epoll.h>
/*
int EpollCreate1(int flag) {
- return epoll_create1(flag);
+ return epoll_create1(flag);
}
-int EpollCtl(int efd, int op, int sfd, int Events, int Fd) {
- struct epoll_event event;
- event.events = Events;
- event.data.fd = Fd;
+int EpollCtl(int efd, int op,int sfd, int events, int fd) {
+ struct epoll_event event;
+ event.events = events;
+ event.data.fd = fd;
- return epoll_ctl(efd, op, sfd, &event);
+ return epoll_ctl(efd, op, sfd, &event);
}
-typedef struct Event{
- uint32_t events;
- int fd;
+struct event_t {
+ uint32_t events;
+ int fd;
};
struct epoll_event events[128];
-int run_epoll_wait(int fd, struct Event *event) {
- int n, i;
- n = epoll_wait(fd, events, 128, -1);
- for (i = 0; i < n; i++) {
- event[i].events = events[i].events;
- event[i].fd = events[i].data.fd;
- }
- return n;
+int run_epoll_wait(int fd, struct event_t *event) {
+ int n, i;
+ n = epoll_wait(fd, events, 128, -1);
+ for (i = 0; i < n; i++) {
+ event[i].events = events[i].events;
+ event[i].fd = events[i].data.fd;
+ }
+ return n;
}
*/
import "C"
@@ -57,8 +57,8 @@ func EpollCtl(epfd int, op int, fd int, event *syscall.EpollEvent) error {
}
func EpollWait(epfd int, events []syscall.EpollEvent, msec int) (int, error) {
- var c_events [128]C.struct_Event
- n := int(C.run_epoll_wait(C.int(epfd), (*C.struct_Event)(unsafe.Pointer(&c_events))))
+ var c_events [128]C.struct_event_t
+ n := int(C.run_epoll_wait(C.int(epfd), (*C.struct_event_t)(unsafe.Pointer(&c_events))))
if n < 0 {
return int(n), fmt.Errorf("Failed to wait epoll")
}
--
2.8.3

View File

@ -0,0 +1,39 @@
From 7c572f16734b69134b17c5f6c563d6d6a595e606 Mon Sep 17 00:00:00 2001
From: Aleksa Sarai <asarai@suse.de>
Date: Wed, 13 Apr 2016 19:29:20 +1000
Subject: [PATCH 3/3] archutils: fix build on aarch64
Due to an invalid architecture name (arm64), containerd could not build
on aarch64 machines. Fix this by using the correct name of the
architecture for conditional building.
Signed-off-by: Aleksa Sarai <asarai@suse.de>
---
archutils/epoll.go | 3 ++-
archutils/epoll_aarch64.go | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/archutils/epoll.go b/archutils/epoll.go
index 6922b52..6bb6047 100644
--- a/archutils/epoll.go
+++ b/archutils/epoll.go
@@ -1,4 +1,5 @@
-//+build !arm64,linux
+// +build linux,!aarch64
+
package archutils
import (
diff --git a/archutils/epoll_aarch64.go b/archutils/epoll_aarch64.go
index 73cd8ed..3d63147 100644
--- a/archutils/epoll_aarch64.go
+++ b/archutils/epoll_aarch64.go
@@ -1,4 +1,4 @@
-// +build arm64,linux
+// +build linux,aarch64
package archutils
--
2.8.3

View File

@ -0,0 +1,183 @@
From 313db3df26b12293e7d99eab0647f5222f195648 Mon Sep 17 00:00:00 2001
From: Qiang Huang <h.huangqiang@huawei.com>
Date: Fri, 29 Apr 2016 11:42:41 +0000
Subject: [PATCH 4/4] Correct build flag for arm64
On arm64, the default build flag is the same as the one from
`go env` which is arm64. So we should use arm64 instead of
aarch64 for both build flag and file name.
Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
---
archutils/epoll.go | 2 +-
archutils/epoll_aarch64.go | 70 ----------------------------------------------
archutils/epoll_arm64.go | 70 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 71 insertions(+), 71 deletions(-)
delete mode 100644 archutils/epoll_aarch64.go
create mode 100644 archutils/epoll_arm64.go
diff --git a/archutils/epoll.go b/archutils/epoll.go
index 6bb6047..c8ade64 100644
--- a/archutils/epoll.go
+++ b/archutils/epoll.go
@@ -1,4 +1,4 @@
-// +build linux,!aarch64
+// +build linux,!arm64
package archutils
diff --git a/archutils/epoll_aarch64.go b/archutils/epoll_aarch64.go
deleted file mode 100644
index 3d63147..0000000
--- a/archutils/epoll_aarch64.go
+++ /dev/null
@@ -1,70 +0,0 @@
-// +build linux,aarch64
-
-package archutils
-
-// #include <sys/epoll.h>
-/*
-int EpollCreate1(int flag) {
- return epoll_create1(flag);
-}
-
-int EpollCtl(int efd, int op,int sfd, int events, int fd) {
- struct epoll_event event;
- event.events = events;
- event.data.fd = fd;
-
- return epoll_ctl(efd, op, sfd, &event);
-}
-
-struct event_t {
- uint32_t events;
- int fd;
-};
-
-struct epoll_event events[128];
-int run_epoll_wait(int fd, struct event_t *event) {
- int n, i;
- n = epoll_wait(fd, events, 128, -1);
- for (i = 0; i < n; i++) {
- event[i].events = events[i].events;
- event[i].fd = events[i].data.fd;
- }
- return n;
-}
-*/
-import "C"
-
-import (
- "fmt"
- "syscall"
- "unsafe"
-)
-
-func EpollCreate1(flag int) (int, error) {
- fd := int(C.EpollCreate1(C.int(flag)))
- if fd < 0 {
- return fd, fmt.Errorf("failed to create epoll, errno is %d", fd)
- }
- return fd, nil
-}
-
-func EpollCtl(epfd int, op int, fd int, event *syscall.EpollEvent) error {
- errno := C.EpollCtl(C.int(epfd), C.int(syscall.EPOLL_CTL_ADD), C.int(fd), C.int(event.Events), C.int(event.Fd))
- if errno < 0 {
- return fmt.Errorf("Failed to ctl epoll")
- }
- return nil
-}
-
-func EpollWait(epfd int, events []syscall.EpollEvent, msec int) (int, error) {
- var c_events [128]C.struct_event_t
- n := int(C.run_epoll_wait(C.int(epfd), (*C.struct_event_t)(unsafe.Pointer(&c_events))))
- if n < 0 {
- return int(n), fmt.Errorf("Failed to wait epoll")
- }
- for i := 0; i < n; i++ {
- events[i].Fd = int32(c_events[i].fd)
- events[i].Events = uint32(c_events[i].events)
- }
- return int(n), nil
-}
diff --git a/archutils/epoll_arm64.go b/archutils/epoll_arm64.go
new file mode 100644
index 0000000..00abc68
--- /dev/null
+++ b/archutils/epoll_arm64.go
@@ -0,0 +1,70 @@
+// +build linux,arm64
+
+package archutils
+
+// #include <sys/epoll.h>
+/*
+int EpollCreate1(int flag) {
+ return epoll_create1(flag);
+}
+
+int EpollCtl(int efd, int op,int sfd, int events, int fd) {
+ struct epoll_event event;
+ event.events = events;
+ event.data.fd = fd;
+
+ return epoll_ctl(efd, op, sfd, &event);
+}
+
+struct event_t {
+ uint32_t events;
+ int fd;
+};
+
+struct epoll_event events[128];
+int run_epoll_wait(int fd, struct event_t *event) {
+ int n, i;
+ n = epoll_wait(fd, events, 128, -1);
+ for (i = 0; i < n; i++) {
+ event[i].events = events[i].events;
+ event[i].fd = events[i].data.fd;
+ }
+ return n;
+}
+*/
+import "C"
+
+import (
+ "fmt"
+ "syscall"
+ "unsafe"
+)
+
+func EpollCreate1(flag int) (int, error) {
+ fd := int(C.EpollCreate1(C.int(flag)))
+ if fd < 0 {
+ return fd, fmt.Errorf("failed to create epoll, errno is %d", fd)
+ }
+ return fd, nil
+}
+
+func EpollCtl(epfd int, op int, fd int, event *syscall.EpollEvent) error {
+ errno := C.EpollCtl(C.int(epfd), C.int(syscall.EPOLL_CTL_ADD), C.int(fd), C.int(event.Events), C.int(event.Fd))
+ if errno < 0 {
+ return fmt.Errorf("Failed to ctl epoll")
+ }
+ return nil
+}
+
+func EpollWait(epfd int, events []syscall.EpollEvent, msec int) (int, error) {
+ var c_events [128]C.struct_event_t
+ n := int(C.run_epoll_wait(C.int(epfd), (*C.struct_event_t)(unsafe.Pointer(&c_events))))
+ if n < 0 {
+ return int(n), fmt.Errorf("Failed to wait epoll")
+ }
+ for i := 0; i < n; i++ {
+ events[i].Fd = int32(c_events[i].fd)
+ events[i].Events = uint32(c_events[i].events)
+ }
+ return int(n), nil
+}
--
2.8.3