From patchwork Thu Feb 20 16:01:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Havelange X-Patchwork-Id: 1241515 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=busybox.net (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=essensium.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=essensium.com header.i=@essensium.com header.a=rsa-sha256 header.s=google header.b=UymnlZzP; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48NfV4468lz9sRN for ; Fri, 21 Feb 2020 03:01:48 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 5D6F18756D; Thu, 20 Feb 2020 16:01:45 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id E-U4tj21cVa9; Thu, 20 Feb 2020 16:01:42 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 2EF5D84332; Thu, 20 Feb 2020 16:01:42 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 969021BF9B3 for ; Thu, 20 Feb 2020 16:01:40 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 8A430203BA for ; Thu, 20 Feb 2020 16:01:40 +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 Jsb6+TqIgczv for ; Thu, 20 Feb 2020 16:01:39 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by silver.osuosl.org (Postfix) with ESMTPS id BB32A2034A for ; Thu, 20 Feb 2020 16:01:38 +0000 (UTC) Received: by mail-wm1-f68.google.com with SMTP id a6so2640509wme.2 for ; Thu, 20 Feb 2020 08:01:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=essensium.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rmljOPBOQc0pe/Nze/L287kiXF/klL7Xm0209PUfx0E=; b=UymnlZzPCB2DNmFXUL3TthRfdvdehf0OHvL1cd02b9jaaG3vtMXOhFy6DaV0KFgLSC +ndbkHx4nwtX86DxQY0gUt873L0nOnunmlwf/49QgA8Vr/v9+vLaIsErrjQ8Epgq8uwb FRRr6tF6jfF7+KT6pP+SBk76Q8s1/l+rI2D8s1lpnUrbEh2Ntcuw+8OybV+isjTDUAt1 RZwpqiGdcTsypuFBIxEVQfClfBchkj8I7wo+AUX72g6e9EgdZXnc45736ZsZJWuLPlvn z546NZil1MoExyXV2WE4CX31j+uOxQhde83gjKDr6iywl4hqOBqfWKgILLGsSjs/6y+Y SDSw== 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:mime-version :content-transfer-encoding; bh=rmljOPBOQc0pe/Nze/L287kiXF/klL7Xm0209PUfx0E=; b=B11QXZ4fAF2vDwFw7nB7dJnIpPTRWz1MK59FZ2TsgnnNr0U8t+1DZIHR/WEAeWAgbR yOu86VmiDgz1sBsvTmnYWPMlFuSThyKHvtvQ4ThrldfSlF1JGSYP1wpFQKwQe5hn3nsC TdwHts5KdGQalBoMCJ8zw69FHKO4yIYegnzmBXcQxipx/RbGYL7kVuhHCh3n/Iz/oASz NP+/WYyezvOWQNhWMA/bdtdSFgh5gwJsy4TF7TkWaWu2KPrjCgNTRZlHdITlidGFnM1X aRc0GPRH8MnpQonl33d2KZcqBWpe+JEkNDmC48Uy6Nsiu0IIcyhjHxN0/EZFu89TmyeJ qRwg== X-Gm-Message-State: APjAAAU85C037BVMFPX/scsinPlpaR9p0CBtaijXxL0UDi12Zv0WNRr5 AmIcOoh4zDWUmeL1aVpuVWApffqiUO7Gcg== X-Google-Smtp-Source: APXvYqwvOuq9BaNXfh0WHdiYFPMwr3/pC0yiv6HeLyVkObVPXEN1atp61iNsVtLMLXttSkpKmc0P1Q== X-Received: by 2002:a05:600c:114d:: with SMTP id z13mr5188451wmz.105.1582214496595; Thu, 20 Feb 2020 08:01:36 -0800 (PST) Received: from ph-ThinkPad-E560.local.ess-mail.com (ip-188-118-3-185.reverse.destiny.be. [188.118.3.185]) by smtp.gmail.com with ESMTPSA id h5sm5483691wmf.8.2020.02.20.08.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2020 08:01:35 -0800 (PST) From: Patrick Havelange To: buildroot@buildroot.org Date: Thu, 20 Feb 2020 17:01:10 +0100 Message-Id: <20200220160119.3407-1-patrick.havelange@essensium.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [Buildroot] [PATCH v3 01/10] package/pkg-cargo.mk: Introduce the cargo package infrastructure. X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas De Schampheleire , Patrick Havelange , Sam Voss , "Yann E . MORIN" , Thomas Petazzoni Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" In order to be package agnostic, the install phase is now using cargo instead of install. TARGET_CONFIGURE_OPTS is now also set when running cargo in order to support cross compiling C code within cargo. Signed-off-by: Patrick Havelange --- changes: v2 -> v3 (Sam Voss) - set TARGET_CONFIGURE_OPTS when running cargo This is the V3 of the previously posted series : http://patchwork.ozlabs.org/project/buildroot/list/?series=156166&state=%2A&archive=both A lot of changes following the buildroot developer meeting's decisions from February 2020. Needs to be applied on top of the rust 1.40 bump --- package/Makefile.in | 1 + package/pkg-cargo.mk | 92 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 package/pkg-cargo.mk diff --git a/package/Makefile.in b/package/Makefile.in index 285e2837ef..650d7c166e 100644 --- a/package/Makefile.in +++ b/package/Makefile.in @@ -426,3 +426,4 @@ include package/pkg-kernel-module.mk include package/pkg-waf.mk include package/pkg-golang.mk include package/pkg-meson.mk +include package/pkg-cargo.mk diff --git a/package/pkg-cargo.mk b/package/pkg-cargo.mk new file mode 100644 index 0000000000..35f7c15ad9 --- /dev/null +++ b/package/pkg-cargo.mk @@ -0,0 +1,92 @@ +################################################################################ +# Cargo package infrastructure +# +# This file implements an infrastructure that eases development of package +# .mk files for Cargo packages. It should be used for all packages that use +# Cargo as their build system. +# +# See the Buildroot documentation for details on the usage of this +# infrastructure +# +# In terms of implementation, this Cargo infrastructure requires the .mk file +# to only specify metadata information about the package: name, version, +# download URL, etc. +# +# We still allow the package .mk file to override what the different steps +# are doing, if needed. For example, if _BUILD_CMDS is already defined, +# it is used as the list of commands to perform to build the package, +# instead of the default Cargo behaviour. The package can also define some +# post operation hooks. +# +################################################################################ + +################################################################################ +# inner-cargo-package -- defines how the configuration, compilation and +# installation of a cargo package should be done, implements a few hooks +# to tune the build process for cargo specifities and calls the generic +# package infrastructure to generate the necessary make targets +# +# argument 1 is the lowercase package name +# argument 2 is the uppercase package name, including a HOST_ prefix +# for host packages +# argument 3 is the uppercase package name, without the HOST_ prefix +# for host packages +# argument 4 is the type (target or host) +################################################################################ + +define inner-cargo-package + +# We need host-rustc to run cargo +$(2)_DEPENDENCIES += host-rustc + +$(2)_CARGO_ENV = \ + CARGO_HOME=$(HOST_DIR)/share/cargo \ + $(TARGET_CONFIGURE_OPTS) + +$(2)_CARGO_MODE = $(if $(BR2_ENABLE_DEBUG),debug,release) + +ifeq ($(4),target) + $(2)_CARGO_TARGET_OPT = --target $$(RUSTC_TARGET_NAME) +endif + +# +# Build step. Only define it if not already defined by the package .mk +# file. +# +ifndef $(2)_BUILD_CMDS +define $(2)_BUILD_CMDS + $(TARGET_MAKE_ENV) $$($(2)_CARGO_ENV) \ + cargo build \ + --$$($(2)_CARGO_MODE) \ + $$($(2)_CARGO_TARGET_OPT) \ + --manifest-path $$(@D)/Cargo.toml +endef +endif + +# +# Target installation step. Only define it if not already defined by +# the package .mk file. +# +ifndef $(2)_INSTALL_TARGET_CMDS +define $(2)_INSTALL_TARGET_CMDS + $(TARGET_MAKE_ENV) $$($(2)_CARGO_ENV) \ + cargo install \ + --root $(TARGET_DIR)/usr/ \ + --bins \ + --path $$(@D) \ + $$($(2)_CARGO_TARGET_OPT) \ + --force +endef +endif + +# Call the generic package infrastructure to generate the necessary +# make targets +$(call inner-generic-package,$(1),$(2),$(3),$(4)) + +endef + +################################################################################ +# cargo-package -- the target generator macro for Cargo packages +################################################################################ + +cargo-package = $(call inner-cargo-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)