Skip to content

Commit

Permalink
Add openssl1 case for couchbase
Browse files Browse the repository at this point in the history
  • Loading branch information
bigorn0 committed Sep 26, 2023
1 parent c53de02 commit 27c3d4e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/linux-openssl1-build-prebuilds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Prebuild for Linux x64 With Openssl 1 instead of Openssl 3

on:
workflow_dispatch:

jobs:
build-for-linux:
runs-on: ubuntu-22.04
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
cache: npm
node-version: 18
- name: Install toolkit
run: npm ci
- name: Set Electron Major version in env
run: echo "ELECTRON_MAJOR_VERSION=$(node get-electron-major-version.js)" >> $GITHUB_ENV
- name: Download artifact
id: download-artifact
uses: dawidd6/action-download-artifact@v2
with:
# Optional, GitHub token, a Personal Access Token with `public_repo` scope if needed
# Required, if the artifact is from a different repo
# Required, if the repo is private a Personal Access Token with `repo` scope is needed or GitHub token in a job where the permissions `action` scope set to `read`
github_token: ${{secrets.GITHUB_TOKEN}}
# Optional, workflow file name or ID
# If not specified, will be inferred from run_id (if run_id is specified), or will be the current workflow
workflow: discover-and-prepare-upstream-native-modules.yml
# Optional, the status or conclusion of a completed workflow to search for
# Can be one of a workflow conclusion:
# "failure", "success", "neutral", "cancelled", "skipped", "timed_out", "action_required"
# Or a workflow status:
# "completed", "in_progress", "queued"
# Use the empty string ("") to ignore status or conclusion in the search
workflow_conclusion: success
name: modulesToBuildForElectron-${{ env.ELECTRON_MAJOR_VERSION }}
- name: Build native modules on Linux x64
run: npm run rebuild-custom-for-target
12 changes: 10 additions & 2 deletions lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ export const ghPackageNpmrc = `
@hackolade:registry=https://npm.pkg.github.com
always-auth=true`;

export const pkgTpl = ({ githubOrganizationScope, moduleName, targetPlatform, targetArch, version }) => {
export const pkgTpl = ({ githubOrganizationScope, moduleName, targetPlatform, targetArch, version, forOpenSSL1 }) => {
const mainFile = (moduleName === 'desktop-trampoline' && 'desktop-trampoline') || 'prebuild.node';
const opensslSuffix = forOpenSSL1? '-openssl1': '';

return {
name: `${githubOrganizationScope}/${moduleName}-${targetPlatform}-${targetArch}`,
name: `${githubOrganizationScope}/${moduleName}-${targetPlatform}-${targetArch}${opensslSuffix}`,
version: `${version}-${electronVersion}`,
main: mainFile,
files: [mainFile],
Expand All @@ -51,6 +52,7 @@ export async function writePkgTpl({ moduleName, targetPlatform, targetArch, vers
targetArch,
version,
scopedPackagePath,
forOpenSSL1,
});
await writeFile(path.resolve(scopedPackagePath, 'package.json'), JSON.stringify(packageJsonContentForModule));
}
Expand Down Expand Up @@ -180,6 +182,12 @@ export async function normalizeNativeModulesUnderHackolade(nativeModules) {
[`${pkg.name}-darwin-x64`]: prebuildPkgVersion,
[`${pkg.name}-darwin-arm64`]: prebuildPkgVersion,
};

// add openssl1 variant for listed modules that require it
if(name === 'couchbase'){
depsByTarget[`${pkg.name}-linux-x64-openssl1`] = prebuildPkgVersion;
}

const deps = pkg.dependencies;
pkg.dependencies = Object.assign(deps, depsByTarget);

Expand Down
11 changes: 9 additions & 2 deletions rebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { prebuildNativeModule } from '#lib/prebuilds.js';
import { npxCommand, exec } from '#lib/commands.js';
import modules from './modulesToBuild.json' assert { type: 'json' };
import { ROOT_DIR } from '#root';
import { mkdir, cp, readdir, rm } from 'node:fs/promises';
import { mkdir, cp, readdir,readFile, rm } from 'node:fs/promises';
import path from 'node:path';
import { checkPackageVersionExistsFromPath, publishToGitHubPackages, writePkgTpl } from '#lib/publish.js';
import winAddon from './winapi-detect-remote-desktop-addon/package.json' assert { type: 'json' };
Expand Down Expand Up @@ -44,7 +44,13 @@ if (platform() === 'win32') {
modulesToBuild.push(remoteDesktopDetectionAddon);
}

for (const { module, targetPlatform, targetArch } of modulesToBuild) {
// Detect Ubuntu version to know if we need to specifically build modules for Openssl 1 like Couchbase
const ubuntuReleaseFile = await readFile(path.resolve('/etc/os-release'));

const mustBuildForOpenSSL1 = ubuntuReleaseFile.toString('UTF8').split('\n').filter(line => line.includes('VERSION_ID=20.04')).length > 0;
const modulesToBuildOnlyForOpenSSL1 = modulesToBuild.filter(module => module.name === 'couchbase');

for (const { module, targetPlatform, targetArch } of mustBuildForOpenSSL1 ? modulesToBuildOnlyForOpenSSL1: modulesToBuild) {

const prebuildModuleNameForTarget = `${module.name}-${targetPlatform}-${targetArch}`;
const nativeModuleScopedPackage = path.join(
Expand All @@ -62,6 +68,7 @@ for (const { module, targetPlatform, targetArch } of modulesToBuild) {
targetArch,
scopedPackagePath: nativeModuleScopedPackage,
version: module.version,
forOpenSSL1: mustBuildForOpenSSL1,
});

const token = env.NODE_AUTH_TOKEN;
Expand Down

0 comments on commit 27c3d4e

Please sign in to comment.