mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-29 12:55:21 +01:00
Rust improvements (#1495)
This commit is contained in:
parent
508292ae39
commit
817856bc82
@ -4,5 +4,6 @@ jslib
|
|||||||
webpack.main.js
|
webpack.main.js
|
||||||
webpack.renderer.js
|
webpack.renderer.js
|
||||||
src/scripts/duo.js
|
src/scripts/duo.js
|
||||||
|
desktop_native
|
||||||
|
|
||||||
**/node_modules
|
**/node_modules
|
||||||
|
12
.github/workflows/build.yml
vendored
12
.github/workflows/build.yml
vendored
@ -153,7 +153,7 @@ jobs:
|
|||||||
uses: actions/cache@48af2dc4a9e8278b89d7fa154b955c30c6aaab09 # v3.0.2
|
uses: actions/cache@48af2dc4a9e8278b89d7fa154b955c30c6aaab09 # v3.0.2
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: desktop_native/dist
|
path: desktop_native/*.node
|
||||||
key: rust-${{ runner.os }}-${{ hashFiles('desktop_native/**/*') }}
|
key: rust-${{ runner.os }}-${{ hashFiles('desktop_native/**/*') }}
|
||||||
|
|
||||||
- name: Build Native Module
|
- name: Build Native Module
|
||||||
@ -278,7 +278,7 @@ jobs:
|
|||||||
uses: actions/cache@48af2dc4a9e8278b89d7fa154b955c30c6aaab09 # v3.0.2
|
uses: actions/cache@48af2dc4a9e8278b89d7fa154b955c30c6aaab09 # v3.0.2
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: desktop_native/dist
|
path: desktop_native/*.node
|
||||||
key: rust-${{ runner.os }}-${{ hashFiles('desktop_native/**/*') }}
|
key: rust-${{ runner.os }}-${{ hashFiles('desktop_native/**/*') }}
|
||||||
|
|
||||||
- name: Build Native Module
|
- name: Build Native Module
|
||||||
@ -540,7 +540,7 @@ jobs:
|
|||||||
uses: actions/cache@48af2dc4a9e8278b89d7fa154b955c30c6aaab09 # v3.0.2
|
uses: actions/cache@48af2dc4a9e8278b89d7fa154b955c30c6aaab09 # v3.0.2
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: desktop_native/dist
|
path: desktop_native/*.node
|
||||||
key: rust-${{ runner.os }}-${{ hashFiles('desktop_native/**/*') }}
|
key: rust-${{ runner.os }}-${{ hashFiles('desktop_native/**/*') }}
|
||||||
|
|
||||||
- name: Build Native Module
|
- name: Build Native Module
|
||||||
@ -703,7 +703,7 @@ jobs:
|
|||||||
uses: actions/cache@48af2dc4a9e8278b89d7fa154b955c30c6aaab09 # v3.0.2
|
uses: actions/cache@48af2dc4a9e8278b89d7fa154b955c30c6aaab09 # v3.0.2
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: desktop_native/dist
|
path: desktop_native/*.node
|
||||||
key: rust-${{ runner.os }}-${{ hashFiles('desktop_native/**/*') }}
|
key: rust-${{ runner.os }}-${{ hashFiles('desktop_native/**/*') }}
|
||||||
|
|
||||||
- name: Build Native Module
|
- name: Build Native Module
|
||||||
@ -910,7 +910,7 @@ jobs:
|
|||||||
uses: actions/cache@48af2dc4a9e8278b89d7fa154b955c30c6aaab09 # v3.0.2
|
uses: actions/cache@48af2dc4a9e8278b89d7fa154b955c30c6aaab09 # v3.0.2
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: desktop_native/dist
|
path: desktop_native/*.node
|
||||||
key: rust-${{ runner.os }}-${{ hashFiles('desktop_native/**/*') }}
|
key: rust-${{ runner.os }}-${{ hashFiles('desktop_native/**/*') }}
|
||||||
|
|
||||||
- name: Build Native Module
|
- name: Build Native Module
|
||||||
@ -1104,7 +1104,7 @@ jobs:
|
|||||||
uses: actions/cache@48af2dc4a9e8278b89d7fa154b955c30c6aaab09 # v3.0.2
|
uses: actions/cache@48af2dc4a9e8278b89d7fa154b955c30c6aaab09 # v3.0.2
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: desktop_native/dist
|
path: desktop_native/*.node
|
||||||
key: rust-${{ runner.os }}-${{ hashFiles('desktop_native/**/*') }}
|
key: rust-${{ runner.os }}-${{ hashFiles('desktop_native/**/*') }}
|
||||||
|
|
||||||
- name: Build Native Module
|
- name: Build Native Module
|
||||||
|
1
desktop_native/.gitignore
vendored
1
desktop_native/.gitignore
vendored
@ -3,3 +3,4 @@ index.node
|
|||||||
**/node_modules
|
**/node_modules
|
||||||
**/.DS_Store
|
**/.DS_Store
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
|
*.node
|
||||||
|
@ -1,32 +1,97 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
const { existsSync, readFileSync } = require('fs')
|
||||||
const { readFileSync } = require('fs')
|
const { join } = require('path')
|
||||||
|
|
||||||
const { platform, arch } = process
|
const { platform, arch } = process
|
||||||
|
|
||||||
let nativeBinding = null
|
let nativeBinding = null
|
||||||
let isMusl = false
|
let localFileExisted = false
|
||||||
let loadError = null
|
let loadError = null
|
||||||
|
|
||||||
|
function isMusl() {
|
||||||
|
// For Node 10
|
||||||
|
if (!process.report || typeof process.report.getReport !== 'function') {
|
||||||
|
try {
|
||||||
|
return readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
|
||||||
|
} catch (e) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const { glibcVersionRuntime } = process.report.getReport().header
|
||||||
|
return !glibcVersionRuntime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (platform) {
|
switch (platform) {
|
||||||
|
case 'android':
|
||||||
|
switch (arch) {
|
||||||
|
case 'arm64':
|
||||||
|
localFileExisted = existsSync(join(__dirname, 'desktop_native.android-arm64.node'))
|
||||||
|
try {
|
||||||
|
if (localFileExisted) {
|
||||||
|
nativeBinding = require('./desktop_native.android-arm64.node')
|
||||||
|
} else {
|
||||||
|
nativeBinding = require('@bitwarden/desktop_native-android-arm64')
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
loadError = e
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'arm':
|
||||||
|
localFileExisted = existsSync(join(__dirname, 'desktop_native.android-arm-eabi.node'))
|
||||||
|
try {
|
||||||
|
if (localFileExisted) {
|
||||||
|
nativeBinding = require('./desktop_native.android-arm-eabi.node')
|
||||||
|
} else {
|
||||||
|
nativeBinding = require('@bitwarden/desktop_native-android-arm-eabi')
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
loadError = e
|
||||||
|
}
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
throw new Error(`Unsupported architecture on Android ${arch}`)
|
||||||
|
}
|
||||||
|
break
|
||||||
case 'win32':
|
case 'win32':
|
||||||
switch (arch) {
|
switch (arch) {
|
||||||
case 'x64':
|
case 'x64':
|
||||||
|
localFileExisted = existsSync(
|
||||||
|
join(__dirname, 'desktop_native.win32-x64-msvc.node')
|
||||||
|
)
|
||||||
try {
|
try {
|
||||||
nativeBinding = require('./dist/desktop_native.win32-x64-msvc')
|
if (localFileExisted) {
|
||||||
|
nativeBinding = require('./desktop_native.win32-x64-msvc.node')
|
||||||
|
} else {
|
||||||
|
nativeBinding = require('@bitwarden/desktop_native-win32-x64-msvc')
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'ia32':
|
case 'ia32':
|
||||||
|
localFileExisted = existsSync(
|
||||||
|
join(__dirname, 'desktop_native.win32-ia32-msvc.node')
|
||||||
|
)
|
||||||
try {
|
try {
|
||||||
nativeBinding = require('./dist/desktop_native.win32-ia32-msvc')
|
if (localFileExisted) {
|
||||||
|
nativeBinding = require('./desktop_native.win32-ia32-msvc.node')
|
||||||
|
} else {
|
||||||
|
nativeBinding = require('@bitwarden/desktop_native-win32-ia32-msvc')
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'arm64':
|
case 'arm64':
|
||||||
|
localFileExisted = existsSync(
|
||||||
|
join(__dirname, 'desktop_native.win32-arm64-msvc.node')
|
||||||
|
)
|
||||||
try {
|
try {
|
||||||
nativeBinding = require('./dist/desktop_native.win32-arm64-msvc')
|
if (localFileExisted) {
|
||||||
|
nativeBinding = require('./desktop_native.win32-arm64-msvc.node')
|
||||||
|
} else {
|
||||||
|
nativeBinding = require('@bitwarden/desktop_native-win32-arm64-msvc')
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
}
|
}
|
||||||
@ -38,15 +103,27 @@ switch (platform) {
|
|||||||
case 'darwin':
|
case 'darwin':
|
||||||
switch (arch) {
|
switch (arch) {
|
||||||
case 'x64':
|
case 'x64':
|
||||||
|
localFileExisted = existsSync(join(__dirname, 'desktop_native.darwin-x64.node'))
|
||||||
try {
|
try {
|
||||||
nativeBinding = require('./dist/desktop_native.darwin-x64')
|
if (localFileExisted) {
|
||||||
|
nativeBinding = require('./desktop_native.darwin-x64.node')
|
||||||
|
} else {
|
||||||
|
nativeBinding = require('@bitwarden/desktop_native-darwin-x64')
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'arm64':
|
case 'arm64':
|
||||||
|
localFileExisted = existsSync(
|
||||||
|
join(__dirname, 'desktop_native.darwin-arm64.node')
|
||||||
|
)
|
||||||
try {
|
try {
|
||||||
nativeBinding = require('./dist/desktop_native.darwin-arm64')
|
if (localFileExisted) {
|
||||||
|
nativeBinding = require('./desktop_native.darwin-arm64.node')
|
||||||
|
} else {
|
||||||
|
nativeBinding = require('@bitwarden/desktop_native-darwin-arm64')
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
}
|
}
|
||||||
@ -55,43 +132,91 @@ switch (platform) {
|
|||||||
throw new Error(`Unsupported architecture on macOS: ${arch}`)
|
throw new Error(`Unsupported architecture on macOS: ${arch}`)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
case 'freebsd':
|
||||||
|
if (arch !== 'x64') {
|
||||||
|
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
|
||||||
|
}
|
||||||
|
localFileExisted = existsSync(join(__dirname, 'desktop_native.freebsd-x64.node'))
|
||||||
|
try {
|
||||||
|
if (localFileExisted) {
|
||||||
|
nativeBinding = require('./desktop_native.freebsd-x64.node')
|
||||||
|
} else {
|
||||||
|
nativeBinding = require('@bitwarden/desktop_native-freebsd-x64')
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
loadError = e
|
||||||
|
}
|
||||||
|
break
|
||||||
case 'linux':
|
case 'linux':
|
||||||
switch (arch) {
|
switch (arch) {
|
||||||
case 'x64':
|
case 'x64':
|
||||||
isMusl = readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
|
if (isMusl()) {
|
||||||
if (isMusl) {
|
localFileExisted = existsSync(
|
||||||
|
join(__dirname, 'desktop_native.linux-x64-musl.node')
|
||||||
|
)
|
||||||
try {
|
try {
|
||||||
nativeBinding = require('./dist/desktop_native.linux-x64-musl')
|
if (localFileExisted) {
|
||||||
|
nativeBinding = require('./desktop_native.linux-x64-musl.node')
|
||||||
|
} else {
|
||||||
|
nativeBinding = require('@bitwarden/desktop_native-linux-x64-musl')
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
localFileExisted = existsSync(
|
||||||
|
join(__dirname, 'desktop_native.linux-x64-gnu.node')
|
||||||
|
)
|
||||||
try {
|
try {
|
||||||
nativeBinding = require('./dist/desktop_native.linux-x64-gnu')
|
if (localFileExisted) {
|
||||||
|
nativeBinding = require('./desktop_native.linux-x64-gnu.node')
|
||||||
|
} else {
|
||||||
|
nativeBinding = require('@bitwarden/desktop_native-linux-x64-gnu')
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'arm64':
|
case 'arm64':
|
||||||
isMusl = readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
|
if (isMusl()) {
|
||||||
if (isMusl) {
|
localFileExisted = existsSync(
|
||||||
|
join(__dirname, 'desktop_native.linux-arm64-musl.node')
|
||||||
|
)
|
||||||
try {
|
try {
|
||||||
nativeBinding = require('./dist/desktop_native.linux-arm64-musl')
|
if (localFileExisted) {
|
||||||
|
nativeBinding = require('./desktop_native.linux-arm64-musl.node')
|
||||||
|
} else {
|
||||||
|
nativeBinding = require('@bitwarden/desktop_native-linux-arm64-musl')
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
localFileExisted = existsSync(
|
||||||
|
join(__dirname, 'desktop_native.linux-arm64-gnu.node')
|
||||||
|
)
|
||||||
try {
|
try {
|
||||||
nativeBinding = require('./dist/desktop_native.linux-arm64-gnu')
|
if (localFileExisted) {
|
||||||
|
nativeBinding = require('./desktop_native.linux-arm64-gnu.node')
|
||||||
|
} else {
|
||||||
|
nativeBinding = require('@bitwarden/desktop_native-linux-arm64-gnu')
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'arm':
|
case 'arm':
|
||||||
|
localFileExisted = existsSync(
|
||||||
|
join(__dirname, 'desktop_native.linux-arm-gnueabihf.node')
|
||||||
|
)
|
||||||
try {
|
try {
|
||||||
nativeBinding = require('./dist/desktop_native.linux-arm-gnueabihf')
|
if (localFileExisted) {
|
||||||
|
nativeBinding = require('./desktop_native.linux-arm-gnueabihf.node')
|
||||||
|
} else {
|
||||||
|
nativeBinding = require('@bitwarden/desktop_native-linux-arm-gnueabihf')
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
}
|
}
|
||||||
@ -111,4 +236,6 @@ if (!nativeBinding) {
|
|||||||
throw new Error(`Failed to load native binding`)
|
throw new Error(`Failed to load native binding`)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.nativeBinding
|
const { passwords } = nativeBinding
|
||||||
|
|
||||||
|
module.exports.passwords = passwords
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.node",
|
"main": "index.node",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "napi build dist --platform --release --js true",
|
"build": "napi build --release --platform",
|
||||||
"build:debug": "napi build dist --platform --js true",
|
"build:debug": "napi build --platform",
|
||||||
"build:cross-platform": "node build.js",
|
"build:cross-platform": "node build.js",
|
||||||
"test": "cargo test"
|
"test": "cargo test"
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user