]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
cgo-helloworld: init add
authorChangqing Li <changqing.li@windriver.com>
Wed, 20 May 2026 02:52:28 +0000 (10:52 +0800)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 28 May 2026 10:21:53 +0000 (11:21 +0100)
* Add a go example recipe with cgo enabled, Flush the stdio buffer so
  that piped stdout can read the output before the program exits.

  This is for covering go reproducibility with cgo enabled. The test
  coverage is provided by the reproducibility world build.

  Related to the following commit [1]:
  [0642d23230 go.bbclass: change GOTMPDIR to improve reproducibility]

* cgo-helloworld is a complement for go-helloworld, also add it in
  runtime case for go and gotools

[1] https://git.openembedded.org/openembedded-core/commit/?id=0642d2323072f561a4d0eeb9266213387b2997fc

[YOCTO #16100]

Signed-off-by: Changqing Li <changqing.li@windriver.com>
Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/conf/distro/include/maintainers.inc
meta/lib/oeqa/runtime/cases/go.py
meta/recipes-core/packagegroups/packagegroup-core-tools-testapps.bb
meta/recipes-extended/go-examples/cgo-helloworld/cgo-helloworld.go [new file with mode: 0644]
meta/recipes-extended/go-examples/cgo-helloworld_1.0.bb [new file with mode: 0644]

index fdfdec28b5d159fa6f21945d77004efea4c69e23..b2d974a85e117b674dbd32246b15f45eec1dd012 100644 (file)
@@ -97,6 +97,7 @@ RECIPE_MAINTAINER:pn-cargo = "Randy MacLeod <Randy.MacLeod@windriver.com>"
 RECIPE_MAINTAINER:pn-cargo-c = "Deepesh Varatharajan <Deepesh.Varatharajan@windriver.com>"
 RECIPE_MAINTAINER:pn-ccache = "Robert Yang <liezhi.yang@windriver.com>"
 RECIPE_MAINTAINER:pn-cdrtools-native = "Yi Zhao <yi.zhao@windriver.com>"
+RECIPE_MAINTAINER:pn-cgo-helloworld = "Changqing Li <changqing.li@windriver.com>"
 RECIPE_MAINTAINER:pn-chrpath = "Yi Zhao <yi.zhao@windriver.com>"
 RECIPE_MAINTAINER:pn-clang = "Khem Raj <raj.khem@gmail.com>"
 RECIPE_MAINTAINER:pn-clang-cross-${TARGET_ARCH} = "Khem Raj <raj.khem@gmail.com>"
index 0c9c4ff4cd3205d318c54e90a627aa7a00604223..6e7a9bcd94150f3997985b87436c0f0d84b0484c 100644 (file)
@@ -85,3 +85,15 @@ class GoHelloworldTest(OERuntimeTestCase):
 
         msg = 'Incorrect output: %s' % output
         self.assertEqual(output, "Hello, world!", msg=msg)
+
+class CgoHelloworldTest(OERuntimeTestCase):
+    @OETestDepends(['ssh.SSHTest.test_ssh'])
+    @OEHasPackage(['cgo-helloworld'])
+    def test_cgohelloworld(self):
+        cmd = "cgo-helloworld"
+        status, output = self.target.run(cmd)
+        msg = 'Exit status was not 0. Output: %s' % output
+        self.assertEqual(status, 0, msg=msg)
+
+        msg = 'Incorrect output: %s' % output
+        self.assertEqual(output, "Hello, world!", msg=msg)
index 25561f6878f80c9fa0c9ea9ef07d8249682e6ec1..d6bed8d32ca360d4022d8396e0af4cecf5d9e014 100644 (file)
@@ -21,7 +21,10 @@ KEXECTOOLS:loongarch64 ?= ""
 # go does not support ppc32, only ppc64
 # https://github.com/golang/go/issues/22885
 # gccgo may do better
-GOTOOLS ?= "go-helloworld"
+GOTOOLS ?= "\
+    go-helloworld \
+    cgo-helloworld \
+    "
 GOTOOLS:powerpc ?= ""
 GOTOOLS:riscv32 ?= ""
 
diff --git a/meta/recipes-extended/go-examples/cgo-helloworld/cgo-helloworld.go b/meta/recipes-extended/go-examples/cgo-helloworld/cgo-helloworld.go
new file mode 100644 (file)
index 0000000..0c1f9d4
--- /dev/null
@@ -0,0 +1,9 @@
+package main
+
+// #include <stdio.h>
+// void hello() { printf("Hello, world!\n"); fflush(stdout);}
+import "C"
+
+func main() {
+       C.hello()
+}
diff --git a/meta/recipes-extended/go-examples/cgo-helloworld_1.0.bb b/meta/recipes-extended/go-examples/cgo-helloworld_1.0.bb
new file mode 100644 (file)
index 0000000..9ca1e16
--- /dev/null
@@ -0,0 +1,23 @@
+SUMMARY = "A simple CGO example that calls C to print hello world"
+SECTION = "examples"
+HOMEPAGE = "https://golang.org/"
+
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
+
+SRC_URI = "file://cgo-helloworld.go"
+
+S = "${UNPACKDIR}"
+
+GO_IMPORT = "cgo-helloworld"
+GO_INSTALL = "${GO_IMPORT}"
+
+inherit go
+
+export GO111MODULE = "off"
+export CGO_ENABLED = "1"
+
+do_configure:prepend() {
+    mkdir -p ${S}/src/${GO_IMPORT}
+    cp ${UNPACKDIR}/cgo-helloworld.go ${S}/src/${GO_IMPORT}/main.go
+}