Skip to content

Commit

Permalink
feat: auto-detect os & arch
Browse files Browse the repository at this point in the history
  • Loading branch information
omurovec committed Feb 21, 2023
1 parent b4e81ea commit c1760b9
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions script/Deployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ contract Deployer {
string private zksolcPath;
address private diamondProxy;

struct SystemInfo {
string os;
string arch;
string extension;
string toolchain;
}

constructor(string memory _zksolcVersion, address _diamondProxy) {
///@notice install bin compiler
projectRoot = _vm.projectRoot();
Expand Down Expand Up @@ -87,23 +94,38 @@ contract Deployer {
bytecode = _vm.ffi(echoCmds);
}

function _installCompiler(string memory version) internal returns (string memory path) {
///@notice Ensure correct compiler bin is installed
string memory os = _vm.envString("OS");
string memory arch = _vm.envString("ARCH");
string memory extension = keccak256(bytes(os)) == keccak256(bytes("windows")) ? "exe" : "";

///@notice Get toolchain
string memory toolchain = "";
if (keccak256(bytes(os)) == keccak256(bytes("windows"))) {
toolchain = "-gnu";
} else if (keccak256(bytes(os)) == keccak256(bytes("linux"))) {
toolchain = "-musl";
function _detectSystemInfo() private returns (SystemInfo memory systemInfo) {
string[] memory cmds = new string[](2);

///@notice Try to check arch on windows
cmds[0] = "echo";
cmds[1] = "%PROCESSOR_ARCHITECTURE%";

///@notice %PROCESS_ARCHITECTURE% evaluated to something
if(keccak256(bytes(_vm.ffi(cmds))) != keccak256(bytes(cmds[1]))) {
systemInfo.os = "windows";
systemInfo.arch = "amd64";
systemInfo.extension = "exe";
systemInfo.toolchain = "-gnu";
} else {
///@notice Check os
cmds[1] = "$(uname -s)";
systemInfo.os = keccak256(bytes(_vm.ffi(cmds))) != keccak256(bytes("Darwin")) ? "macosx" : "linux";
systemInfo.toolchain = keccak256(bytes(systemInfo.os)) == keccak256(bytes("linux")) ? "-musl" : "";

///@notice Check arch
cmds[1] = "$(uname -m)";
systemInfo.arch = keccak256(bytes(_vm.ffi(cmds))) != keccak256(bytes("arm64")) ? "arm64" : "amd64";
}
}

///@notice Ensure correct compiler bin is installed
function _installCompiler(string memory version) internal returns (string memory path) {
SystemInfo memory systemInfo = _detectSystemInfo();

///@notice Construct urls/paths
string memory fileName = string(abi.encodePacked("zksolc-", os, "-", arch, toolchain, "-v", version, extension));
string memory zksolcUrl = string(abi.encodePacked(ZKSOLC_BIN_REPO, "/raw/main/", os, "-", arch, "/", fileName));
string memory fileName = string(abi.encodePacked("zksolc-", systemInfo.os, "-", systemInfo.arch, systemInfo.toolchain, "-v", version, systemInfo.extension));
string memory zksolcUrl = string(abi.encodePacked(ZKSOLC_BIN_REPO, "/raw/main/", systemInfo.os, "-", systemInfo.arch, "/", fileName));
path = string(abi.encodePacked(projectRoot, "/lib/", fileName));

///@notice Download zksolc compiler bin
Expand Down

0 comments on commit c1760b9

Please sign in to comment.