Skip to content

Commit

Permalink
feat: add build release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
vuilder0 committed Oct 15, 2021
1 parent 842edff commit 9572c1c
Show file tree
Hide file tree
Showing 8 changed files with 545 additions and 2 deletions.
138 changes: 138 additions & 0 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: Build Release

on:
push:
branches:
- "main"

env:
BUILD_TYPE: Release


jobs:
create_release:
name: "Create Release"
runs-on: "ubuntu-latest"
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}

steps:
- name: Create release
id: create_release
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "latest"
prerelease: true
title: "Development Build"

build_emscripten:
name: Build for Emscripten
needs: create_release
runs-on: ubuntu-latest

steps:
- name: Remove unused software to free up space
run: |
# These are quick to delete and large enough to make a difference
rm -rf /usr/share/swift/ # 1.3 GB in 80 subdirs
rm -rf /usr/local/lib/android/sdk/build-tools/ # 2.1 GB in 450 subdirs
rm -rf /usr/share/dotnet/shared/ # 5.3 GB in 350 subdirs
rm -rf /usr/local/lib/android/sdk/ndk/ # 7.6 GB in 1500 subdirs
- uses: actions/checkout@v2

- name: Update Submodule
run: git submodule update --init --recursive

- name: Build
run: bash ${{github.workspace}}/scripts/build_emscripten.sh

- name: Upload Release Assets
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_name: soljson.js
asset_path: ${{github.workspace}}/upload/soljson.js
asset_content_type: application/octet-stream

build_linux:
name: Build for Linux
needs: create_release
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Update Submodule
run: git submodule update --init --recursive

- name: Install Dependencies
run: bash ${{github.workspace}}/scripts/install_deps.sh

- name: Build
run: bash ${{github.workspace}}/build.sh

- name: Compress Artifact
run: |
cd ${{github.workspace}}/build/solppc
tar -cvzf solppc_linux.tar.gz ./solppc
- name: Upload Release Assets
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_name: solppc_linux.tar.gz
asset_path: ${{github.workspace}}/build/solppc/solppc_linux.tar.gz
asset_content_type: application/octet-stream

build-macos:
name: Build for MacOS
needs: create_release
runs-on: macos-11

steps:
- uses: actions/checkout@v2

- name: Update Submodule
run: git submodule update --init --recursive

- name: Install Dependencies
run: |
bash ${{github.workspace}}/scripts/osx_install_dependencies.sh
- name: Build
run: |
mkdir -p build/
echo -n > prerelease.txt
cd build/
cmake .. -DSOLC_LINK_STATIC=1 -DCMAKE_BUILD_TYPE=Release
make -j3
- name: Compress Artifact
run: |
cd ${{github.workspace}}/build/solppc
tar -cvzf solppc_darwin.tar.gz ./solppc
- name: Upload Release Assets
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_name: solppc_darwin.tar.gz
asset_path: ${{github.workspace}}/build/solppc/solppc_darwin.tar.gz
asset_content_type: application/octet-stream









2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ docs/utils/*.pyc
deps/install
deps/cache
cmake-build-*/
upload/
soljson.js

# vim stuff
[._]*.sw[a-p]
Expand Down
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,12 @@ add_subdirectory(libyul)
add_subdirectory(libevmasm)
add_subdirectory(libsmtutil)
add_subdirectory(libsolidity)
add_subdirectory(solppc)
add_subdirectory(test)
add_subdirectory(libsolc)

if (NOT EMSCRIPTEN)
add_subdirectory(solppc)
endif()

if (TESTS AND NOT EMSCRIPTEN)
add_subdirectory(test)
endif()
14 changes: 14 additions & 0 deletions libsolc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include_directories(AFTER ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/solidity)

if (EMSCRIPTEN)
# Specify which functions to export in soljson.js.
# Note that additional Emscripten-generated methods needed by solc-js are
# defined to be exported in cmake/EthCompilerSettings.cmake.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s EXPORTED_FUNCTIONS='[\"_solidity_license\",\"_solidity_version\",\"_solidity_compile\",\"_solidity_alloc\",\"_solidity_free\",\"_solidity_reset\"]'")
add_executable(soljson libsolc.cpp libsolc.h)
target_link_libraries(soljson PRIVATE solidity)
else()
add_library(libsolc libsolc.cpp libsolc.h)
set_target_properties(libsolc PROPERTIES OUTPUT_NAME solc)
target_link_libraries(libsolc PRIVATE solidity)
endif()
162 changes: 162 additions & 0 deletions libsolc/libsolc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
This file is part of solidity.
solidity 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 3 of the License, or
(at your option) any later version.
solidity 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 solidity. If not, see <http://www.gnu.org/licenses/>.
*/
// SPDX-License-Identifier: GPL-3.0
/**
* @author Christian <c@ethdev.com>
* @date 2014
* Public compiler API.
*/

#include <libsolc/libsolc.h>
#include <libsolidity/interface/StandardCompiler.h>
#include <libsolidity/interface/Version.h>
#include <libyul/YulString.h>
#include <libsolutil/Common.h>
#include <libsolutil/JSON.h>

#include <cstdlib>
#include <list>
#include <string>

#include "license.h"

using namespace std;
using namespace solidity;
using namespace solidity::util;

using solidity::frontend::ReadCallback;
using solidity::frontend::StandardCompiler;

namespace
{

// The strings in this list must not be resized after they have been added here (via solidity_alloc()), because
// this may potentially change the pointer that was passed to the caller from solidity_alloc().
static list<string> solidityAllocations;

/// Find the equivalent to @p _data in the list of allocations of solidity_alloc(),
/// removes it from the list and returns its value.
///
/// If any invalid argument is being passed, it is considered a programming error
/// on the caller-side and hence, will call abort() then.
string takeOverAllocation(char const* _data)
{
for (auto iter = begin(solidityAllocations); iter != end(solidityAllocations); ++iter)
if (iter->data() == _data)
{
string chunk = move(*iter);
solidityAllocations.erase(iter);
return chunk;
}

abort();
}

/// Resizes a std::string to the proper length based on the occurrence of a zero terminator.
void truncateCString(string& _data)
{
size_t pos = _data.find('\0');
if (pos != string::npos)
_data.resize(pos);
}

ReadCallback::Callback wrapReadCallback(CStyleReadFileCallback _readCallback, void* _readContext)
{
ReadCallback::Callback readCallback;
if (_readCallback)
{
readCallback = [=](string const& _kind, string const& _data)
{
char* contents_c = nullptr;
char* error_c = nullptr;
_readCallback(_readContext, _kind.data(), _data.data(), &contents_c, &error_c);
ReadCallback::Result result;
result.success = true;
if (!contents_c && !error_c)
{
result.success = false;
result.responseOrErrorMessage = "Callback not supported.";
}
if (contents_c)
{
result.success = true;
result.responseOrErrorMessage = takeOverAllocation(contents_c);
}
if (error_c)
{
result.success = false;
result.responseOrErrorMessage = takeOverAllocation(error_c);
}
truncateCString(result.responseOrErrorMessage);
return result;
};
}
return readCallback;
}

string compile(string _input, CStyleReadFileCallback _readCallback, void* _readContext)
{
StandardCompiler compiler(wrapReadCallback(_readCallback, _readContext));
return compiler.compile(move(_input));
}

}

extern "C"
{
extern char const* solidity_license() noexcept
{
static string fullLicenseText = otherLicenses + licenseText;
return fullLicenseText.c_str();
}

extern char const* solidity_version() noexcept
{
return frontend::VersionString.c_str();
}

extern char* solidity_compile(char const* _input, CStyleReadFileCallback _readCallback, void* _readContext) noexcept
{
return solidityAllocations.emplace_back(compile(_input, _readCallback, _readContext)).data();
}

extern char* solidity_alloc(size_t _size) noexcept
{
try
{
return solidityAllocations.emplace_back(_size, '\0').data();
}
catch (...)
{
// most likely a std::bad_alloc(), if at all.
return nullptr;
}
}

extern void solidity_free(char* _data) noexcept
{
takeOverAllocation(_data);
}

extern void solidity_reset() noexcept
{
// This is called right before each compilation, but not at the end, so additional memory
// can be freed here.
yul::YulStringRepository::reset();
solidityAllocations.clear();
}
}
Loading

0 comments on commit 9572c1c

Please sign in to comment.