From patchwork Fri Feb 14 12:48:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Havelange X-Patchwork-Id: 1238015 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.136; helo=silver.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=cyuBttML; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48JtVW46mbz9sRm for ; Fri, 14 Feb 2020 23:49:06 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 2E7B0220EC; Fri, 14 Feb 2020 12:49:02 +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 gLLGZxva0ler; Fri, 14 Feb 2020 12:48:59 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 499792153B; Fri, 14 Feb 2020 12:48:59 +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 2211B1BF3A0 for ; Fri, 14 Feb 2020 12:48:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 1976F87E56 for ; Fri, 14 Feb 2020 12:48:44 +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 OFtCas8l6nYO for ; Fri, 14 Feb 2020 12:48:42 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by hemlock.osuosl.org (Postfix) with ESMTPS id 8089C87D54 for ; Fri, 14 Feb 2020 12:48:42 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id m16so10741683wrx.11 for ; Fri, 14 Feb 2020 04:48:42 -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=lzHO0d2BqnGXC1Bu6abMwaL36wTkxb0o98k7kNqBOXI=; b=cyuBttMLliikOdAVbNm+dpweF0STj/Jwx83HofgjcxSFR4wlMIJOfRPnNZq8utebYj AAYaswvJkRepA0e7TsZ4sMCWYKqw75knom0h4QinFzHuuAq3dkE3a+wDvr7nTymF6nwM FpGGLNXAKcirq1EUQ81umt4ae0pFuLwTEGW+Sm0gKysrpEnrzCempSoAqpZkRfPC2diC fpniuWSCbLFGUs//22YkDFkFL5nftm2esW/bvvc37XQr5QNyhCJ5fEOXR2ihQimkFIHI sRM+Ms/d+owRt+J86cXawrwKzSWID97t86P6pVhL7jEdsEx82CQqMTSCIjFNq+TlRbVo D7gw== 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=lzHO0d2BqnGXC1Bu6abMwaL36wTkxb0o98k7kNqBOXI=; b=aSWRbKwh2omSPYHf4Tt9MEC3CMu3cBz5pm95H2iSQIFiZ2AuCh0BOiT4aURgGRwQN8 0C7lt7Q8fNyhgX+9Iw1/keG/P7LX9rkyDhp+KbmkyBTR1QT92Cv+3S8oHZFnLbXAkZGY PPeiYd7X7HL7xZzSYCA3gTOAvncY7DhnKYo07eW5fEs8NvHR0nfwFDWVlQQAR8uKYQoa sAl71edb6W5sYq8PG4X28BNIFXvW6FHwGZM2K+WTbt9JW+fET11v3gdwfx2N9zckc9ul N5rPSis+HSsOVZ5CW3AWVmB8P8id0Jw2TuZUsiPPSq2+eYWRqRIpaXjLwPWfanOdVzFd g1zw== X-Gm-Message-State: APjAAAX/w7hAY3etK04UhSP37ahIms4ieayN5QH7PgCHuICUa0Dad6GY z56tcpBsZNHjQua0rwp+QXZk0FFwvtwyIQ== X-Google-Smtp-Source: APXvYqz2TcH3S1JrS2Xseh5QylP0SW2g5bJgWqFIOmErdtpbPO0R0AfcBRaZmaGNnn0Ql3nVCMKpMg== X-Received: by 2002:a5d:438c:: with SMTP id i12mr3835303wrq.51.1581684520342; Fri, 14 Feb 2020 04:48:40 -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 o4sm6888928wrx.25.2020.02.14.04.48.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2020 04:48:39 -0800 (PST) From: Patrick Havelange To: buildroot@buildroot.org Date: Fri, 14 Feb 2020 13:48:18 +0100 Message-Id: <20200214124827.30767-1-patrick.havelange@essensium.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [Buildroot] [PATCH v2 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. Signed-off-by: Patrick Havelange --- This is the V2 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 | 89 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 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..2242f3a082 --- /dev/null +++ b/package/pkg-cargo.mk @@ -0,0 +1,89 @@ +################################################################################ +# 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 +$(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)