You are not logged in.

#1 2017-07-25 12:07:41

vaneruni
Member
Registered: 2017-07-25
Posts: 2

[SOLVED] Binary file does not work after package() when using zeit/pkg

I have this PKGBUILD for a small app I've created for myself (to change media keys behavior for K290 keyboard).
This application is Node.js app, that uses zeit/pkg to create linux binary from the package.
The problem I'm having is that after the package is built binary file in $srcdir works as expected, while binary file in $pkgdir does not (showing me Node.js REPL).
I assume that the actual code of the application is being removed when makepkg strips "unneeded" symbols from binaries and libraries.
EDIT: Actually strip does remove actual application payload as discussed on github.com/zeit/pkg.
Is there any way to prevent makepkg from doing this step?

PKGBUILD:

pkgname=k290fn
pkgver=1.0.0
pkgrel=1
pkgdesc="Logitech K290 Fn-key utility"
arch=("x86_64")
makedepends=("nodejs" "npm")
source=(package.json
		index.js
		build.sh)
sha256sums=(4ff266206bade15a7803426712d0daa5abe9b54f035c88f550a92fa87e7184e3
			cc88a9bd73a4ec402569cade30075860d8387a4b2ce26f4ea5c7030e6ed90ea3
			ed11dcd7b908ce5f25934662620d5db15794f554b88ec4237d1fabca10638b3f)

build() {
	cd "$srcdir"
	npm i
	./build.sh
}

package() {
	cd "$srcdir"
	echo $pwd
	mkdir -p "$pkgdir"/opt/$pkgname
	install -Dm0744 pkg/index "$pkgdir"/opt/$pkgname/k290fn
	install -Dm0744 pkg/usb_bindings.node "$pkgdir"/opt/$pkgname/usb_bindings.node
}

index.js

const usb = require("usb");

const k290 = {
	idVendor: 0x046d,
	idProduct: 0xc31f
};

const reset = false;

function setFn(device, on) {
	if (device == null) {
		return console.log("Keyboard not found");
	}
	try {
		device.open();
	} catch (e) {
		if (e.errno === usb.LIBUSB_ERROR_ACCESS) {
			return console.log("You'll need higher permissions to work with USB devices.", e);
		}
		return console.log("Failed to open device", e);
	}
	device.controlTransfer(0x40, 2, 0x001a, on, Buffer.from([]), function (err, data) {
		if (err) {
			return console.log("Failed to set FN keys", err);
		}
		console.log("FN keys switched.");
		device.close();
	});
}

const devices = usb.getDeviceList();
const kbd = devices.find(function ({ deviceDescriptor }) {
	return deviceDescriptor.idVendor === k290.idVendor
		&& deviceDescriptor.idProduct === k290.idProduct;
});

setFn(kbd, reset ? 0 : 1);

buidl.sh

#!/usr/bin/env bash

usb=node_modules/usb/
bin=node_modules/.bin
pkg=$bin/pkg

mkdir -p pkg

cp $usb/build/Release/usb_bindings.node pkg/
$pkg -t linux --out-path pkg/  index.js

The idea of the patch for K290 keyboard belongs to Marcus Ilgner

Last edited by vaneruni (2017-07-25 12:30:43)

Offline

#2 2017-07-25 12:27:42

vaneruni
Member
Registered: 2017-07-25
Posts: 2

Re: [SOLVED] Binary file does not work after package() when using zeit/pkg

Found it myself.

Need to add options disabling strip to PKGBUILD, like so:

options=(!strip)

Offline

Board footer

Powered by FluxBB