Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/1] packages/nodejs: install npm packages on host
@ 2022-01-19 14:07 Tom Marcuzzi
  2022-01-22 13:20 ` Thomas Petazzoni
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Tom Marcuzzi @ 2022-01-19 14:07 UTC (permalink / raw)
  To: buildroot; +Cc: Tom Marcuzzi, Daniel Price, Martin Bark

Signed-off-by: Tom Marcuzzi <tom.marcuzzi@orolia.com>
---
 package/nodejs/Config.in.host | 32 ++++++++++++++++++++++++++++++++
 package/nodejs/nodejs.mk      | 31 +++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)

diff --git a/package/nodejs/Config.in.host b/package/nodejs/Config.in.host
index 4ceaf0c73e..601eb6e052 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.
+		  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. For example, if in
+		  'Additional modules' you specified 'node-curl' (see:
+		  https://github.com/jiangmiao/node-curl), you could then
+		  specify 'libcurl' here, to ensure that buildroot builds the
+		  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..a342d1c90f 100644
--- a/package/nodejs/nodejs.mk
+++ b/package/nodejs/nodejs.mk
@@ -96,6 +96,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 NPM for other packages to use
+HOST_NPM = $(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 NPM 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.
+	$(HOST_NPM) 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 +139,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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Buildroot] [PATCH 1/1] packages/nodejs: install npm packages on host
  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 ` [Buildroot] [PATCH v2] " Tom Marcuzzi
  2022-07-28  7:44 ` [Buildroot] [PATCH 1/1] " Arnout Vandecappelle
  2 siblings, 0 replies; 5+ messages in thread
From: Thomas Petazzoni @ 2022-01-22 13:20 UTC (permalink / raw)
  To: Tom Marcuzzi; +Cc: Martin Bark, Daniel Price, buildroot

Hello Tom,

On Wed, 19 Jan 2022 15:07:03 +0100
Tom Marcuzzi <tom.marcuzzi@orolia.com> wrote:

> Signed-off-by: Tom Marcuzzi <tom.marcuzzi@orolia.com>
> ---
>  package/nodejs/Config.in.host | 32 ++++++++++++++++++++++++++++++++
>  package/nodejs/nodejs.mk      | 31 +++++++++++++++++++++++++++++++
>  2 files changed, 63 insertions(+)

Thanks for your patch. Since the change is non-trivial, it would be
good to have some details in the commit log about the motivations for
the change. I suppose your build process at some point requires NodeJS
on the host ?

> diff --git a/package/nodejs/Config.in.host b/package/nodejs/Config.in.host
> index 4ceaf0c73e..601eb6e052 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"

Please don't indent options, so remove the leading tab on all those
lines.

> +		help
> +		  List of space-separated nodejs modules to install via npm.

Perhaps clarify that they will be installed for the host NodeJS.

> +		  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. For example, if in
> +		  'Additional modules' you specified 'node-curl' (see:
> +		  https://github.com/jiangmiao/node-curl), you could then
> +		  specify 'libcurl' here, to ensure that buildroot builds the
> +		  libcurl package, and does so before building your node
> +		  modules.

The libcurl example here is bad, because this
BR2_PACKAGE_HOST_NODEJS_MODULES_ADDITIONAL_DEPS option should only
contain host packages, and never target packages. So the example should
mention host-libcurl and not libcurl.

Also, this new option BR2_PACKAGE_HOST_NODEJS_MODULES_ADDITIONAL_DEPS
is not used anywhere. You forgot to change:

HOST_NODEJS_DEPENDENCIES = host-icu host-libopenssl host-python3 host-zlib

to:

HOST_NODEJS_DEPENDENCIES = host-icu host-libopenssl host-python3 host-zlib \
	$(call qstrip,(BR2_PACKAGE_HOST_NODEJS_MODULES_ADDITIONAL_DEPS))

Could you have a look at the above questions, so that we can resolve
the open points, and converge towards a solution that we can merge ?

Thanks a lot!

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Buildroot] [PATCH v2] packages/nodejs: install npm packages on host
  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
  2022-05-14 21:01   ` Yann E. MORIN
  2022-07-28  7:44 ` [Buildroot] [PATCH 1/1] " Arnout Vandecappelle
  2 siblings, 1 reply; 5+ messages in thread
From: Tom Marcuzzi @ 2022-01-25 13:05 UTC (permalink / raw)
  To: buildroot; +Cc: Tom Marcuzzi, Martin Bark, thomas.petazzoni, Daniel Price

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Buildroot] [PATCH v2] packages/nodejs: install npm packages on host
  2022-01-25 13:05 ` [Buildroot] [PATCH v2] " Tom Marcuzzi
@ 2022-05-14 21:01   ` Yann E. MORIN
  0 siblings, 0 replies; 5+ messages in thread
From: Yann E. MORIN @ 2022-05-14 21:01 UTC (permalink / raw)
  To: Tom Marcuzzi; +Cc: Daniel Price, Martin Bark, thomas.petazzoni, buildroot

Tom, All,

Sorry for the delay; here's a quick review...

On 2022-01-25 14:05 +0100, Tom Marcuzzi spake thusly:
> 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>
> ---
[--SNIP--]
> 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"

I know you modelled this after the equivalent code for the target
variant, but I think BR2_PACKAGE_HOST_NODEJS_MODULES_ADDITIONAL_DEPS
should have a dependency on BR2_PACKAGE_HOST_NODEJS_MODULES_ADDITIONAL
not being empty (and a similar dependency should be added for the target
case), something like:

    depends on BR2_PACKAGE_HOST_NODEJS_MODULES_ADDITIONAL != ""

[--SNIP--]
> 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
[--SNIP--]
> @@ -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) \

NODEJS_CPU is the target CPU. This is most probably incorrect for the
host npm. You can use $(HOSTARCH) to decide what kind of CPU to use,
something like:

    ifeq ($(HOSTARCH),x86)
    HOST_NODEJS_CPU = ia32
    else ifeq ($(HOSTARCH),x86_64)
    HOST_NODEJS_CPU = x84
    ...
    fi

Or maybe we just don't need it at all, since we do not specify it at all
when configuring the host nodejs...

> +	npm_config_build_from_source=true \
> +	npm_config_nodedir=$(HOST_DIR)/nodejs-$(NODEJS_VERSION) \

For the target variant, we point that to the nodejs build directory:

    npm_config_nodedir=$(BUILD_DIR)/nodejs-$(NODEJS_VERSION)

So for the host we should probably do something similar:

    npm_config_nodedir=$(BUILD_DIR)/host-nodejs-$(NODEJS_VERSION)

Otherwise, please explain that in the commit log.

And note that it should probably be better to use the actual variable:

    npm_config_nodedir=$(HOST_NODEJS_BUILDDIR)

and that the target variant should probably also be fixed.

> +	npm_config_prefix=$(HOST_DIR)/usr \
> +	npm_config_cache=$(HOST_DIR)/.npm-cache \

Ditto, this should point to $(BUILD_DIR)/.host-npm-cache

Regards,
Yann E. MORIN.

> +	$(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

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Buildroot] [PATCH 1/1] packages/nodejs: install npm packages on host
  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 ` [Buildroot] [PATCH v2] " Tom Marcuzzi
@ 2022-07-28  7:44 ` Arnout Vandecappelle
  2 siblings, 0 replies; 5+ messages in thread
From: Arnout Vandecappelle @ 2022-07-28  7:44 UTC (permalink / raw)
  To: Tom Marcuzzi, buildroot; +Cc: Daniel Price, Martin Bark

  Hi Tom,

On 19/01/2022 15:07, Tom Marcuzzi wrote:
> Signed-off-by: Tom Marcuzzi <tom.marcuzzi@orolia.com>
> ---
>   package/nodejs/Config.in.host | 32 ++++++++++++++++++++++++++++++++
>   package/nodejs/nodejs.mk      | 31 +++++++++++++++++++++++++++++++
>   2 files changed, 63 insertions(+)
> 
> diff --git a/package/nodejs/Config.in.host b/package/nodejs/Config.in.host
> index 4ceaf0c73e..601eb6e052 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.
> +		  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. For example, if in
> +		  'Additional modules' you specified 'node-curl' (see:
> +		  https://github.com/jiangmiao/node-curl), you could then
> +		  specify 'libcurl' here, to ensure that buildroot builds the
> +		  libcurl package, and does so before building your node
> +		  modules.
> +
> +endif

  After a bit of deliberation, we decided that the existing 
BR2_PACKAGE_NODEJS_MODULES_ADDITIONAL is in fact a bit of a mistake. It is was 
introduced back then because we thought that you would typically want to install 
hundreds of npm packages on your system, and we wouldn't want to have buildroot 
packages for all of them.

  However, in reality, this is not the case. What happens in reality is that you 
have just one, maximum a few nodejs applications, and their packages.json pulls 
in the 100s of dependencies.

  Also, what we've learned from cargo and go, is that we can apply the vendoring 
to the package itself (or rather, the language infrastructure already does that) 
and we don't need to create all those packages as buildroot packages.

  In conclusion, the proper way going forward is to create a host-webpack 
package using the generic-package infrastructure. It should be implemented as 
follows:

- use the existing download infrastructure to download the source (from github, 
not from npm);

- in the build step, call "npm build" to download all the dependencies and 
create the bundle;

- in the install step, either call "npm install" or (probably easier) manually 
install things to $(HOST_DIR).


  Of course, it is wrong to download things in the build step, but that's anyway 
what happens with BR2_PACKAGE_NODEJS_MODULES_ADDITIONAL, and it's also what used 
to happen with cargo and go before we implemented the vendoring. Once we have a 
(or a few) example npm packages, we can look into implementing vendoring for npm 
as well.


  Also, once we have a few npm packages, we could consider adding npm-package 
infra to make this easier. I'm not sure if we're going to get there, however, 
because usually I think people will use their own npm applications which are 
kept in an external, and there aren't that many applications that would ever be 
packaged in buildroot itself. NodeRED is one, I guess.


  Anyway, I realize that we're asking you to do more work. Do you think you 
could make a package for host-webpack?


  Regards,
  Arnout



> diff --git a/package/nodejs/nodejs.mk b/package/nodejs/nodejs.mk
> index 727af6dc50..a342d1c90f 100644
> --- a/package/nodejs/nodejs.mk
> +++ b/package/nodejs/nodejs.mk
> @@ -96,6 +96,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 NPM for other packages to use
> +HOST_NPM = $(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 NPM 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.
> +	$(HOST_NPM) 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 +139,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)
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-07-28  7:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [Buildroot] [PATCH v2] " Tom Marcuzzi
2022-05-14 21:01   ` Yann E. MORIN
2022-07-28  7:44 ` [Buildroot] [PATCH 1/1] " Arnout Vandecappelle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox