diff --git a/compilerr.js b/compilerr.js index f8daee5..cfe6eb1 100644 --- a/compilerr.js +++ b/compilerr.js @@ -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 || {}; @@ -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 { @@ -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`, diff --git a/index.js b/index.js index 658693e..0653030 100755 --- a/index.js +++ b/index.js @@ -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' ]; @@ -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']; @@ -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); @@ -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) {