|
|
|
@ -11,10 +11,12 @@ import path from "path";
|
|
|
|
|
import process from "process"; |
|
|
|
|
import child_process from "child_process"; |
|
|
|
|
import glob from "fast-glob"; |
|
|
|
|
import { Cell } from "ton"; |
|
|
|
|
import semver from "semver"; |
|
|
|
|
|
|
|
|
|
async function main() { |
|
|
|
|
console.log(`=================================================================`); |
|
|
|
|
console.log(`Build script running, let's find some FunC contracts to compile..`); |
|
|
|
|
console.log("================================================================="); |
|
|
|
|
console.log("Build script running, let's find some FunC contracts to compile.."); |
|
|
|
|
|
|
|
|
|
// if we have an explicit bin directory, use the executables there (needed for glitch.com)
|
|
|
|
|
if (fs.existsSync("bin")) { |
|
|
|
@ -23,12 +25,15 @@ async function main() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// make sure func compiler is available
|
|
|
|
|
let funcVersion = ""; |
|
|
|
|
const minSupportFunc = "0.2.0"; |
|
|
|
|
try { |
|
|
|
|
funcVersion = child_process.execSync("func -V").toString(); |
|
|
|
|
} catch (e) {} |
|
|
|
|
if (!funcVersion.includes(`Func build information`)) { |
|
|
|
|
console.log(`\nFATAL ERROR: 'func' executable is not found, is it installed and in path?`); |
|
|
|
|
const funcVersion = child_process |
|
|
|
|
.execSync("func -V") |
|
|
|
|
.toString() |
|
|
|
|
.match(/semantic version: v([0-9.]+)/)?.[1]; |
|
|
|
|
if (!semver.gte(semver.coerce(funcVersion) ?? "", minSupportFunc)) throw new Error("Nonexistent version or outdated"); |
|
|
|
|
} catch (e) { |
|
|
|
|
console.log(`\nFATAL ERROR: 'func' with version >= ${minSupportFunc} executable is not found, is it installed and in path?`); |
|
|
|
|
process.exit(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -37,8 +42,8 @@ async function main() {
|
|
|
|
|
try { |
|
|
|
|
fiftVersion = child_process.execSync("fift -V").toString(); |
|
|
|
|
} catch (e) {} |
|
|
|
|
if (!fiftVersion.includes(`Fift build information`)) { |
|
|
|
|
console.log(`\nFATAL ERROR: 'fift' executable is not found, is it installed and in path?`); |
|
|
|
|
if (!fiftVersion.includes("Fift build information")) { |
|
|
|
|
console.log("\nFATAL ERROR: 'fift' executable is not found, is it installed and in path?"); |
|
|
|
|
process.exit(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -70,6 +75,11 @@ async function main() {
|
|
|
|
|
console.log(` - Deleting old build artifact '${cellArtifact}'`); |
|
|
|
|
fs.unlinkSync(cellArtifact); |
|
|
|
|
} |
|
|
|
|
const hexArtifact = `build/${contractName}.compiled.json`; |
|
|
|
|
if (fs.existsSync(hexArtifact)) { |
|
|
|
|
console.log(` - Deleting old build artifact '${hexArtifact}'`); |
|
|
|
|
fs.unlinkSync(hexArtifact); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// check if we have a tlb file
|
|
|
|
|
const tlbFile = `contracts/${contractName}.tlb`; |
|
|
|
@ -87,27 +97,20 @@ async function main() {
|
|
|
|
|
console.log(` - Warning: TL-B file for contract '${tlbFile}' not found, are your op consts according to standard?`); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// create a merged fc file with source code from all dependencies
|
|
|
|
|
let sourceToCompile = ""; |
|
|
|
|
const importFiles = glob.sync([`contracts/imports/*.fc`, `contracts/imports/*.func`, `contracts/imports/${contractName}/*.fc`, `contracts/imports/${contractName}/*.func`]); |
|
|
|
|
for (const importFile of importFiles) { |
|
|
|
|
console.log(` - Adding import '${importFile}'`); |
|
|
|
|
sourceToCompile += `${fs.readFileSync(importFile).toString()}\n`; |
|
|
|
|
} |
|
|
|
|
console.log(` - Adding the contract itself '${rootContract}'`); |
|
|
|
|
sourceToCompile += `${fs.readFileSync(rootContract).toString()}\n`; |
|
|
|
|
fs.writeFileSync(mergedFuncArtifact, sourceToCompile); |
|
|
|
|
console.log(` - Build artifact created '${mergedFuncArtifact}'`); |
|
|
|
|
|
|
|
|
|
// run the func compiler to create a fif file
|
|
|
|
|
console.log(` - Trying to compile '${mergedFuncArtifact}' with 'func' compiler..`); |
|
|
|
|
const buildErrors = child_process.execSync(`func -APS -o build/${contractName}.fif ${mergedFuncArtifact} 2>&1 1>node_modules/.tmpfunc`).toString(); |
|
|
|
|
console.log(` - Trying to compile '${rootContract}' with 'func' compiler..`); |
|
|
|
|
let buildErrors: string; |
|
|
|
|
try { |
|
|
|
|
buildErrors = child_process.execSync(`func -APS -o build/${contractName}.fif ${rootContract} 2>&1 1>node_modules/.tmpfunc`).toString(); |
|
|
|
|
} catch (e) { |
|
|
|
|
buildErrors = e.stdout.toString(); |
|
|
|
|
} |
|
|
|
|
if (buildErrors.length > 0) { |
|
|
|
|
console.log(` - OH NO! Compilation Errors! The compiler output was:`); |
|
|
|
|
console.log(" - OH NO! Compilation Errors! The compiler output was:"); |
|
|
|
|
console.log(`\n${buildErrors}`); |
|
|
|
|
process.exit(1); |
|
|
|
|
} else { |
|
|
|
|
console.log(` - Compilation successful!`); |
|
|
|
|
console.log(" - Compilation successful!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// make sure fif build artifact was created
|
|
|
|
@ -119,7 +122,7 @@ async function main() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// create a temp cell.fif that will generate the cell
|
|
|
|
|
let fiftCellSource = `"Asm.fif" include\n`; |
|
|
|
|
let fiftCellSource = '"Asm.fif" include\n'; |
|
|
|
|
fiftCellSource += `${fs.readFileSync(fiftArtifact).toString()}\n`; |
|
|
|
|
fiftCellSource += `boc>B "${cellArtifact}" B>file`; |
|
|
|
|
fs.writeFileSync(fiftCellArtifact, fiftCellSource); |
|
|
|
@ -128,21 +131,41 @@ async function main() {
|
|
|
|
|
try { |
|
|
|
|
child_process.execSync(`fift ${fiftCellArtifact}`); |
|
|
|
|
} catch (e) { |
|
|
|
|
console.log(`FATAL ERROR: 'fift' executable failed, is FIFTPATH env variable defined?`); |
|
|
|
|
console.log("FATAL ERROR: 'fift' executable failed, is FIFTPATH env variable defined?"); |
|
|
|
|
process.exit(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Remove intermediary
|
|
|
|
|
fs.unlinkSync(fiftCellArtifact); |
|
|
|
|
|
|
|
|
|
// make sure cell build artifact was created
|
|
|
|
|
if (!fs.existsSync(cellArtifact)) { |
|
|
|
|
console.log(` - For some reason '${cellArtifact}' was not created!`); |
|
|
|
|
process.exit(1); |
|
|
|
|
} else { |
|
|
|
|
console.log(` - Build artifact created '${cellArtifact}'`); |
|
|
|
|
fs.unlinkSync(fiftCellArtifact); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fs.writeFileSync( |
|
|
|
|
hexArtifact, |
|
|
|
|
JSON.stringify({ |
|
|
|
|
hex: Cell.fromBoc(fs.readFileSync(cellArtifact))[0].toBoc().toString("hex"), |
|
|
|
|
}) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// Remove intermediary
|
|
|
|
|
fs.unlinkSync(cellArtifact); |
|
|
|
|
|
|
|
|
|
// make sure hex artifact was created
|
|
|
|
|
if (!fs.existsSync(hexArtifact)) { |
|
|
|
|
console.log(` - For some reason '${hexArtifact}' was not created!`); |
|
|
|
|
process.exit(1); |
|
|
|
|
} else { |
|
|
|
|
console.log(` - Build artifact created '${hexArtifact}'`); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
console.log(``); |
|
|
|
|
console.log(""); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
main(); |
|
|
|
@ -152,7 +175,7 @@ main();
|
|
|
|
|
function crc32(r: string) { |
|
|
|
|
for (var a, o = [], c = 0; c < 256; c++) { |
|
|
|
|
a = c; |
|
|
|
|
for (var f = 0; f < 8; f++) a = 1 & a ? 3988292384 ^ (a >>> 1) : a >>> 1; |
|
|
|
|
for (let f = 0; f < 8; f++) a = 1 & a ? 3988292384 ^ (a >>> 1) : a >>> 1; |
|
|
|
|
o[c] = a; |
|
|
|
|
} |
|
|
|
|
for (var n = -1, t = 0; t < r.length; t++) n = (n >>> 8) ^ o[255 & (n ^ r.charCodeAt(t))]; |
|
|
|
|