Skip to content

Commit

Permalink
add new jobs and lint rust
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Jan 11, 2025
1 parent 6e78fba commit f620056
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 59 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/audity.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# .github/workflows/libwasmvm_audit.yml
name: libwasmvm_audit

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
libwasmvm_audit:
runs-on: ubuntu-latest
container:
image: rust:1.83.0
steps:
- uses: actions/checkout@v4
- name: Install OpenSSL
run: |
sudo apt update
sudo apt install libssl-dev
- name: Show Rust version information
run: rustc --version && cargo --version && rustup --version
- name: Install cargo-audit
run: cargo install --debug cargo-audit --version 0.21.0
- name: Run cargo-audit
working-directory: libwasmvm
run: cargo audit
51 changes: 51 additions & 0 deletions .github/workflows/libwasmvm-sanity.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# .github/workflows/libwasmvm_sanity.yml
name: libwasmvm_sanity

on:
push:
branches:
- main
- 0.14-dev
- GoIter-creation
- release/*
pull_request:
branches:
- main

jobs:
libwasmvm_sanity:
runs-on: ubuntu-latest
container:
image: rust:1.83.0
steps:
- uses: actions/checkout@v4
- name: Show Rust version information
run: rustc --version && cargo --version && rustup --version
- name: Add Rust components
run: rustup component add rustfmt
- name: Ensure libwasmvm/bindings.h is up-to-date
working-directory: libwasmvm
run: |
cargo check
CHANGES_IN_REPO=$(git status --porcelain bindings.h)
if [[ -n "$CHANGES_IN_REPO" ]]; then
echo "Repository is dirty. Showing 'git status' and 'git --no-pager diff' for debugging now:"
git status && git --no-pager diff
exit 1
fi
- name: Ensure internal/api/bindings.h is up to date
run: diff libwasmvm/bindings.h internal/api/bindings.h
- name: Check Rust formatting
working-directory: libwasmvm
run: cargo fmt -- --check
- name: Run unit tests
working-directory: libwasmvm
run: cargo test
- name: Build docs
working-directory: libwasmvm
run: cargo doc --no-deps
- name: Test docs
working-directory: libwasmvm
run: |
sed -i '/^crate-type = \["cdylib"\]/d' Cargo.toml
cargo test --doc
54 changes: 27 additions & 27 deletions libwasmvm/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ enum GoError {
};
typedef int32_t GoError;

typedef struct cache_t {
typedef struct CacheT {

} cache_t;
} CacheT;

/**
* A view into an externally owned byte slice (Go `[]byte`).
Expand Down Expand Up @@ -412,33 +412,33 @@ typedef struct GasReport {
uint64_t used_internally;
} GasReport;

struct cache_t *init_cache(struct ByteSliceView config, struct UnmanagedVector *error_msg);
struct CacheT *init_cache(struct ByteSliceView config, struct UnmanagedVector *error_msg);

struct UnmanagedVector store_code(struct cache_t *cache,
struct UnmanagedVector store_code(struct CacheT *cache,
struct ByteSliceView wasm,
bool checked,
bool persist,
struct UnmanagedVector *error_msg);

void remove_wasm(struct cache_t *cache,
void remove_wasm(struct CacheT *cache,
struct ByteSliceView checksum,
struct UnmanagedVector *error_msg);

struct UnmanagedVector load_wasm(struct cache_t *cache,
struct UnmanagedVector load_wasm(struct CacheT *cache,
struct ByteSliceView checksum,
struct UnmanagedVector *error_msg);

void pin(struct cache_t *cache, struct ByteSliceView checksum, struct UnmanagedVector *error_msg);
void pin(struct CacheT *cache, struct ByteSliceView checksum, struct UnmanagedVector *error_msg);

void unpin(struct cache_t *cache, struct ByteSliceView checksum, struct UnmanagedVector *error_msg);
void unpin(struct CacheT *cache, struct ByteSliceView checksum, struct UnmanagedVector *error_msg);

struct AnalysisReport analyze_code(struct cache_t *cache,
struct AnalysisReport analyze_code(struct CacheT *cache,
struct ByteSliceView checksum,
struct UnmanagedVector *error_msg);

struct Metrics get_metrics(struct cache_t *cache, struct UnmanagedVector *error_msg);
struct Metrics get_metrics(struct CacheT *cache, struct UnmanagedVector *error_msg);

struct UnmanagedVector get_pinned_metrics(struct cache_t *cache, struct UnmanagedVector *error_msg);
struct UnmanagedVector get_pinned_metrics(struct CacheT *cache, struct UnmanagedVector *error_msg);

/**
* frees a cache reference
Expand All @@ -448,9 +448,9 @@ struct UnmanagedVector get_pinned_metrics(struct cache_t *cache, struct Unmanage
* This must be called exactly once for any `*cache_t` returned by `init_cache`
* and cannot be called on any other pointer.
*/
void release_cache(struct cache_t *cache);
void release_cache(struct CacheT *cache);

struct UnmanagedVector instantiate(struct cache_t *cache,
struct UnmanagedVector instantiate(struct CacheT *cache,
struct ByteSliceView checksum,
struct ByteSliceView env,
struct ByteSliceView info,
Expand All @@ -463,7 +463,7 @@ struct UnmanagedVector instantiate(struct cache_t *cache,
struct GasReport *gas_report,
struct UnmanagedVector *error_msg);

struct UnmanagedVector execute(struct cache_t *cache,
struct UnmanagedVector execute(struct CacheT *cache,
struct ByteSliceView checksum,
struct ByteSliceView env,
struct ByteSliceView info,
Expand All @@ -476,7 +476,7 @@ struct UnmanagedVector execute(struct cache_t *cache,
struct GasReport *gas_report,
struct UnmanagedVector *error_msg);

struct UnmanagedVector migrate(struct cache_t *cache,
struct UnmanagedVector migrate(struct CacheT *cache,
struct ByteSliceView checksum,
struct ByteSliceView env,
struct ByteSliceView msg,
Expand All @@ -488,7 +488,7 @@ struct UnmanagedVector migrate(struct cache_t *cache,
struct GasReport *gas_report,
struct UnmanagedVector *error_msg);

struct UnmanagedVector migrate_with_info(struct cache_t *cache,
struct UnmanagedVector migrate_with_info(struct CacheT *cache,
struct ByteSliceView checksum,
struct ByteSliceView env,
struct ByteSliceView msg,
Expand All @@ -501,7 +501,7 @@ struct UnmanagedVector migrate_with_info(struct cache_t *cache,
struct GasReport *gas_report,
struct UnmanagedVector *error_msg);

struct UnmanagedVector sudo(struct cache_t *cache,
struct UnmanagedVector sudo(struct CacheT *cache,
struct ByteSliceView checksum,
struct ByteSliceView env,
struct ByteSliceView msg,
Expand All @@ -513,7 +513,7 @@ struct UnmanagedVector sudo(struct cache_t *cache,
struct GasReport *gas_report,
struct UnmanagedVector *error_msg);

struct UnmanagedVector reply(struct cache_t *cache,
struct UnmanagedVector reply(struct CacheT *cache,
struct ByteSliceView checksum,
struct ByteSliceView env,
struct ByteSliceView msg,
Expand All @@ -525,7 +525,7 @@ struct UnmanagedVector reply(struct cache_t *cache,
struct GasReport *gas_report,
struct UnmanagedVector *error_msg);

struct UnmanagedVector query(struct cache_t *cache,
struct UnmanagedVector query(struct CacheT *cache,
struct ByteSliceView checksum,
struct ByteSliceView env,
struct ByteSliceView msg,
Expand All @@ -537,7 +537,7 @@ struct UnmanagedVector query(struct cache_t *cache,
struct GasReport *gas_report,
struct UnmanagedVector *error_msg);

struct UnmanagedVector ibc_channel_open(struct cache_t *cache,
struct UnmanagedVector ibc_channel_open(struct CacheT *cache,
struct ByteSliceView checksum,
struct ByteSliceView env,
struct ByteSliceView msg,
Expand All @@ -549,7 +549,7 @@ struct UnmanagedVector ibc_channel_open(struct cache_t *cache,
struct GasReport *gas_report,
struct UnmanagedVector *error_msg);

struct UnmanagedVector ibc_channel_connect(struct cache_t *cache,
struct UnmanagedVector ibc_channel_connect(struct CacheT *cache,
struct ByteSliceView checksum,
struct ByteSliceView env,
struct ByteSliceView msg,
Expand All @@ -561,7 +561,7 @@ struct UnmanagedVector ibc_channel_connect(struct cache_t *cache,
struct GasReport *gas_report,
struct UnmanagedVector *error_msg);

struct UnmanagedVector ibc_channel_close(struct cache_t *cache,
struct UnmanagedVector ibc_channel_close(struct CacheT *cache,
struct ByteSliceView checksum,
struct ByteSliceView env,
struct ByteSliceView msg,
Expand All @@ -573,7 +573,7 @@ struct UnmanagedVector ibc_channel_close(struct cache_t *cache,
struct GasReport *gas_report,
struct UnmanagedVector *error_msg);

struct UnmanagedVector ibc_packet_receive(struct cache_t *cache,
struct UnmanagedVector ibc_packet_receive(struct CacheT *cache,
struct ByteSliceView checksum,
struct ByteSliceView env,
struct ByteSliceView msg,
Expand All @@ -585,7 +585,7 @@ struct UnmanagedVector ibc_packet_receive(struct cache_t *cache,
struct GasReport *gas_report,
struct UnmanagedVector *error_msg);

struct UnmanagedVector ibc_packet_ack(struct cache_t *cache,
struct UnmanagedVector ibc_packet_ack(struct CacheT *cache,
struct ByteSliceView checksum,
struct ByteSliceView env,
struct ByteSliceView msg,
Expand All @@ -597,7 +597,7 @@ struct UnmanagedVector ibc_packet_ack(struct cache_t *cache,
struct GasReport *gas_report,
struct UnmanagedVector *error_msg);

struct UnmanagedVector ibc_packet_timeout(struct cache_t *cache,
struct UnmanagedVector ibc_packet_timeout(struct CacheT *cache,
struct ByteSliceView checksum,
struct ByteSliceView env,
struct ByteSliceView msg,
Expand All @@ -609,7 +609,7 @@ struct UnmanagedVector ibc_packet_timeout(struct cache_t *cache,
struct GasReport *gas_report,
struct UnmanagedVector *error_msg);

struct UnmanagedVector ibc_source_callback(struct cache_t *cache,
struct UnmanagedVector ibc_source_callback(struct CacheT *cache,
struct ByteSliceView checksum,
struct ByteSliceView env,
struct ByteSliceView msg,
Expand All @@ -621,7 +621,7 @@ struct UnmanagedVector ibc_source_callback(struct cache_t *cache,
struct GasReport *gas_report,
struct UnmanagedVector *error_msg);

struct UnmanagedVector ibc_destination_callback(struct cache_t *cache,
struct UnmanagedVector ibc_destination_callback(struct CacheT *cache,
struct ByteSliceView checksum,
struct ByteSliceView env,
struct ByteSliceView msg,
Expand Down
26 changes: 13 additions & 13 deletions libwasmvm/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use crate::querier::GoQuerier;
use crate::storage::GoStorage;

#[repr(C)]
pub struct cache_t {}
pub struct CacheT {}

pub fn to_cache(ptr: *mut cache_t) -> Option<&'static mut Cache<GoApi, GoStorage, GoQuerier>> {
pub fn to_cache(ptr: *mut CacheT) -> Option<&'static mut Cache<GoApi, GoStorage, GoQuerier>> {
if ptr.is_null() {
None
} else {
Expand All @@ -30,12 +30,12 @@ pub fn to_cache(ptr: *mut cache_t) -> Option<&'static mut Cache<GoApi, GoStorage
pub extern "C" fn init_cache(
config: ByteSliceView,
error_msg: Option<&mut UnmanagedVector>,
) -> *mut cache_t {
) -> *mut CacheT {
let r = catch_unwind(|| do_init_cache(config)).unwrap_or_else(|err| {
handle_vm_panic("do_init_cache", err);
Err(Error::panic())
});
handle_c_error_ptr(r, error_msg) as *mut cache_t
handle_c_error_ptr(r, error_msg) as *mut CacheT
}

fn do_init_cache(config: ByteSliceView) -> Result<*mut Cache<GoApi, GoStorage, GoQuerier>, Error> {
Expand All @@ -49,7 +49,7 @@ fn do_init_cache(config: ByteSliceView) -> Result<*mut Cache<GoApi, GoStorage, G

#[no_mangle]
pub extern "C" fn store_code(
cache: *mut cache_t,
cache: *mut CacheT,
wasm: ByteSliceView,
checked: bool,
persist: bool,
Expand Down Expand Up @@ -81,7 +81,7 @@ fn do_store_code(

#[no_mangle]
pub extern "C" fn remove_wasm(
cache: *mut cache_t,
cache: *mut CacheT,
checksum: ByteSliceView,
error_msg: Option<&mut UnmanagedVector>,
) {
Expand Down Expand Up @@ -110,7 +110,7 @@ fn do_remove_wasm(

#[no_mangle]
pub extern "C" fn load_wasm(
cache: *mut cache_t,
cache: *mut CacheT,
checksum: ByteSliceView,
error_msg: Option<&mut UnmanagedVector>,
) -> UnmanagedVector {
Expand Down Expand Up @@ -140,7 +140,7 @@ fn do_load_wasm(

#[no_mangle]
pub extern "C" fn pin(
cache: *mut cache_t,
cache: *mut CacheT,
checksum: ByteSliceView,
error_msg: Option<&mut UnmanagedVector>,
) {
Expand Down Expand Up @@ -170,7 +170,7 @@ fn do_pin(

#[no_mangle]
pub extern "C" fn unpin(
cache: *mut cache_t,
cache: *mut CacheT,
checksum: ByteSliceView,
error_msg: Option<&mut UnmanagedVector>,
) {
Expand Down Expand Up @@ -278,7 +278,7 @@ fn set_to_csv(set: BTreeSet<impl AsRef<str>>) -> String {

#[no_mangle]
pub extern "C" fn analyze_code(
cache: *mut cache_t,
cache: *mut CacheT,
checksum: ByteSliceView,
error_msg: Option<&mut UnmanagedVector>,
) -> AnalysisReport {
Expand Down Expand Up @@ -357,7 +357,7 @@ impl From<cosmwasm_vm::Metrics> for Metrics {

#[no_mangle]
pub extern "C" fn get_metrics(
cache: *mut cache_t,
cache: *mut CacheT,
error_msg: Option<&mut UnmanagedVector>,
) -> Metrics {
let r = match to_cache(cache) {
Expand Down Expand Up @@ -412,7 +412,7 @@ impl From<cosmwasm_vm::PinnedMetrics> for PinnedMetrics {

#[no_mangle]
pub extern "C" fn get_pinned_metrics(
cache: *mut cache_t,
cache: *mut CacheT,
error_msg: Option<&mut UnmanagedVector>,
) -> UnmanagedVector {
let r = match to_cache(cache) {
Expand Down Expand Up @@ -442,7 +442,7 @@ fn do_get_pinned_metrics(
/// This must be called exactly once for any `*cache_t` returned by `init_cache`
/// and cannot be called on any other pointer.
#[no_mangle]
pub extern "C" fn release_cache(cache: *mut cache_t) {
pub extern "C" fn release_cache(cache: *mut CacheT) {
if !cache.is_null() {
// this will free cache when it goes out of scope
let _ = unsafe { Box::from_raw(cache as *mut Cache<GoApi, GoStorage, GoQuerier>) };
Expand Down
Loading

0 comments on commit f620056

Please sign in to comment.