Skip to content

Commit

Permalink
fix: build and embedded binary
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed May 8, 2024
1 parent 114d180 commit d4d322c
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 40 deletions.
6 changes: 6 additions & 0 deletions .changeset/fast-crabs-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'renterd': patch
'hostd': patch
---

Fixed an issue with the binary embedding.
6 changes: 6 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ jobs:
- name: Build
run: yarn workspace ${{ matrix.app }} build
shell: bash
- name: Download daemon binary
run: yarn workspace ${{ matrix.app }} download:binary
shell: bash
- name: Package executable bundles, sign and notarize, make distributables
env:
APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
Expand All @@ -78,6 +81,9 @@ jobs:
- name: Build
run: yarn workspace ${{ matrix.app }} build
shell: bash
- name: Download daemon binary
run: yarn workspace ${{ matrix.app }} download:binary
shell: bash
- name: Package executable bundles, make distributables
run: yarn workspace ${{ matrix.app }} make --arch=arm64,x64
shell: bash
Expand Down
1 change: 1 addition & 0 deletions hostd/forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
appleApiKeyId: process.env.APPLE_API_KEY,
appleApiIssuer: process.env.APPLE_API_ISSUER,
},
extraResource: ['bin'],
icon: './assets/icons/icon',
},
rebuildConfig: {},
Expand Down
17 changes: 13 additions & 4 deletions hostd/main/asset.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import path from 'path'
import { env } from './env'

export function getResourcePath(name: string) {
return path.join(process.resourcesPath, name)
}

export function getResourceAsarPath(name: string) {
return getResourcePath(path.join('app.asar', name))
}

export function getResourceAsarUnpackedPath(name: string) {
return getResourcePath(path.join('app.asar.unpacked', name))
}

export function getAsset(name: string) {
return env.isDev
? path.join(process.cwd(), 'assets', name)
: path.join(__dirname, '../assets', name)
return getResourceAsarPath(path.join('assets', name))
}
6 changes: 2 additions & 4 deletions hostd/main/binary.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import * as path from 'path'
import { env } from './env'
import { getResourcePath } from './asset'

export function getBinaryDirectoryPath(): string {
return env.isDev
? path.join(process.cwd(), 'bin')
: path.join(__dirname, '../bin')
return getResourcePath('bin')
}

export function getBinaryFilePath(): string {
Expand Down
6 changes: 3 additions & 3 deletions hostd/main/window.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path, { join } from 'path'
import { join } from 'path'
import { BrowserWindow, app } from 'electron'
import { format } from 'url'
import { state } from './state'
import { system } from './system'
import { getAsset } from './asset'
import { getAsset, getResourceAsarPath } from './asset'
import { env } from './env'

export function initWindow() {
Expand All @@ -30,7 +30,7 @@ export function initWindow() {
const url = env.isDev
? 'http://localhost:8000/'
: format({
pathname: path.join(__dirname, '../../renderer/out/index.html'),
pathname: getResourceAsarPath('renderer/out/index.html'),
protocol: 'file:',
slashes: true,
})
Expand Down
9 changes: 0 additions & 9 deletions hostd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,5 @@
"postcss": "^8.4.31",
"rimraf": "^3.0.2",
"typescript": "5.0.3"
},
"build": {
"icon": "assets/appicon.png",
"asar": true,
"files": [
"dist",
"assets",
"bin"
]
}
}
1 change: 1 addition & 0 deletions renterd/forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
appleApiKeyId: process.env.APPLE_API_KEY,
appleApiIssuer: process.env.APPLE_API_ISSUER,
},
extraResource: ['bin'],
icon: './assets/icons/icon',
},
rebuildConfig: {},
Expand Down
17 changes: 13 additions & 4 deletions renterd/main/asset.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import path from 'path'
import { env } from './env'

export function getResourcePath(name: string) {
return path.join(process.resourcesPath, name)
}

export function getResourceAsarPath(name: string) {
return getResourcePath(path.join('app.asar', name))
}

export function getResourceAsarUnpackedPath(name: string) {
return getResourcePath(path.join('app.asar.unpacked', name))
}

export function getAsset(name: string) {
return env.isDev
? path.join(process.cwd(), 'assets', name)
: path.join(__dirname, '../assets', name)
return getResourceAsarPath(path.join('assets', name))
}
6 changes: 2 additions & 4 deletions renterd/main/binary.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import * as path from 'path'
import { env } from './env'
import { getResourcePath } from './asset'

export function getBinaryDirectoryPath(): string {
return env.isDev
? path.join(process.cwd(), 'bin')
: path.join(__dirname, '../bin')
return getResourcePath('bin')
}

export function getBinaryFilePath(): string {
Expand Down
1 change: 1 addition & 0 deletions renterd/main/daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export async function startDaemon(): Promise<void> {
await stopDaemon()
const config = getConfig()
const binaryFilePath = getBinaryFilePath()

state.daemon = spawn(binaryFilePath, [], {
env: { ...process.env, RENTERD_CONFIG_FILE: getConfigFilePath() },
cwd: config.directory,
Expand Down
6 changes: 3 additions & 3 deletions renterd/main/window.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path, { join } from 'path'
import { join } from 'path'
import { BrowserWindow, app } from 'electron'
import { format } from 'url'
import { state } from './state'
import { system } from './system'
import { getAsset } from './asset'
import { getAsset, getResourceAsarPath } from './asset'
import { env } from './env'

export function initWindow() {
Expand All @@ -30,7 +30,7 @@ export function initWindow() {
const url = env.isDev
? 'http://localhost:8000/'
: format({
pathname: path.join(__dirname, '../../renderer/out/index.html'),
pathname: getResourceAsarPath('renderer/out/index.html'),
protocol: 'file:',
slashes: true,
})
Expand Down
9 changes: 0 additions & 9 deletions renterd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,5 @@
"postcss": "^8.4.31",
"rimraf": "^3.0.2",
"typescript": "5.0.3"
},
"build": {
"icon": "assets/appicon.png",
"asar": true,
"files": [
"dist",
"assets",
"bin"
]
}
}

0 comments on commit d4d322c

Please sign in to comment.