From b1a003b1e923e8b529f3af3c21a0ade032de09bf Mon Sep 17 00:00:00 2001 From: Alexey Danilevich Date: Thu, 22 Feb 2024 08:49:12 +0300 Subject: [PATCH] Fix build scripts (#1048) Adding the ability to specify a build target Fix warning --- ton_client/build.js | 49 ++++++++++++++++++++++++++--- ton_client/src/processing/errors.rs | 2 +- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/ton_client/build.js b/ton_client/build.js index 776c526ae..4a2d013a0 100644 --- a/ton_client/build.js +++ b/ton_client/build.js @@ -11,10 +11,47 @@ const { devMode, } = require('./build-lib'); const platform = os.platform(); -const arch = os.arch(); +const cArch = os.arch(); +const getArch = () => { + for (let i = 1; i < process.argv.length - 1; i++) { + if(process.argv[i] === '--target') { + return process.argv[i + 1]; + } + } + return cArch; +} +const getRustTarget = () => { + if(cArch === arch) { + return ''; + + } + const platformTargets = { + linux: { + arm: 'armv7-unknown-linux-gnueabihf', + arm64: 'aarch64-unknown-linux-gnu', + x64: 'x86_64-unknown-linux-gnu' + }, + win32: { + x64: 'x86_64-pc-windows-msvc' + }, + darwin: { + x64: 'x86_64-apple-darwin', + arm64: 'aarch64-apple-darwin' + } + }; + return platformTargets[platform]?.[arch] ?? ''; +} +const arch = getArch(); +const rustTarget = getRustTarget(); main(async () => { - await spawnProcess('cargo', ['build', '--release']); + if(rustTarget) { + await spawnProcess('rustup', ['target', 'add', rustTarget]); + } + console.log('Executing: cargo', + ['build', '--release'].concat(rustTarget ? ['--target', rustTarget] : []).join(' ') + ); + await spawnProcess('cargo', ['build', '--release'].concat(rustTarget ? ['--target', rustTarget] : [])); deleteFolderRecursive(root_path('bin')); fs.mkdirSync(root_path('bin'), { recursive: true }); const platformNames = { @@ -30,10 +67,12 @@ main(async () => { }, }; for (const [src, dstSuffix] of platformNames[platform][arch] || []) { - const target = ['..', 'target', 'release', src.replace('{}', 'ton_client')]; + const target = ['..', 'target', rustTarget, 'release', src.replace('{}', 'ton_client')]; await postBuild(target, platform); await gz( - target, - `tonclient_${version}_${platform}${dstSuffix || ''}`, [__dirname, 'build']); + target, + `tonclient_${version}_${platform}${cArch==arch ? '' : `_${arch}`}${dstSuffix || ''}`, + [__dirname, 'build'] + ); } }); diff --git a/ton_client/src/processing/errors.rs b/ton_client/src/processing/errors.rs index 54e4957bb..ac4358e0f 100644 --- a/ton_client/src/processing/errors.rs +++ b/ton_client/src/processing/errors.rs @@ -78,7 +78,7 @@ impl Error { "message_id": message_id, }); if let Some(shard_block_id) = shard_block_id { - data["shard_block_id"] = shard_block_id.clone().into(); + data["shard_block_id"] = shard_block_id.into(); } error_with_data(code, message, data) }