Skip to content

Commit

Permalink
Merge up this branch in the ci
Browse files Browse the repository at this point in the history
  • Loading branch information
prozacchiwawa committed May 14, 2023
2 parents ae434ae + 0a6a14a commit 01259f2
Show file tree
Hide file tree
Showing 20 changed files with 372 additions and 188 deletions.
81 changes: 36 additions & 45 deletions .github/workflows/build-arm64-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,65 +13,63 @@ on:

jobs:
build_wheels:
name: ARM64 Python Wheels on ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [[ARM64, Linux]]
name: Build ARM64 Python Wheels
runs-on: [ARM64, Linux]
container:
image: ghcr.io/chia-network/build-images/centos-pypa-rust-aarch64:latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 1

- name: Set up QEMU on x86_64
if: startsWith(matrix.os, 'ubuntu-latest')
id: qemu
uses: docker/setup-qemu-action@v2
with:
platforms: arm64

- name: Set up
run: |
echo "${PATH}"
yum -y install openssl-devel
source /root/.cargo/env
rustup default stable
rustup target add aarch64-unknown-linux-musl
rm -rf venv
export PATH="${PATH}:/opt/python/cp39-cp39/bin/:/opt/python/cp38-cp38/bin/:/opt/python/cp37-cp37m/bin/"
- name: Build Python wheels
run: |
podman run --rm=true \
-v ${{ github.workspace }}:/ws:rw --workdir=/ws \
quay.io/pypa/manylinux2014_aarch64 \
bash -exc '\
echo $PATH && \
curl -L https://sh.rustup.rs > rustup-init.sh && \
sh rustup-init.sh -y && \
yum -y install openssl-devel && \
source $HOME/.cargo/env && \
rustup target add aarch64-unknown-linux-musl && \
rm -rf venv && \
export PATH=/opt/python/cp39-cp39/bin/:$PATH && \
export PATH=/opt/python/cp38-cp38/bin/:$PATH && \
export PATH=/opt/python/cp37-cp37m/bin/:$PATH && \
/opt/python/cp38-cp38/bin/python -m venv venv && \
if [ ! -f "activate" ]; then ln -s venv/bin/activate; fi && \
. ./activate && \
pip install maturin==0.12.20 && \
CC=gcc maturin build --release --strip --manylinux 2014 \
--no-sdist --cargo-extra-args=--all-features \
'
/opt/python/cp38-cp38/bin/python -m venv venv
if [ ! -f "activate" ]; then ln -s venv/bin/activate; fi
. ./activate
pip install maturin==0.12.20
CC=gcc maturin build --release --strip --manylinux 2014 --no-sdist --cargo-extra-args=--all-features
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: wheels
path: target/wheels/

- name: Clean up AMR64
run: |
rm -rf venv
rm -rf dist
publish_wheels:
name: Publish ARM64 Python Wheels
runs-on: ubuntu-latest
needs: build_wheels
steps:
- name: Fetch wheels from previous job
uses: actions/download-artifact@v3
with:
name: wheels
path: target/wheels/

- name: Install Twine
run: |
if [ ! -f "venv" ]; then rm -rf venv; fi
sudo apt-get install python3-venv python3-pip -y
sudo apt install python3 python3-pip -y
python3 -m venv venv
if [ ! -f "activate" ]; then ln -s venv/bin/activate; fi
. ./activate
pip install setuptools_rust
pip install twine
pip3 install setuptools_rust
pip3 install twine
- name: Test for secrets access
id: check_secrets
shell: bash
Expand All @@ -91,7 +89,6 @@ jobs:
run: |
. ./activate
twine upload --non-interactive --skip-existing --verbose 'target/wheels/*'
- name: publish (Test PyPi)
if: steps.check_secrets.outputs.HAS_SECRET
env:
Expand All @@ -102,9 +99,3 @@ jobs:
run: |
. ./activate
twine upload --non-interactive --skip-existing --verbose 'target/wheels/*'
- name: Clean up AMR64
if: startsWith(matrix.os, 'ARM64')
run: |
rm -rf venv
rm -rf dist
22 changes: 19 additions & 3 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ jobs:
run: |
podman run --rm=true \
-v ${{ github.workspace }}:/ws:rw --workdir=/ws \
quay.io/pypa/manylinux2010_x86_64 \
ghcr.io/chia-network/build-images/centos-pypa-rust-x86_64 \
bash -exc '\
curl -L https://sh.rustup.rs > rustup-init.sh && \
sh rustup-init.sh -y && \
yum -y install libc6 openssl-devel && \
source $HOME/.cargo/env && \
rustup target add x86_64-unknown-linux-musl && \
Expand Down Expand Up @@ -276,3 +274,21 @@ jobs:
- name: cargo test
run: cargo test

coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
- name: Install tarpaulin
run: cargo +nightly install cargo-tarpaulin
- name: Run tarpaulin
run: cargo tarpaulin --no-dead-code --engine llvm --workspace --all-features --ignore-panics --out Lcov
- name: Upload to Coveralls
uses: coverallsapp/github-action@v2
if: always()
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
with:
path-to-lcov: './lcov.info'
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# clvm_tools_rs Changelog

## 0.0.31 Chia CLVM Tools Rust 2023-04-17

### Added

- defconst was added.
- hierarchial debug was added.
- clvm command linetools: supported more command line features in both compiler front-ends.

2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clvm_tools_rs"
version = "0.1.30"
version = "0.1.31"
edition = "2018"
authors = ["Art Yerkes <[email protected]>"]
description = "tools for working with chialisp language; compiler, repl, python and wasm bindings"
Expand Down
13 changes: 7 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ bindings = "pyo3"
[project]
name = "clvm_tools_rs"

[project.scripts]
brun = "clvm_tools_rs.cmds:brun"
run = "clvm_tools_rs.cmds:run"
opc = "clvm_tools_rs.cmds:opc"
opd = "clvm_tools_rs.cmds:opd"
cldb = "clvm_tools_rs.cmds:cldb"
# - Reenable these when we switch over from clvm_tools.
# [project.scripts]
# brun = "clvm_tools_rs.cmds:brun"
# run = "clvm_tools_rs.cmds:run"
# opc = "clvm_tools_rs.cmds:opc"
# opd = "clvm_tools_rs.cmds:opd"
# cldb = "clvm_tools_rs.cmds:cldb"
67 changes: 0 additions & 67 deletions src/classic/clvm/__type_compatibility__.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,28 +170,6 @@ impl Bytes {
Bytes::new(Some(BytesFromType::Raw(concat_bin)))
}

pub fn slice(&self, start: usize, length: Option<usize>) -> Self {
let len = match length {
Some(x) => {
if self._b.len() > start + x {
x
} else {
self._b.len() - start
}
}
None => self._b.len() - start,
};
let mut ui8_clone = Vec::<u8>::with_capacity(len);
for i in start..start + len - 1 {
ui8_clone.push(self._b[i]);
}
Bytes::new(Some(BytesFromType::Raw(ui8_clone)))
}

pub fn subarray(&self, start: usize, length: Option<usize>) -> Self {
self.slice(start, length)
}

pub fn data(&self) -> &Vec<u8> {
&self._b
}
Expand Down Expand Up @@ -230,51 +208,6 @@ impl Bytes {
}
true
}

pub fn equal_to(&self, b: &Bytes) -> bool {
let slen = self._b.len();
let blen = b.length();
if slen != blen {
return false;
} else {
for i in 0..slen {
if b.at(i) != self._b[i] {
return false;
}
}
}
true
}

/**
* Returns:
* +1 if argument is smaller
* 0 if this and argument is the same
* -1 if argument is larger
* @param other
*/
pub fn compare(&self, other: Bytes) -> Ordering {
let slen = min(self._b.len(), other.length());

for i in 0..slen - 1 {
let diff: i32 = other.at(i) as i32 - self._b[i] as i32;
match (diff < 0, diff > 0) {
(true, _) => {
return Ordering::Less;
}
(_, true) => {
return Ordering::Greater;
}
_ => {}
}
}
if self._b.len() < slen {
return Ordering::Less;
} else if slen < other.length() {
return Ordering::Greater;
}
Ordering::Equal
}
}

impl Display for Bytes {
Expand Down
37 changes: 26 additions & 11 deletions src/classic/clvm_tools/clvmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ pub fn detect_modern(allocator: &mut Allocator, sexp: NodePtr) -> Option<i32> {
pub fn compile_clvm_text_maybe_opt(
allocator: &mut Allocator,
do_optimize: bool,
search_paths: &[String],
opts: Rc<dyn CompilerOpts>,
symbol_table: &mut HashMap<String, String>,
text: &str,
input_path: &str,
classic_with_opts: bool,
) -> Result<NodePtr, EvalErr> {
let ir_src = read_ir(text).map_err(|s| EvalErr(allocator.null(), s.to_string()))?;
let assembled_sexp = assemble_from_ir(allocator, Rc::new(ir_src))?;

if let Some(dialect) = detect_modern(allocator, assembled_sexp) {
let runner = Rc::new(DefaultProgramRunner::new());
let opts = Rc::new(DefaultCompilerOpts::new(input_path))
let opts = opts
.set_optimize(do_optimize)
.set_frontend_opt(dialect > 21)
.set_search_paths(search_paths);
.set_frontend_opt(dialect > 21);

let unopt_res = compile_file(allocator, runner.clone(), opts, text, symbol_table);
let res = if do_optimize {
Expand All @@ -123,7 +123,10 @@ pub fn compile_clvm_text_maybe_opt(
} else {
let compile_invoke_code = run(allocator);
let input_sexp = allocator.new_pair(assembled_sexp, allocator.null())?;
let run_program = run_program_for_search_paths(input_path, search_paths, false);
let run_program = run_program_for_search_paths(input_path, &opts.get_search_paths(), false);
if classic_with_opts {
run_program.set_compiler_opts(Some(opts));
}
let run_program_output =
run_program.run_program(allocator, compile_invoke_code, input_sexp, None)?;
Ok(run_program_output.1)
Expand All @@ -132,31 +135,41 @@ pub fn compile_clvm_text_maybe_opt(

pub fn compile_clvm_text(
allocator: &mut Allocator,
search_paths: &[String],
opts: Rc<dyn CompilerOpts>,
symbol_table: &mut HashMap<String, String>,
text: &str,
input_path: &str,
classic_with_opts: bool,
) -> Result<NodePtr, EvalErr> {
compile_clvm_text_maybe_opt(
allocator,
true,
search_paths,
opts,
symbol_table,
text,
input_path,
classic_with_opts,
)
}

pub fn compile_clvm_inner(
allocator: &mut Allocator,
search_paths: &[String],
opts: Rc<dyn CompilerOpts>,
symbol_table: &mut HashMap<String, String>,
filename: &str,
text: &str,
result_stream: &mut Stream,
classic_with_opts: bool,
) -> Result<(), String> {
let result = compile_clvm_text(allocator, search_paths, symbol_table, text, filename)
.map_err(|x| format!("error {} compiling {}", x.1, disassemble(allocator, x.0)))?;
let result = compile_clvm_text(
allocator,
opts,
symbol_table,
text,
filename,
classic_with_opts,
)
.map_err(|x| format!("error {} compiling {}", x.1, disassemble(allocator, x.0)))?;
sexp_to_stream(allocator, result, result_stream);
Ok(())
}
Expand All @@ -175,14 +188,16 @@ pub fn compile_clvm(
if compile {
let text = fs::read_to_string(input_path)
.map_err(|x| format!("error reading {input_path}: {x:?}"))?;
let opts = Rc::new(DefaultCompilerOpts::new(input_path)).set_search_paths(search_paths);

compile_clvm_inner(
&mut allocator,
search_paths,
opts,
symbol_table,
input_path,
&text,
&mut result_stream,
false,
)?;

let output_path_obj = Path::new(output_path);
Expand Down
2 changes: 2 additions & 0 deletions src/classic/clvm_tools/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ pub fn run(args: &[String]) {
io::stdout()
.write_all(s.get_value().data())
.expect("stdout");
io::stdout().flush().expect("stdout");
}

pub fn brun(args: &[String]) {
Expand All @@ -291,6 +292,7 @@ pub fn brun(args: &[String]) {
if let Err(e) = io::stdout().write_all(s.get_value().data()) {
println!("{e}")
}
io::stdout().flush().expect("stdout");
}

#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq)]
Expand Down
Loading

0 comments on commit 01259f2

Please sign in to comment.