Skip to content

Commit

Permalink
Added support for separate arches under macos
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathon-love committed Feb 14, 2024
1 parent e5c3cea commit 435f24f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
9 changes: 6 additions & 3 deletions compilerr.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const snapshots = require('./snapshots');
const temp = require('temp');
temp.track();

const compile = function(srcDir, moduleDir, paths, packageInfo, log, options) {
const compile = function(srcDir, moduleDir, paths, packageInfo, rVersion, rArch, log, options) {

options = options || {};

Expand All @@ -32,10 +32,9 @@ const compile = function(srcDir, moduleDir, paths, packageInfo, log, options) {
break;
}

let rVersion = packageInfo.rVersion;
let snapshot = snapshots[rVersion];
let included = (packageInfo.name === 'jmv' ? snapshot.base_packages : snapshot.jmv_packages);
let buildDir = path.join(srcDir, 'build', `R${ rVersion }-${ platform }`);
let buildDir = path.join(srcDir, 'build', `R${ packageInfo.rVersion }-${ platform }`);
let mirror = options.mirror || snapshot.mran_url;

try {
Expand Down Expand Up @@ -193,6 +192,10 @@ const compile = function(srcDir, moduleDir, paths, packageInfo, log, options) {
let installed = fs.readdirSync(buildDir);

let rv = rVersion.substring(0,3)
if (rArch === 'x64')
rv = `${ rv }-x86_64`;
else if (rArch === 'arm64')
rv = `${ rv }-arm64`;

const subs = [
[`/Library/Frameworks/R.framework/Versions/${ rv }/Resources/lib/libR.dylib`,
Expand Down
22 changes: 18 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ try {
rVersionOutput = child_process.execSync(cmd, { encoding: 'UTF-8', env: env });
}

let rVersion = /R version ([0-9]+\.[0-9]+\.[0-9]+)/g.exec(rVersionOutput);
let rVersion = /^R version ([0-9]+\.[0-9]+\.[0-9]+)/.exec(rVersionOutput);
let rArch = '';

if (rVersion === null && process.platform === 'win32') {
rVersion = [ undefined, '3.4.1' ];
Expand All @@ -231,6 +232,19 @@ try {
throw 'unable to determine R version';
rVersion = rVersion[1];

const versionParts = /^([0-9]+)\.([0-9]+)/.exec(rVersion);
const versionAsInt = 100 * parseInt(versionParts[1]) + parseInt(versionParts[2]);

let rVersionAndArch = rVersion;
if (process.platform === 'darwin' && versionAsInt > 401) { // macOS + > 4.1
let arch = /Platform: ([^-]+)/.exec(rVersionOutput)[1];
if (arch === 'aarch64')
rArch = 'arm64';
else if (arch == 'x86_64')
rArch = 'x64';
rVersionAndArch = `${ rVersion }-${ rArch }`;
}

let mirror;
let skipRemotes = args['skip-remotes'];

Expand Down Expand Up @@ -522,13 +536,13 @@ try {

if (isBuilding || isInstallingTo) {

packageInfoLite.rVersion = rVersion;
packageInfoLite.rVersion = rVersionAndArch;
content = '---\n' + yaml.safeDump(packageInfoLite) + '\n...\n';

fs.writeFileSync(path.join(modDir, 'jamovi.yaml'), content);
console.log('wrote: jamovi.yaml');

packageInfo.rVersion = rVersion;
packageInfo.rVersion = rVersionAndArch;
content = '---\n' + yaml.safeDump(packageInfo) + '\n...\n';

fs.writeFileSync(path.join(modDir, 'jamovi-full.yaml'), content);
Expand All @@ -543,7 +557,7 @@ try {
}

log.debug('compiling R package');
compileR(srcDir, modDir, paths, packageInfo, log, { mirror, skipRemotes, skipDeps: args['skip-deps'] });
compileR(srcDir, modDir, paths, packageInfo, rVersion, rArch, log, { mirror, skipRemotes, skipDeps: args['skip-deps'] });
log.debug('compiled');

if (isBuilding) {
Expand Down

0 comments on commit 435f24f

Please sign in to comment.