Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Marcuzzi <tom.marcuzzi@orolia.com>
To: buildroot@buildroot.org
Cc: Tom Marcuzzi <tom.marcuzzi@orolia.com>,
	Martin Bark <martin@barkynet.com>,
	thomas.petazzoni@bootlin.com,
	Daniel Price <daniel.price@gmail.com>
Subject: [Buildroot] [PATCH v2] packages/nodejs: install npm packages on host
Date: Tue, 25 Jan 2022 14:05:05 +0100	[thread overview]
Message-ID: <20220125130506.668690-1-tom.marcuzzi@orolia.com> (raw)
In-Reply-To: <20220119140703.12978-1-tom.marcuzzi@orolia.com>

Installing npm packages on host allows to use JavaScript tools that
runs on NodeJS (such as webpack) to build web applications.

Signed-off-by: Tom Marcuzzi <tom.marcuzzi@orolia.com>
---
Changes v1 -> v2:
  - Fixed indentation and help in Config.in.host
  - Corrected use of BR2_PACKAGE_HOST_NODEJS_MODULES_ADDITIONAL_DEPS
  - Rename HOST_NPM to NPMHOST to prevent check-package warning

 package/nodejs/Config.in.host | 32 ++++++++++++++++++++++++++++++++
 package/nodejs/nodejs.mk      | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/package/nodejs/Config.in.host b/package/nodejs/Config.in.host
index 4ceaf0c73e..0b67a59c55 100644
--- a/package/nodejs/Config.in.host
+++ b/package/nodejs/Config.in.host
@@ -16,3 +16,35 @@ config BR2_PACKAGE_HOST_NODEJS
 comment "host nodejs needs a host gcc >= 8"
 	depends on BR2_PACKAGE_HOST_QEMU_USER_ARCH_SUPPORTS
 	depends on !BR2_HOST_GCC_AT_LEAST_8
+
+if BR2_PACKAGE_HOST_NODEJS
+
+config BR2_PACKAGE_HOST_NODEJS_MODULES_ADDITIONAL
+	string "Additional modules"
+	help
+	  List of space-separated nodejs modules to install via npm
+	  on host. See https://npmjs.org/ to find modules and
+	  'npm help install' for available installation methods.
+	  For repeatable builds, download and save tgz files or
+	  clone git repos for the components you care about.
+
+	  Example:
+	  serialport uglify-js@1.3.4 /my/module/mymodule.tgz \
+	  git://github.com/someuser/somemodule.git#v1.2
+
+	  This would install the serialport module (at the newest
+	  version), the uglify-js module at 1.3.4, a module from a
+	  filesystem path, and a module from a git repository.
+
+config BR2_PACKAGE_HOST_NODEJS_MODULES_ADDITIONAL_DEPS
+	string "Additional module dependencies"
+	help
+	  List of space-separated buildroot recipes which must be
+	  built before your npms can be installed on host. For example,
+	  if in 'Additional modules' you specified 'node-curl' (see:
+	  https://github.com/jiangmiao/node-curl), you could then
+	  specify 'host-libcurl' here, to ensure that buildroot builds
+	  the host-libcurl package, and does so before building your node
+	  modules.
+
+endif
diff --git a/package/nodejs/nodejs.mk b/package/nodejs/nodejs.mk
index 727af6dc50..8a4a2ff0cf 100644
--- a/package/nodejs/nodejs.mk
+++ b/package/nodejs/nodejs.mk
@@ -10,7 +10,8 @@ NODEJS_SITE = http://nodejs.org/dist/v$(NODEJS_VERSION)
 NODEJS_DEPENDENCIES = host-qemu host-python3 host-nodejs c-ares \
 	libuv zlib nghttp2 \
 	$(call qstrip,$(BR2_PACKAGE_NODEJS_MODULES_ADDITIONAL_DEPS))
-HOST_NODEJS_DEPENDENCIES = host-icu host-libopenssl host-python3 host-zlib
+HOST_NODEJS_DEPENDENCIES = host-icu host-libopenssl host-python3 host-zlib \
+	$(call qstrip,$(BR2_PACKAGE_HOST_NODEJS_MODULES_ADDITIONAL_DEPS))
 NODEJS_INSTALL_STAGING = YES
 NODEJS_LICENSE = MIT (core code); MIT, Apache and BSD family licenses (Bundled components)
 NODEJS_LICENSE_FILES = LICENSE
@@ -96,6 +97,35 @@ NODEJS_HOST_TOOLS = $(NODEJS_HOST_TOOLS_V8) $(NODEJS_HOST_TOOLS_NODE)

 HOST_NODEJS_CXXFLAGS = $(HOST_CXXFLAGS) -DU_DISABLE_RENAMING=1

+#
+# Build the list of modules to install on host.
+#
+HOST_NODEJS_MODULES_LIST= $(call qstrip,\
+	$(BR2_PACKAGE_HOST_NODEJS_MODULES_ADDITIONAL))
+
+# Define NPMHOST for other packages to use
+NPMHOST = $(HOST_CONFIGURE_OPTS) \
+	LDFLAGS="$(HOST_LDFLAGS)" \
+	LD="$(HOST_CXX)" \
+	npm_config_arch=$(NODEJS_CPU) \
+	npm_config_target_arch=$(NODEJS_CPU) \
+	npm_config_build_from_source=true \
+	npm_config_nodedir=$(HOST_DIR)/nodejs-$(NODEJS_VERSION) \
+	npm_config_prefix=$(HOST_DIR)/usr \
+	npm_config_cache=$(HOST_DIR)/.npm-cache \
+	$(HOST_DIR)/bin/npm
+#
+# We can only call NPMHOST if there's something to install.
+#
+ifneq ($(HOST_NODEJS_MODULES_LIST),)
+define HOST_NODEJS_INSTALL_MODULES
+	# If you're having trouble with module installation, adding -d to the
+	# npm install call below and setting npm_config_rollback=false can both
+	# help in diagnosing the problem.
+	$(NPMHOST) install -g $(HOST_NODEJS_MODULES_LIST)
+endef
+endif
+
 define HOST_NODEJS_BUILD_CMDS
 	$(HOST_MAKE_ENV) PYTHON=$(HOST_DIR)/bin/python3 \
 		$(MAKE) -C $(@D) \
@@ -110,6 +140,8 @@ define HOST_NODEJS_INSTALL_CMDS
 	$(foreach f,$(NODEJS_HOST_TOOLS), \
 		$(INSTALL) -m755 -D $(@D)/out/Release/$(f) $(HOST_DIR)/bin/$(f)
 	)
+
+	$(HOST_NODEJS_INSTALL_MODULES)
 endef

 ifeq ($(BR2_i386),y)
--
2.25.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

  parent reply	other threads:[~2022-01-25 13:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-19 14:07 [Buildroot] [PATCH 1/1] packages/nodejs: install npm packages on host Tom Marcuzzi
2022-01-22 13:20 ` Thomas Petazzoni
2022-01-25 13:05 ` Tom Marcuzzi [this message]
2022-05-14 21:01   ` [Buildroot] [PATCH v2] " Yann E. MORIN
2022-07-28  7:44 ` [Buildroot] [PATCH 1/1] " Arnout Vandecappelle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220125130506.668690-1-tom.marcuzzi@orolia.com \
    --to=tom.marcuzzi@orolia.com \
    --cc=buildroot@buildroot.org \
    --cc=daniel.price@gmail.com \
    --cc=martin@barkynet.com \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox