Skip to content

Commit

Permalink
Import ideas
Browse files Browse the repository at this point in the history
  • Loading branch information
ayakoakasaka committed Nov 29, 2023
1 parent 9dfd9d5 commit 1980cea
Show file tree
Hide file tree
Showing 30 changed files with 2,441 additions and 65 deletions.
12 changes: 12 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BasedOnStyle: LLVM
PointerAlignment: Right
ColumnLimit: 79
IndentWidth: 8
TabWidth: 8
ContinuationIndentWidth: 8
ConstructorInitializerIndentWidth: 8
AlwaysBreakAfterReturnType: TopLevelDefinitions
BreakBeforeBraces: Linux
IndentGotoLabels: false
ForEachMacros: ["ARRAY_FOREACH", "LIST_FOREACH", "LIST_FOREACH_REVERSE", "VEC_FOREACH", "VEC_FOREACH_IDX"]
SpaceBeforeParens: ControlStatementsExceptControlMacros
9 changes: 9 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ubuntu:22.04

WORKDIR /home/

COPY . .

ENV PATH="/root/.cargo/bin:$PATH"

RUN bash ./setup.sh
32 changes: 32 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "Codespaces Rust Starter",
"extensions": [
"matklad.rust-analyzer",
"serayuzgur.crates",
"vadimcn.vscode-lldb",
"ms-vscode.makefile-tools",
"ms-vscode.cpptools-extension-pack"
],
"dockerFile": "Dockerfile",
"initCommands": [
"settings set target.disable-aslr false"
],
"settings": {
"editor.formatOnSave": true,
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh",
"environment": [
"RUST_BACKTRACE=1",
"RUST_LOG=debug",
"RUST_LOG_STYLE=always"
]
}
},
"terminal.integrated.defaultProfile.linux": "zsh",
"files.exclude": {
"**/CONTRIBUTING.md": true,
"**/LICENSE": true
}
}
}
30 changes: 30 additions & 0 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

## update and install 1st level of packages
apt-get update
apt-get install -y \
curl \
git \
gnupg2 \
jq \
sudo \
zsh \
build-essential \
cmake \
libssl-dev \
openssl \
unzip \
g++-12 \

update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-12 50

## Add package directories to PATH
export PATH="/usr/bin:/usr/local/bin:$PATH"

## update and install 2nd level of packages
apt-get install -y pkg-config

## install rustup and common components
curl https://sh.rustup.rs -sSf | sh -s -- -y

source $HOME/.cargo/env
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# A hack to enable some degree of syntax highlighting on GitHub. Should be removed if GitHub ever receives native support for Wit files.
*.wit linguist-language=Rust
6 changes: 4 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ jobs:
name: Check ABI files are up-to-date
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: WebAssembly/wit-abi-up-to-date@v15
- uses: actions/checkout@v4
- uses: WebAssembly/wit-abi-up-to-date@v16
with:
wit-bindgen: '0.14.0'
130 changes: 130 additions & 0 deletions .github/workflows/wasmtime.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: Wasmtime

on:
push:
branches: [ "main" ]
tags:
- "v*"
pull_request:
branches: [ "main" ]

concurrency:
group: cmake-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build-and-run:
env:
CC: ${{matrix.compiler}}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{matrix.os}}

steps:
- name: Install dependencies (rustup)
run: |
rustup target add wasm32-wasi
- name: Install dependencies (cargo)
run: |
cargo install --version 1.0.51 wasm-tools
cargo install --version 0.14.0 wit-bindgen-cli
- name: Install dependencies (ubuntu)
if: startsWith(matrix.os, 'ubuntu-')
run: sudo apt-get update && sudo apt-get install -y pax

- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install wasmtime (ubuntu)
if: startsWith(matrix.os, 'ubuntu-')
run: |
curl -O -L https://github.com/bytecodealliance/wasmtime/releases/download/v14.0.4/wasmtime-v14.0.4-x86_64-linux.tar.xz
tar xvJf wasmtime-v14.0.4-x86_64-linux.tar.xz
echo "WASMTIME=$(pwd -P)/wasmtime-v14.0.4-x86_64-linux/wasmtime" >> ${GITHUB_ENV}
- name: Install wasmtime (macOS)
if: startsWith(matrix.os, 'macos-')
run: |
curl -O -L https://github.com/bytecodealliance/wasmtime/releases/download/v14.0.4/wasmtime-v14.0.4-x86_64-macos.tar.xz
tar xvzf wasmtime-v14.0.4-x86_64-macos.tar.xz
echo "WASMTIME=$(pwd -P)/wasmtime-v14.0.4-x86_64-macos/wasmtime" >> ${GITHUB_ENV}
- name: Build guest (Rust)
run: |
./build.sh
working-directory: ${{github.workspace}}/guest

- name: Build guest (C)
run: |
./build.sh
working-directory: ${{github.workspace}}/guest_c

- name: Build host
run: |
cargo build
working-directory: ${{github.workspace}}/host

- name: Run (component)
run: |
cargo run ../guest/guest-component.wasm
working-directory: ${{github.workspace}}/host

- name: Check the output (component)
run: |
test $(ls *.jpg|wc -l) -eq 60
working-directory: ${{github.workspace}}/host

- name: Clean up the output (component)
run: |
rm *.jpg
working-directory: ${{github.workspace}}/host

- name: Run (wasmtime precompiled component)
run: |
cargo run ../guest/guest-component.cwasm
working-directory: ${{github.workspace}}/host

- name: Check the output (wasmtime precompiled component)
run: |
test $(ls *.jpg|wc -l) -eq 60
working-directory: ${{github.workspace}}/host

- name: Clean up the output (wasmtime precompiled component)
run: |
rm *.jpg
working-directory: ${{github.workspace}}/host

- name: Run (C, component)
run: |
cargo run ../guest_c/guest-component.wasm
working-directory: ${{github.workspace}}/host

- name: Check the output (C, component)
run: |
test $(ls *.jpg|wc -l) -eq 60
working-directory: ${{github.workspace}}/host

- name: Clean up the output (C, component)
run: |
rm *.jpg
working-directory: ${{github.workspace}}/host

- name: Run (C, wasmtime precompiled component)
run: |
cargo run ../guest_c/guest-component.cwasm
working-directory: ${{github.workspace}}/host

- name: Check the output (C, precompiled component)
run: |
test $(ls *.jpg|wc -l) -eq 60
working-directory: ${{github.workspace}}/host

- name: Clean up the output (C, precompiled component)
run: |
rm *.jpg
working-directory: ${{github.workspace}}/host
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*/target/*
*.lock
Loading

0 comments on commit 1980cea

Please sign in to comment.