Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add arch to cache directory #45

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# `v8-module-cache` Changelog

## Next

* Fix segmentation fault with Rosetta on Apple Silicon [#45](https://github.com/zertosh/v8-compile-cache/pull/45).

## 2021-03-05, Version 2.3.0

* Fix use require.main instead of module.parent [#34](https://github.com/zertosh/v8-compile-cache/pull/34).
Expand Down
17 changes: 17 additions & 0 deletions test/arch/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -eo pipefail

THIS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
: "${NODE_BIN:=node}"

if [ "$(/usr/bin/arch)" != "arm64" ]; then
echo "arch/run.sh: This must be run on Apple Silicon." >&2
exit
fi

# shellcheck disable=SC2016
"$NODE_BIN" "$THIS_DIR/yarn.js" config get init.author.name >/dev/null
/usr/bin/arch -x86_64 "$NODE_BIN" "$THIS_DIR/yarn.js" config get init.author.name >/dev/null

echo "Success!"
4 changes: 4 additions & 0 deletions test/arch/yarn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

require ('../../v8-compile-cache.js');
require('yarn/lib/cli.js');
10 changes: 7 additions & 3 deletions test/getCacheDir-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ tap.test('getCacheDir (v8)', t => {
const nameParts = parts[1].split(path.sep);

t.match(nameParts[1], /^v8-compile-cache(-\d+)?$/);
t.equal(nameParts[2], process.versions.v8);
t.equal(nameParts[2], process.arch);
t.equal(nameParts[3], process.versions.v8);

t.done();
});
Expand All @@ -24,6 +25,7 @@ tap.test('getCacheDir (chakracore)', t => {
'(' + getCacheDir.toString() + ')();',
{
process: {
arch: process.arch,
getuid: process.getuid,
versions: {chakracore: '1.2.3'},
env: {},
Expand All @@ -37,7 +39,7 @@ tap.test('getCacheDir (chakracore)', t => {
const nameParts = parts[1].split(path.sep);

t.match(nameParts[1], /^v8-compile-cache(-\d+)?$/);
t.equal(nameParts[2], 'chakracore-1.2.3');
t.equal(nameParts[3], 'chakracore-1.2.3');

t.done();
});
Expand All @@ -47,6 +49,7 @@ tap.test('getCacheDir (unknown)', t => {
'(' + getCacheDir.toString() + ')();',
{
process: {
arch: process.arch,
getuid: process.getuid,
version: '1.2.3',
versions: {},
Expand All @@ -60,7 +63,7 @@ tap.test('getCacheDir (unknown)', t => {
const parts = cacheDir.split(os.tmpdir());
const nameParts = parts[1].split(path.sep);
t.match(nameParts[1], /^v8-compile-cache(-\d+)?$/);
t.equal(nameParts[2], 'node-1.2.3');
t.equal(nameParts[3], 'node-1.2.3');

t.done();
});
Expand All @@ -70,6 +73,7 @@ tap.test('getCacheDir (env)', t => {
'(' + getCacheDir.toString() + ')();',
{
process: {
arch: process.arch,
getuid: process.getuid,
versions: {},
env: {
Expand Down
4 changes: 3 additions & 1 deletion v8-compile-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,14 @@ function getCacheDir() {
const dirname = typeof process.getuid === 'function'
? 'v8-compile-cache-' + process.getuid()
: 'v8-compile-cache';
// Avoid cache incompatibility issues with Rosetta on Apple Silicon.
const arch = process.arch;
const version = typeof process.versions.v8 === 'string'
? process.versions.v8
: typeof process.versions.chakracore === 'string'
? 'chakracore-' + process.versions.chakracore
: 'node-' + process.version;
const cacheDir = path.join(os.tmpdir(), dirname, version);
const cacheDir = path.join(os.tmpdir(), dirname, arch, version);
return cacheDir;
}

Expand Down