balena-io / etcher

Flash OS images to SD cards & USB drives, safely and easily.
https://etcher.io/
Apache License 2.0
29.32k stars 2.09k forks source link

How to skip building etcher-util binary #4256

Closed sukanka closed 2 months ago

sukanka commented 3 months ago

Hello, I'm one of the maintainers of the AUR package balena-etcher, And I built etcher from source for archlinux utilizing systemwide electron and node.

The build scripts are in AUR repo, mainly in the PKGBUILD

Below are the details:

  1. run package command
    npm install
    npm run package
  2. the built artifacts are in out/, within it balenaEtcher-linux-* looks like the package structure for deb and rpm
  3. I find there is an etcher-util appears in both out/balenaEtcher-linux-*/resources/ and out/sidecar. There is also a src dir in out/sidecar. From the compiling process below https://github.com/balena-io/etcher/blob/c748c2a9c022d1d61b44e70202d073b00cdbd08c/forge.sidecar.ts#L79-L98

It is equivalent to node util/api.js. So I wrote a wrapper named etcher-util to replace the binary file and it works fine.

Here is my problem: even though I can get rid of etcher-util binary in the built package, I have to build it in the building procedure. Is there any way that I can build only js scripts in out/sidecar/src but not the final binary file?

Thanks

sukanka commented 2 months ago

Finally, I solved this myself. Here is my patch.

diff --git a/forge.sidecar.ts b/forge.sidecar.ts
index fc34809..00d644f 100644
--- a/forge.sidecar.ts
+++ b/forge.sidecar.ts
@@ -77,23 +77,8 @@ function build(
        commands.push(['npm', ['rebuild', 'mountutils', `--arch=${arch}`]]);

        commands.push([
-           'pkg',
-           [
-               path.join(sourcesDir, 'util', 'api.js'),
-               '-c',
-               'pkg-sidecar.json',
-               // `--no-bytecode` so that we can cross-compile for arm64 on x64
-               '--no-bytecode',
-               '--public',
-               '--public-packages',
-               '"*"',
-               // always build for host platform and node version
-               // https://github.com/vercel/pkg-fetch/releases
-               '--target',
-               `node20-${arch}`,
-               '--output',
-               binPath,
-           ],
+           "install",
+           ['-Dm644', '/dev/null', binPath,]
        ]);
    });