Skip to content

Commit

Permalink
feat: first commit, with binding generation, publish and caching on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
AugustoFKL committed Jul 24, 2023
1 parent 4a80c75 commit d82ad66
Show file tree
Hide file tree
Showing 16 changed files with 686 additions and 0 deletions.
Empty file added .cargo/config.toml
Empty file.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 4
max_line_length = 120

[*.md]
# double whitespace at end of line
# denotes a line break in Markdown
trim_trailing_whitespace = false

[{*.sh,*.yml,*.yaml}]
indent_size = 2
87 changes: 87 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Publish

on:
workflow_dispatch:
push:
tags:
- v*

env:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse

jobs:
publish:
strategy:
matrix:
triple:
- { os: 'ubuntu-latest', target: 'x86_64-unknown-linux-gnu', lib: 'libcicd_ffi.so' }
- { os: 'macos-latest', target: 'aarch64-apple-darwin', lib: 'libcicd_ffi.dylib' }
- { os: 'macos-latest', target: 'x86_64-apple-darwin', lib: 'libcicd_ffi.dylib' }
- { os: 'windows-latest', target: 'x86_64-pc-windows-msvc', lib: 'cicd_ffi.dll' }
env:
ARTIFACT_FILE_PATH: "./target/${{ matrix.triple.target }}/release/${{ matrix.triple.lib }}"
KOTLIN_BINDINGS_PATH: "./uniffi"
PYTHON_BINDINGS_PATH: "./cicd_ffi.py"
UDL_PATH: "./cicd_ffi/src/cicd_ffi.udl"
ZIP_NAME: "cicd_ffi-${{ matrix.triple.target }}.zip"
name: Publish artifacts for ${{ matrix.triple.os }} with ${{ matrix.triple.target }}
runs-on: ${{ matrix.triple.os }}

steps:
# Get current tag to use as the release name.
- name: Get current tag
id: tag
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT

# Get current date to use as the release as part of the release name.
- name: Get current date
id: date
run: echo "date=$(date --rfc-3339=date)" >> $GITHUB_OUTPUT

- uses: actions/checkout@v3
with:
submodules: recursive
token: ${{ secrets.PAT }}
fetch-depth: 1

- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
targets: "${{ matrix.triple.target }}"

- name: Generate Cargo.lock
run: cargo update

- name: Cache dependencies
uses: actions/cache/restore@v3
with:
path: |
~/.cargo/.crates.toml
~/.cargo/.crates2.json
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
./target
key: "${{ runner.os }}-rust-${{ matrix.triple.target }}-${{ hashFiles('**/Cargo.lock') }}"
restore-keys: "${{ runner.os }}-rust-${{ matrix.triple.target }}-"

- name: Build project
run: cargo build --release --target ${{ matrix.triple.target }}

- name: Build kotlin artifacts
run: cargo run --release --bin uniffi-bindgen generate ${{ env.UDL_PATH }} -l kotlin -o ./ --no-format

- name: Build python artifacts
run: cargo run --release --bin uniffi-bindgen generate ${{ env.UDL_PATH }} -l python -o ./ --no-format

- name: Zip artifacts
run: 7z a ${{ env.ZIP_NAME }} ${{ env.KOTLIN_BINDINGS_PATH }} ${{ env.PYTHON_BINDINGS_PATH }} ${{ env.ARTIFACT_FILE_PATH }}

- name: Upload development binaries to release
uses: svenstaro/upload-release-action@v2
with:
release_name: "[${{ steps.tag.outputs.tag }}] - ${{ steps.date.outputs.date }}"
repo_token: ${{ secrets.PAT }}
file: ${{ env.ZIP_NAME }}
asset_name: ${{ env.ZIP_NAME }}
tag: ${{ github.ref }}
143 changes: 143 additions & 0 deletions .github/workflows/update_caches.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: Update caches

on:
## Run on every push to the dev branch.
push:
branches:
- master
## Run every Wednesday and Sunday at 00:00 UTC.
schedule:
- cron: "0 0 * * 0,3"
## Manual trigger.
workflow_dispatch:

jobs:
cache-ubuntu:
strategy:
matrix:
triple:
# x86_64 architecture with the Linux GNU toolchain.
- { os: 'ubuntu-latest', target: 'x86_64-unknown-linux-gnu' }

name: Update Rust stable caches for ${{ matrix.triple.os }} with ${{ matrix.triple.target }}
runs-on: ${{ matrix.triple.os }}
steps:
# Checkout the repository and all its submodules, only with the latest commit.
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
token: ${{ secrets.PAT }}
fetch-depth: 1

# Install Rust stable.
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
targets: "${{ matrix.triple.target }}"

# Generate the Cargo.lock file. Since we ignore the lockfile on .gitignore, we need to generate it before we can check the cache.
- name: Generate Cargo.lock
run: cargo update

# Check if a cache exists for the given configuration.
- name: Check cache
id: cache
uses: actions/cache/restore@v3
with:
path: |
~/.cargo/.crates.toml
~/.cargo/.crates2.json
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
./target
key: "${{ runner.os }}-rust-${{ matrix.triple.target }}-${{ hashFiles('**/Cargo.lock') }}"
lookup-only: true

# Build the project if cache not found.
- name: Build project
if: steps.cache.outputs.cache-hit != 'true'
run: cargo build --workspace --release --target ${{ matrix.triple.target }}

# Save the cache if not found.
- name: Save cache
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v3
with:
path: |
~/.cargo/.crates.toml
~/.cargo/.crates2.json
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
./target
key: "${{ runner.os }}-rust-${{ matrix.triple.target }}-${{ hashFiles('**/Cargo.lock') }}"

# Since only Ubuntu is used for testing in a daily basis, we only need to cache the other platforms once in a while, for publishing.
cache-non-ubuntu:
strategy:
matrix:
triple:
# ARM64 (Apple Silicon) architecture for macOS.
- { os: 'macos-latest', target: 'aarch64-apple-darwin' }
# x86_64 architecture for macOS.
- { os: 'macos-latest', target: 'x86_64-apple-darwin' }
# x86_64 architecture for Windows using MSVC (Microsoft Visual C++).
- { os: 'windows-latest', target: 'x86_64-pc-windows-msvc' }

name: Update Rust stable caches for ${{ matrix.triple.os }} with ${{ matrix.triple.target }}
runs-on: ${{ matrix.triple.os }}
# if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
steps:
# Checkout the repository and all its submodules, only with the latest commit.
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
token: ${{ secrets.PAT }}
fetch-depth: 1

# Install Rust stable.
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
targets: "${{ matrix.triple.target }}"

# Generate the Cargo.lock file. Since we ignore the lockfile on .gitignore, we need to generate it before we can check the cache.
- name: Generate Cargo.lock
run: cargo update

# Check if a cache exists for the given configuration.
- name: Check cache
id: cache
uses: actions/cache/restore@v3
with:
path: |
~/.cargo/.crates.toml
~/.cargo/.crates2.json
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
./target
key: "${{ runner.os }}-rust-${{ matrix.triple.target }}-${{ hashFiles('**/Cargo.lock') }}"
lookup-only: true

# Build the project if cache not found.
- name: Build project
if: steps.cache.outputs.cache-hit != 'true'
run: cargo build --workspace --release --target ${{ matrix.triple.target }}

# Save the cache if not found.
- name: Save cache
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v3
with:
path: |
~/.cargo/.crates.toml
~/.cargo/.crates2.json
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
./target
key: "${{ runner.os }}-rust-${{ matrix.triple.target }}-${{ hashFiles('**/Cargo.lock') }}"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ Cargo.lock

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# IntelliJ IDEA
.idea/
*.iml
1 change: 1 addition & 0 deletions .rustc_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"rustc_fingerprint":8006516878952857912,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.71.0 (8ede3aae2 2023-07-12)\nbinary: rustc\ncommit-hash: 8ede3aae28fe6e4d52b38157d7bfe0d3bceef225\ncommit-date: 2023-07-12\nhost: x86_64-pc-windows-msvc\nrelease: 1.71.0\nLLVM version: 16.0.5\n","stderr":""},"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\Augusto\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\npacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""},"12744816824612481171":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\Augusto\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\npacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""}},"successes":{}}
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[workspace]

members = [
"cicd_ffi",
"cicd_tests",
]
21 changes: 21 additions & 0 deletions cicd_ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "cicd_ffi"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
name = "uniffi-bindgen"
path = "./src/uniffi-bindgen.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib"]
name = "cicd_ffi"

[dependencies]
cicd_tests = { path = "../cicd_tests" }
uniffi = { version = "0.24.1", features = ["cli"] }

[build-dependencies]
uniffi = { version = "0.24.1", features = ["build"] }
1 change: 1 addition & 0 deletions cicd_ffi/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() { uniffi::generate_scaffolding("./src/cicd_ffi.udl",).unwrap(); }
20 changes: 20 additions & 0 deletions cicd_ffi/src/cicd_ffi.udl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace cicd_ffi {


};

[Enum]
interface SchemaName {
Name(string name);
Authorization(string authorization);
SchemaNameAndAuthorization(string name, string authorization);
};

interface CreateSchema {
constructor(boolean if_not_exists, SchemaName schema_name);

boolean if_not_exists();


SchemaName schema_name();
};
6 changes: 6 additions & 0 deletions cicd_ffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub use cicd_tests::create_schema::{
CreateSchema,
SchemaName,
};

uniffi::include_scaffolding!("cicd_ffi");
3 changes: 3 additions & 0 deletions cicd_ffi/src/uniffi-bindgen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
uniffi::uniffi_bindgen_main()
}
9 changes: 9 additions & 0 deletions cicd_tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "cicd_tests"
version = "0.1.0"
edition = "2021"

[dependencies]
serde = { version = "1.0.96", features = ["derive"] }
serde_json = "1.0.96"
anyhow = "1.0.71"
Loading

0 comments on commit d82ad66

Please sign in to comment.