Skip to content

Commit a3ffeb5

Browse files
committed
action for building and releasing drm
1 parent 5154005 commit a3ffeb5

7 files changed

Lines changed: 128 additions & 11 deletions

File tree

.github/workflows/release.yml

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,60 @@ jobs:
2121
body: This is an automated release for ${{ github.ref }}. It will be used to speed up `npm install`.
2222
env:
2323
GITHUB_TOKEN: ${{ github.token }}
24+
linux-arm-drm:
25+
runs-on: ubuntu-latest
26+
needs: create_release
27+
steps:
28+
- name: checkout
29+
uses: actions/checkout@v2
30+
with:
31+
fetch-depth: 0
32+
- name: Set up QEMU
33+
uses: docker/setup-qemu-action@v2
34+
- name: Cache Node Dependencies
35+
id: cache
36+
uses: actions/cache@v2
37+
with:
38+
path: ./node_modules
39+
key: modules-${{ hashFiles('package-lock.json') }}
40+
- name: Build for arm
41+
run: docker run --platform linux/arm --rm -v "${PWD}:/work" -w /work node ./tools/crossbuild-drm.sh
42+
- name: upload linux artifact
43+
uses: actions/upload-release-asset@v1
44+
env:
45+
GITHUB_TOKEN: ${{ github.token }}
46+
with:
47+
upload_url: ${{ needs.create_release.outputs.upload_url }}
48+
asset_path: ./build/Release/node-raylib.node
49+
asset_name: node-raylib-linux-arm-drm.node
50+
asset_content_type: application/octet-stream
51+
linux-arm64-drm:
52+
runs-on: ubuntu-latest
53+
needs: create_release
54+
steps:
55+
- name: checkout
56+
uses: actions/checkout@v2
57+
with:
58+
fetch-depth: 0
59+
- name: Set up QEMU
60+
uses: docker/setup-qemu-action@v2
61+
- name: Cache Node Dependencies
62+
id: cache
63+
uses: actions/cache@v2
64+
with:
65+
path: ./node_modules
66+
key: modules-${{ hashFiles('package-lock.json') }}
67+
- name: Build for arm
68+
run: docker run --platform linux/arm64 --rm -v "${PWD}:/work" -w /work node ./tools/crossbuild-drm.sh
69+
- name: upload linux artifact
70+
uses: actions/upload-release-asset@v1
71+
env:
72+
GITHUB_TOKEN: ${{ github.token }}
73+
with:
74+
upload_url: ${{ needs.create_release.outputs.upload_url }}
75+
asset_path: ./build/Release/node-raylib.node
76+
asset_name: node-raylib-linux-arm64-drm.node
77+
asset_content_type: application/octet-stream
2478
linux-arm:
2579
runs-on: ubuntu-latest
2680
needs: create_release
@@ -46,7 +100,7 @@ jobs:
46100
with:
47101
upload_url: ${{ needs.create_release.outputs.upload_url }}
48102
asset_path: ./build/Release/node-raylib.node
49-
asset_name: node-raylib-4.0-linux-arm.node
103+
asset_name: node-raylib-linux-arm.node
50104
asset_content_type: application/octet-stream
51105
linux-arm64:
52106
runs-on: ubuntu-latest
@@ -73,7 +127,7 @@ jobs:
73127
with:
74128
upload_url: ${{ needs.create_release.outputs.upload_url }}
75129
asset_path: ./build/Release/node-raylib.node
76-
asset_name: node-raylib-4.0-linux-arm64.node
130+
asset_name: node-raylib-linux-arm64.node
77131
asset_content_type: application/octet-stream
78132
linux:
79133
runs-on: ubuntu-latest
@@ -103,7 +157,7 @@ jobs:
103157
with:
104158
upload_url: ${{ needs.create_release.outputs.upload_url }}
105159
asset_path: ./build/Release/node-raylib.node
106-
asset_name: node-raylib-4.0-linux-x64.node
160+
asset_name: node-raylib-linux-x64.node
107161
asset_content_type: application/octet-stream
108162
windows:
109163
runs-on: windows-latest
@@ -131,7 +185,7 @@ jobs:
131185
with:
132186
upload_url: ${{ needs.create_release.outputs.upload_url }}
133187
asset_path: ./build/Release/node-raylib.node
134-
asset_name: node-raylib-4.0-win32-x64.node
188+
asset_name: node-raylib-win32-x64.node
135189
asset_content_type: application/octet-stream
136190
macos:
137191
runs-on: macos-latest
@@ -159,5 +213,5 @@ jobs:
159213
with:
160214
upload_url: ${{ needs.create_release.outputs.upload_url }}
161215
asset_path: ./build/Release/node-raylib.node
162-
asset_name: node-raylib-4.0-darwin-x64.node
216+
asset_name: node-raylib-darwin-x64.node
163217
asset_content_type: application/octet-stream

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
strategy:
88
fail-fast: false
99
matrix:
10-
node-version: [14.x, 16.x, 18.x]
10+
node-version: [18.x]
1111
os: [ubuntu, macos, windows]
1212
runs-on: ${{ matrix.os }}-latest
1313
steps:

drm/index.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* node-raylib
3+
*
4+
* https://github.com/robloach/node-raylib
5+
*/
6+
7+
const raylib = require('../src/generated/node-raylib-drm')
8+
const { format } = require('util')
9+
10+
// Constants
11+
raylib.MAX_GAMEPADS = 4
12+
raylib.MAX_GAMEPAD_AXIS = 8
13+
raylib.MAX_GAMEPAD_BUTTONS = 32
14+
raylib.MAX_TOUCH_POINTS = 10
15+
raylib.MAX_KEY_PRESSED_QUEUE = 16
16+
raylib.DEG2RAD = Math.PI / 180
17+
// Wrapped Functions
18+
19+
/**
20+
* Text formatting with variables (sprintf style)
21+
*/
22+
raylib.TextFormat = format
23+
24+
/**
25+
* Define one vertex (color) - 4 byte
26+
* @param {number} r
27+
* @param {number} g
28+
* @param {number} b
29+
* @param {number} a
30+
*/
31+
raylib.rlColor4ub = (r, g, b, a) => {
32+
// workaround as the C addon version isn't compiling?
33+
raylib.rlColor4f(r / 255, g / 255, b / 255, a / 255)
34+
}
35+
// Export the bindings for the module.
36+
module.exports = raylib

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
"CMakeLists.txt",
5454
"index.js",
5555
"CHANGELOG.md",
56-
"tools/postinstall.js"
56+
"tools/postinstall.js",
57+
"drm/*"
5758
],
5859
"bugs": {
5960
"url": "https://github.com/RobLoach/node-raylib/issues"

tools/crossbuild-drm.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
# this is used inside a docker (running with qemu binfmt) to easily crossbuild project
4+
# run with docker run --platform linux/arm64 -it --rm -v "${PWD}:/work" -w /work node ./tools/crossbuild.sh
5+
6+
apt-get update
7+
apt-get install -y xorg-dev libglu1-mesa-dev cmake
8+
npm ci
9+
npm run compile-drm

tools/crossbuild.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66
apt-get update
77
apt-get install -y xorg-dev libglu1-mesa-dev cmake
88
npm ci
9-
npm run compile
10-
npm run compile-drm
9+
npm run compile

tools/postinstall.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { promises: fs } = require('fs')
55
const path = require('path')
66
const fetch = require('cross-fetch')
77

8-
const targetPath = path.join(__dirname, '..', 'build', 'Release', 'node-raylib.node')
8+
let targetPath = path.join(__dirname, '..', 'build', 'Release', 'node-raylib.node')
99

1010
function toBuffer (ab) {
1111
const buf = Buffer.alloc(ab.byteLength)
@@ -31,7 +31,7 @@ async function main () {
3131
process.exit(0)
3232
}
3333

34-
const url = `https://github.com/RobLoach/node-raylib/releases/download/v${process.env.npm_package_version}/node-raylib-4.0-${process.platform}-${process.arch}.node`
34+
let url = `https://github.com/RobLoach/node-raylib/releases/download/v${process.env.npm_package_version}/node-raylib-${process.platform}-${process.arch}.node`
3535

3636
console.log(`Checking for ${url}`)
3737

@@ -57,6 +57,24 @@ async function main () {
5757
console.error(e.message)
5858
}
5959

60+
if (process.arch == 'arm' || process.arch == 'arm64') {
61+
targetPath = path.join(__dirname, '..', 'build', 'Release', 'node-raylib-drm.node')
62+
url = `https://github.com/RobLoach/node-raylib/releases/download/v${process.env.npm_package_version}/node-raylib-${process.platform}-${process.arch}-drm.node`
63+
try {
64+
const data = await fetch(url).then(r => {
65+
if (r.status !== 200) {
66+
throw new Error(`Status: ${r.status}`)
67+
}
68+
return r
69+
}).then(r => r.arrayBuffer())
70+
await fs.writeFile(targetPath, toBuffer(data))
71+
console.log('Found DRM on releases.')
72+
process.exit(0)
73+
} catch (e) {
74+
console.error(e.message)
75+
}
76+
}
77+
6078
// couldn't find it, so tell postinstall to compile it
6179
console.log('Not found. Building.')
6280
process.exit(1)

0 commit comments

Comments
 (0)