Skip to content

Commit 5d55a3f

Browse files
authored
Merge pull request #1 from zoowii/main
add package script and release action in github workflow
2 parents 2a7a1a2 + f57b683 commit 5d55a3f

File tree

4 files changed

+235
-0
lines changed

4 files changed

+235
-0
lines changed

.ci/package.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Check if lib directory exists
5+
if [ ! -d "lib" ]; then
6+
echo "lib directory not found, downloading dependencies..."
7+
./download_deps.sh
8+
fi
9+
10+
# Build based on platform
11+
platform=$(uname)
12+
if [ "$platform" = "Linux" ]; then
13+
echo "Building on Linux..."
14+
cd stdlib
15+
make release
16+
cd ..
17+
cargo build --release
18+
elif [ "$platform" = "Darwin" ]; then
19+
echo "Building on macOS..."
20+
make -f dev.makefile release
21+
else
22+
echo "Unsupported platform: $platform"
23+
exit 1
24+
fi
25+
26+
git config --global --add safe.directory $(pwd)
27+
28+
# Get git commit hash and branch name
29+
git_commit=$(git rev-parse --short HEAD)
30+
git_branch=$(git rev-parse --abbrev-ref HEAD)
31+
32+
# Replace forward slashes with underscores in git_branch
33+
git_branch=$(echo "$git_branch" | tr '/' '_')
34+
35+
36+
# Create package directory
37+
package_name="DTVM_SolSDK-${git_commit}-${git_branch}-${platform}"
38+
package_dir="/tmp/${package_name}"
39+
mkdir -p "$package_dir"
40+
41+
# Copy required files to package directory
42+
cp -r target/release/lib "$package_dir"
43+
cp target/release/yul2wasm "$package_dir" 2>/dev/null || echo "Warning: yul2wasm not found"
44+
cp docs/release_docs/* "$package_dir" 2>/dev/null || echo "Warning: release_docs not found"
45+
46+
# Create tarball in target/release directory
47+
mkdir -p "target/release"
48+
output_file="target/release/${package_name}.tar.gz"
49+
50+
# Remove existing file if it exists
51+
if [ -f "$output_file" ]; then
52+
echo "Removing existing package file: $output_file"
53+
rm -f "$output_file"
54+
fi
55+
56+
# Create the compressed package
57+
tar -czf "$output_file" -C /tmp "$package_name"
58+
59+
cp -f $output_file target/release/DTVM_SolSDK-${platform}-nightly.tar.gz
60+
61+
echo "Package created: $output_file and target/release/DTVM_SolSDK-${platform}-nightly.tar.gz"
62+
63+
# Clean up temporary directory
64+
rm -rf "$package_dir"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: nightly-release
2+
on:
3+
workflow_dispatch:
4+
paths:
5+
- '**'
6+
permissions:
7+
contents: write
8+
jobs:
9+
Artifact: # Pack and publish to Github Artifact
10+
runs-on: ubuntu-latest
11+
container:
12+
image: dtvmdev1/dtvm-sol-dev-x64:main
13+
steps:
14+
- name: Check out code
15+
uses: actions/checkout@v3
16+
with:
17+
lfs: true
18+
submodules: "true"
19+
- name: Build the Release
20+
working-directory: .
21+
run: |
22+
export CUR_PATH=$(pwd)
23+
# install rust
24+
/opt/install_rust.sh
25+
26+
. "$HOME/.cargo/env"
27+
export PATH=$HOME/.cargo/bin:$PATH
28+
29+
export LLVM_SYS_160_PREFIX=/opt/llvm16
30+
export LLVM_DIR=$LLVM_SYS_160_PREFIX/lib/cmake/llvm
31+
export PATH=$LLVM_SYS_160_PREFIX/bin:$PATH
32+
33+
./download_deps.sh
34+
.ci/package.sh
35+
# there should be a DTVM_SolSDK-*.tar.gz file under the target/release directory
36+
ls target/release
37+
- name: Upload Artifact to Github Releases
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: DTVM_SolSDK-Linux-nightly.tar.gz
41+
path: target/release/DTVM_SolSDK-Linux-nightly.tar.gz

.github/workflows/release.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Release
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
permissions:
7+
contents: write
8+
jobs:
9+
Artifact: # Pack and publish to Github Artifact
10+
runs-on: ubuntu-latest
11+
container:
12+
image: dtvmdev1/dtvm-sol-dev-x64:main
13+
steps:
14+
- name: Check out code
15+
uses: actions/checkout@v3
16+
with:
17+
lfs: true
18+
submodules: "true"
19+
- name: Build the Release
20+
working-directory: .
21+
run: |
22+
export CUR_PATH=$(pwd)
23+
# install rust
24+
/opt/install_rust.sh
25+
26+
. "$HOME/.cargo/env"
27+
export PATH=$HOME/.cargo/bin:$PATH
28+
29+
export LLVM_SYS_160_PREFIX=/opt/llvm16
30+
export LLVM_DIR=$LLVM_SYS_160_PREFIX/lib/cmake/llvm
31+
export PATH=$LLVM_SYS_160_PREFIX/bin:$PATH
32+
33+
./download_deps.sh
34+
.ci/package.sh
35+
# there should be a DTVM_SolSDK-*.tar.gz file under the target/release directory
36+
ls target/release
37+
- name: Upload Artifact to Github Releases
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: DTVM_SolSDK-linux-amd64
41+
path: target/release/DTVM_SolSDK-*.tar.gz

docs/release_docs/quick-start.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Quick Start Guide for DTVM_SolSDK
2+
3+
## Prerequisites
4+
5+
The fastest way to set up the compilation environment is to use a Docker image or build it based on the provided Dockerfile:
6+
7+
```bash
8+
docker pull dtvmdev1/dtvm-sol-dev-x64:main
9+
```
10+
11+
Before using DTVM_SolSDK, ensure the following dependencies are installed on your system:
12+
13+
- **LLVM 16** or **lld-16**
14+
- **solc** (Solidity compiler) or **Foundry**
15+
- **Binaryen** (Optional)
16+
17+
### Installing LLVM 16 or lld-16
18+
19+
```bash
20+
cd /opt
21+
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-16.0.4/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04.tar.xz
22+
tar -xvf clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04.tar.xz
23+
rm -rf clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04.tar.xz
24+
mv clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04 llvm16
25+
export LLVM_SYS_160_PREFIX=/opt/llvm16
26+
export PATH=$LLVM_SYS_160_PREFIX/bin:/opt:$PATH
27+
```
28+
29+
### Installing Solidity Compiler (solc)
30+
31+
Download the Solidity compiler from:
32+
[https://github.com/ethereum/solidity/releases](https://github.com/ethereum/solidity/releases)
33+
34+
### Installing Foundry
35+
36+
Install Foundry from:
37+
[https://getfoundry.sh/](https://getfoundry.sh/)
38+
39+
## Basic Usage
40+
41+
### Compiling a Solidity Contract to WebAssembly
42+
43+
The compilation process involves two main steps:
44+
45+
1. Compile Solidity to Yul IR using the Solidity compiler
46+
2. Compile Yul IR to WebAssembly using yul2wasm
47+
48+
Here's a basic example:
49+
50+
```bash
51+
# Step 1: Compile Solidity to Yul IR
52+
solc --ir --optimize-yul -o output_directory --overwrite your_contract.sol
53+
54+
# Step 2: Compile Yul IR to WebAssembly
55+
yul2wasm --input output_directory/ContractName.yul --output your_contract.wasm
56+
```
57+
58+
### Command Line Options
59+
60+
yul2wasm provides several command-line options:
61+
62+
| Option | Description |
63+
|--------|-------------|
64+
| `--input <file>` | Specify the input Yul file (required) |
65+
| `--output <file>` | Specify the output WebAssembly file (required) |
66+
| `--verbose` | Enable verbose output for debugging |
67+
| `--debug` | Generate debug information |
68+
| `--opt-level <level>` | Set LLVM optimization level (0-3, default: 3) |
69+
70+
### Output File Types
71+
72+
When working with yul2wasm, you'll encounter several file types:
73+
74+
- `.wasm`: WebAssembly binary format - the final compiled contract that can be deployed on Wasm-based blockchains
75+
- `.cbin`: Contract binary format - contains the compiled bytecode of the contract
76+
- `.cbin.hex`: Hexadecimal representation of the contract binary - useful for deployment and verification
77+
78+
### Converting WebAssembly to Text Format (WAT)
79+
80+
For inspection or debugging, you can convert the binary WebAssembly to text format:
81+
82+
```bash
83+
wasm2wat -o your_contract.wat your_contract.wasm
84+
```
85+
86+
## Troubleshooting
87+
88+
For common issues, security best practices, and more detailed information, please contact us through:
89+
[https://github.com/DTVMStack/DTVM_SolSDK/issues](https://github.com/DTVMStack/DTVM_SolSDK/issues)

0 commit comments

Comments
 (0)