mirror of
https://github.com/ton-blockchain/ton
synced 2025-02-13 11:42:18 +00:00
* add github action for macOS 14 (arm64, M1) * add github action (portable) for macOS 14 (arm64, M1) * rename macOS arm64 output artifact * Update libsodium on windows * Compile libsodium * Update build-windows.bat * use upgraded libsodium 1.0.20; use compiled static libsodium for Windows instead of precompiled; * revert libsodium 1.0.20; use compiled static libsodium for Windows instead of precompiled; * use upgraded libsodium 1.0.20; use compiled static libsodium for Windows instead of precompiled; * fix libsodium version 1.0.19; use compiled static libsodium for Windows instead of precompiled; * try 1.0.20 libsodium precompiled on github * try 1.0.18 libsodium precompiled on github * try windows build on win server 2019 * and use PlatformToolset=v142 * use cmake -G "Visual Studio 16 2019" * fix path to msvc 2019 on github * separate github windows build on win server 2019 and build on win server 2022 * Update assembly/native/build-windows-2019.bat add retry mechanism Co-authored-by: Dr. Awesome Doge <doge@ton.org> * add test-emulator; disable test groovy pipeline * trigger all gh actions * fix win build * call test-emulator * remove usage of rocksdb in fift-lib * put back some code for test-db * fix test-emulator * remove usage of db-path parameter in fift * some func adjustments * fix checkout of openssl in fift-func-wasm-build-ubuntu.sh * typo * improve wasm build script for quicker turn around * remove sENVIRONMENT=web,worker for funcfiftlib. will be added later. * remove sENVIRONMENT=web,worker for funcfiftlib. will be added later. * remove sENVIRONMENT=web,worker for funcfiftlib. will be added later. * minor adjustments * remove -d option in fift; optimize fift-lib usage * reduce tondb usage --------- Co-authored-by: neodiX <neodix42@ton.org> Co-authored-by: Dr. Awesome Doge <doge@ton.org> Co-authored-by: ms <dungeon666master@protonmail.com>
151 lines
5.3 KiB
C++
151 lines
5.3 KiB
C++
/*
|
|
This file is part of TON Blockchain source code.
|
|
|
|
TON Blockchain is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License
|
|
as published by the Free Software Foundation; either version 2
|
|
of the License, or (at your option) any later version.
|
|
|
|
TON Blockchain is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with TON Blockchain. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
You must obey the GNU General Public License in all respects for all
|
|
of the code used other than OpenSSL. If you modify file(s) with this
|
|
exception, you may extend this exception to your version of the file(s),
|
|
but you are not obligated to do so. If you do not wish to do so, delete this
|
|
exception statement from your version. If you delete this exception statement
|
|
from all source files in the program, then also delete it here.
|
|
|
|
Copyright 2017-2020 Telegram Systems LLP
|
|
*/
|
|
#include "func/func.h"
|
|
#include "git.h"
|
|
#include "td/utils/JsonBuilder.h"
|
|
#include "fift/utils.h"
|
|
#include "td/utils/base64.h"
|
|
#include "td/utils/Status.h"
|
|
#include <sstream>
|
|
#include <iomanip>
|
|
#include "vm/boc.h"
|
|
|
|
td::Result<std::string> compile_internal(char *config_json) {
|
|
TRY_RESULT(input_json, td::json_decode(td::MutableSlice(config_json)))
|
|
auto &obj = input_json.get_object();
|
|
|
|
TRY_RESULT(opt_level, td::get_json_object_int_field(obj, "optLevel", false));
|
|
TRY_RESULT(sources_obj, td::get_json_object_field(obj, "sources", td::JsonValue::Type::Array, false));
|
|
|
|
auto &sources_arr = sources_obj.get_array();
|
|
|
|
std::vector<std::string> sources;
|
|
|
|
for (auto &item : sources_arr) {
|
|
sources.push_back(item.get_string().str());
|
|
}
|
|
|
|
funC::opt_level = std::max(0, opt_level);
|
|
funC::program_envelope = true;
|
|
funC::verbosity = 0;
|
|
funC::indent = 1;
|
|
|
|
std::ostringstream outs, errs;
|
|
auto compile_res = funC::func_proceed(sources, outs, errs);
|
|
|
|
if (compile_res != 0) {
|
|
return td::Status::Error(std::string("Func compilation error: ") + errs.str());
|
|
}
|
|
|
|
TRY_RESULT(code_cell, fift::compile_asm(outs.str(), "/fiftlib/", false));
|
|
TRY_RESULT(boc, vm::std_boc_serialize(code_cell));
|
|
|
|
td::JsonBuilder result_json;
|
|
auto result_obj = result_json.enter_object();
|
|
result_obj("status", "ok");
|
|
result_obj("codeBoc", td::base64_encode(boc));
|
|
result_obj("fiftCode", outs.str());
|
|
result_obj("codeHashHex", code_cell->get_hash().to_hex());
|
|
result_obj.leave();
|
|
|
|
outs.clear();
|
|
errs.clear();
|
|
|
|
return result_json.string_builder().as_cslice().str();
|
|
}
|
|
|
|
/// Callback used to retrieve additional source files or data.
|
|
///
|
|
/// @param _kind The kind of callback (a string).
|
|
/// @param _data The data for the callback (a string).
|
|
/// @param o_contents A pointer to the contents of the file, if found. Allocated via malloc().
|
|
/// @param o_error A pointer to an error message, if there is one. Allocated via malloc().
|
|
///
|
|
/// The callback implementor must use malloc() to allocate storage for
|
|
/// contents or error. The callback implementor must use free() to free
|
|
/// said storage after func_compile returns.
|
|
///
|
|
/// If the callback is not supported, *o_contents and *o_error must be set to NULL.
|
|
typedef void (*CStyleReadFileCallback)(char const* _kind, char const* _data, char** o_contents, char** o_error);
|
|
|
|
funC::ReadCallback::Callback wrapReadCallback(CStyleReadFileCallback _readCallback)
|
|
{
|
|
funC::ReadCallback::Callback readCallback;
|
|
if (_readCallback) {
|
|
readCallback = [=](funC::ReadCallback::Kind _kind, char const* _data) -> td::Result<std::string> {
|
|
char* contents_c = nullptr;
|
|
char* error_c = nullptr;
|
|
_readCallback(funC::ReadCallback::kindString(_kind).data(), _data, &contents_c, &error_c);
|
|
if (!contents_c && !error_c) {
|
|
return td::Status::Error("Callback not supported");
|
|
}
|
|
if (contents_c) {
|
|
return contents_c;
|
|
}
|
|
return td::Status::Error(std::string(error_c));
|
|
};
|
|
}
|
|
return readCallback;
|
|
}
|
|
|
|
extern "C" {
|
|
|
|
const char* version() {
|
|
auto version_json = td::JsonBuilder();
|
|
auto obj = version_json.enter_object();
|
|
obj("funcVersion", funC::func_version);
|
|
obj("funcFiftLibCommitHash", GitMetadata::CommitSHA1());
|
|
obj("funcFiftLibCommitDate", GitMetadata::CommitDate());
|
|
obj.leave();
|
|
return strdup(version_json.string_builder().as_cslice().c_str());
|
|
}
|
|
|
|
const char *func_compile(char *config_json, CStyleReadFileCallback callback) {
|
|
if (callback) {
|
|
funC::read_callback = wrapReadCallback(callback);
|
|
} else {
|
|
funC::read_callback = funC::fs_read_callback;
|
|
}
|
|
|
|
auto res = compile_internal(config_json);
|
|
|
|
if (res.is_error()) {
|
|
auto result = res.move_as_error();
|
|
auto error_res = td::JsonBuilder();
|
|
auto error_o = error_res.enter_object();
|
|
error_o("status", "error");
|
|
error_o("message", result.message().str());
|
|
error_o.leave();
|
|
return strdup(error_res.string_builder().as_cslice().c_str());
|
|
}
|
|
|
|
auto res_string = res.move_as_ok();
|
|
|
|
return strdup(res_string.c_str());
|
|
}
|
|
}
|