From patchwork Fri Jul 27 02:47:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cam Hutchison X-Patchwork-Id: 949972 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=xdna.net Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=xdna.net header.i=@xdna.net header.b="B/AY7bac"; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41cD6P1ldqz9s21 for ; Fri, 27 Jul 2018 12:52:59 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 932F92CAC4; Fri, 27 Jul 2018 02:52:56 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qVzOyf5NROG9; Fri, 27 Jul 2018 02:52:55 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 8CFC62DF3A; Fri, 27 Jul 2018 02:52:55 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 252331C2C08 for ; Fri, 27 Jul 2018 02:52:54 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 22FB288B18 for ; Fri, 27 Jul 2018 02:52:54 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lGpYfKefaRpK for ; Fri, 27 Jul 2018 02:52:53 +0000 (UTC) X-Greylist: delayed 00:05:12 by SQLgrey-1.7.6 Received: from mail-pl0-f65.google.com (mail-pl0-f65.google.com [209.85.160.65]) by hemlock.osuosl.org (Postfix) with ESMTPS id 8090688B08 for ; Fri, 27 Jul 2018 02:52:53 +0000 (UTC) Received: by mail-pl0-f65.google.com with SMTP id s17-v6so1669616plp.7 for ; Thu, 26 Jul 2018 19:52:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xdna.net; s=google; h=from:to:cc:subject:date:message-id; bh=AAtJX5VKwQOe7l0uHiY16x0CBIgFoGZMBpMXxdLOj/E=; b=B/AY7bacIFhgVhjC7Yx/zJnbWSKH5pZ2xni6j86BRwEaTdIwE1AKUxgqww1U2nAmvZ D4ZDj8wHScIGTNunGiJ8XpAke9CebfqD/VmrTb3V9wHkRZ39T3Dgaut23QPC2KgOc0fW G1x+mlzcS14HuOui5xHFBbxAEdVTzh8g2cwGg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=AAtJX5VKwQOe7l0uHiY16x0CBIgFoGZMBpMXxdLOj/E=; b=J0JS0QGzl1sztAKYfXfBwQuB/hg0+wpfCjOo/5NCXnvtqCQ4pJjapqR+76vvJST6UD vAoTx9cnm2Lct+VXMqe1aELk7iSgYs7XHQDBWYpl6YBELYO3hmfl90/dXesr3foIDpzr JBaTmVabJ3qfUtqyyZaRPmqKbuTmpPwWZGpX0HtleX+0t5JGi5tBNBycr2QoIJnksjgI 2xoNZWrY9ol4MEaJOky8Try6iu4Pv/AopfZR0JddDW4YN0Cp1F5qOj36ztGn4gBnmPII LF/HSvqi0dWP+eLkx1pAQ7iSg1AKE97jJKxUvkX0jLSp02wsvdJ0bloFfSc965OAYkIT QbXg== X-Gm-Message-State: AOUpUlFyV6aF0gizdy4hP8vRWHqEnMrS0iIeEoe/7p8zNIY6e43iuIFU Lx21xx7kqadAaGUKj2h2vvmkOygxipk= X-Google-Smtp-Source: AAOMgpelyg8WsxW8tvUerVyDxmQwitEu60vIb8t69XwPYDWYSN9FYS/XwUcEgl6aR48/faDlxMpFQQ== X-Received: by 2002:a17:902:a508:: with SMTP id s8-v6mr4312114plq.223.1532659661086; Thu, 26 Jul 2018 19:47:41 -0700 (PDT) Received: from xdna.net ([2403:5800:a001:4f::2]) by smtp.gmail.com with ESMTPSA id a20-v6sm3580963pfi.124.2018.07.26.19.47.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 19:47:40 -0700 (PDT) From: Cam Hutchison To: buildroot@buildroot.org Date: Fri, 27 Jul 2018 12:47:20 +1000 Message-Id: <20180727024720.13370-1-camh@xdna.net> X-Mailer: git-send-email 2.11.0 Subject: [Buildroot] [PATCH 1/1] pkg-golang: Allow per package/target CGO_ENABLED setting X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.24 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cam Hutchison , Thomas Petazzoni , Thomas De Schampheleire MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" Allow the CGO_ENABLED variable to be controlled per package and per build target, instead of having the value determined by whether or not the toolchain has threads. Some build targets may not build with CGO_ENABLED=1, so allowing a per package and build target override will allow those targets to be built with Buildroot. Signed-off-by: Cam Hutchison --- docs/manual/adding-packages-golang.txt | 14 ++++++++++++++ package/pkg-golang.mk | 17 +++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/docs/manual/adding-packages-golang.txt b/docs/manual/adding-packages-golang.txt index efcf696867..2683774861 100644 --- a/docs/manual/adding-packages-golang.txt +++ b/docs/manual/adding-packages-golang.txt @@ -99,6 +99,20 @@ therefore only use a few of them, or none. +FOO_BUILD_TARGETS = cmd/docker cmd/dockerd+ the binaries produced are +docker+ and +dockerd+. +* +FOO_CGO_ENABLED+ overrides the default value for the +CGO_ENABLED+ + flag passed to the Go compiler. By default +CGO_ENABLED+ is set + to 1 if the toolchain supports threads, but you can force it to + 0 for the package by setting this variable. If the toolchain does + not support threads and you set +FOO_CGO_ENABLED+ to 1, an error + will be generated. + +* +FOO_BUILD_TARGET_CGO_ENABLED_+ can be used to override + the +CGO_ENABLED+ flag passed to the Go compiler for a specific + build target, similar to +FOO_CGO_ENABLED+. ++ references + a target listed in +FOO_BUILD_TARGETS+. If the toolchain does + not support threads and you set this variable to 1, an error will + be generated. + * +FOO_INSTALL_BINS+ can be used to pass the list of binaries that should be installed in +/usr/bin+ on the target. If +FOO_INSTALL_BINS+ is not specified, it defaults to the lower-case diff --git a/package/pkg-golang.mk b/package/pkg-golang.mk index bf178622b5..2be3bd4c14 100644 --- a/package/pkg-golang.mk +++ b/package/pkg-golang.mk @@ -28,8 +28,20 @@ GO_BIN = $(HOST_DIR)/bin/go GO_TARGET_ENV = \ $(HOST_GO_TARGET_ENV) \ PATH=$(BR_PATH) \ - GOBIN= \ - CGO_ENABLED=$(HOST_GO_CGO_ENABLED) + GOBIN= + +# Allow CGO_ENABLED to be defined per package and per build target, but if +# CGO is enabled for a package or a build target and the toolchain does not +# support that, generate an error. +GO_CGO_ENABLED = $(strip \ + $(if $(filter 10,$($(1)_CGO_ENABLED)$(HOST_GO_CGO_ENABLED)),\ + $(error Toolchain does not support CGO_ENABLED=1 for package $(1)),\ + $(or $($(1)_CGO_ENABLED),$(HOST_GO_CGO_ENABLED)))) + +GO_TARGET_CGO_ENABLED = $(strip \ + $(if $(filter 10,$($(1)_BUILD_TARGET_CGO_ENABLED_$(2))$(HOST_GO_CGO_ENABLED)),\ + $(error Toolchain does not support CGO_ENABLED=1 for target $(2)),\ + $(or $($(1)_BUILD_TARGET_CGO_ENABLED_$(2)),$(call GO_CGO_ENABLED,$(1))))) ################################################################################ # inner-golang-package -- defines how the configuration, compilation and @@ -100,6 +112,7 @@ define $(2)_BUILD_CMDS $$(foreach d,$$($(2)_BUILD_TARGETS),\ cd $$($(2)_SRC_PATH); \ $$(GO_TARGET_ENV) \ + CGO_ENABLED=$$(call GO_TARGET_CGO_ENABLED,$(2),$$(d)) \ GOPATH="$$(@D)/$$($(2)_WORKSPACE)" \ $$($(2)_GO_ENV) \ $$(GO_BIN) build -v $$($(2)_BUILD_OPTS) \