bind: avoid header include cycles in generated ObjC code

The test in CL 87656 exposed the problem that an ObjC class C in
header C.h can't implement an interface I in I.h if I.h itself includes
C.h, resulting in an include cycle. Avoid the problem for now by
restricting the set of declared interfaces to the current package and
its imports. This is too strict, but simple and avoids any include
cycles.

Fixes the bind/objc SeqTest on iOS.

Change-Id: I2ff964593cb9e56994c42b68cc49eebe2f549217
Reviewed-on: https://go-review.googlesource.com/88818
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/bind/genobjc.go b/bind/genobjc.go
index 1470b56..92c39ab 100644
--- a/bind/genobjc.go
+++ b/bind/genobjc.go
@@ -1066,6 +1066,22 @@
 	}
 	pT := types.NewPointer(obj.Type())
 	for _, iface := range g.allIntf {
+		p := iface.obj.Pkg()
+		if g.Pkg != nil && g.Pkg != p {
+			// To avoid header include cycles, only declare implementation of interfaces
+			// from imported packages. TODO(elias.naur): Include every interface that
+			// doesn't introduce an include cycle.
+			found := false
+			for _, imp := range g.Pkg.Imports() {
+				if imp == p {
+					found = true
+					break
+				}
+			}
+			if !found {
+				continue
+			}
+		}
 		obj := iface.obj
 		if types.AssignableTo(pT, obj.Type()) {
 			n := fmt.Sprintf("%s%s", g.namePrefixOf(obj.Pkg()), obj.Name())