Skip to content

Commit

Permalink
Merge pull request #96 from sensorial-systems/dev
Browse files Browse the repository at this point in the history
Ligen 0.9
  • Loading branch information
notdanilo authored Oct 17, 2023
2 parents 19dcb74 + 1d21b34 commit 872069d
Show file tree
Hide file tree
Showing 363 changed files with 8,964 additions and 4,672 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Checks

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

env:
CARGO_TERM_COLOR: always

jobs:
test:
name: Test on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macOS-latest] # ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: All targets checks
run: cargo check --workspace --all-targets
# - name: All features checks
# run: cargo check --workspace --all-features --lib --target wasm32-unknown-unknown
# - name: Rust Format checks
# run: cargo fmt --all -- --check
- name: Clippy checks
run: cargo clippy --workspace --all-targets --all-features -- -D warnings -W clippy::all
- name: Documentation tests
run: cargo test --workspace --doc
- name: All features for all targets tests
run: cargo test --workspace --all-targets --all-features
# - name: Web build test
# run: trunk build
29 changes: 0 additions & 29 deletions .github/workflows/tests.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# IntelliJ idea auto-generated files
.idea
.gradle

# Rust files
/target
Expand Down
74 changes: 63 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,66 @@
[workspace]
members = [
"ligen",
"ligen-c",
"ligen-cmake",
# "ligen-cpp/crates/core",
# "ligen-cpp/crates/macro",
# "ligen-cpp/crates/main",
# "ligen-cpp/examples/cpp-counter",
# "ligen-csharp/crates/core",
# "ligen-csharp/crates/macro",
# "ligen-csharp/crates/main",
# "ligen-csharp/examples/csharp-counter",
]
"ligen/common",
"ligen/ir",
"ligen/symbols",
"ligen/parsing",
"ligen/utils",
"ligen/traits",
"ecosystem/python/parser",
"ecosystem/rust/cargo",
"ecosystem/rust/example",
# "ecosystem/rust/exporter",
# "ecosystem/rust/runtime",
"ecosystem/rust/parser",
# "ecosystem/c/cmake",
# "ecosystem/c/generator",
"tools/editor/dependencies/gui-runtime",
"tools/editor"
]
resolver = "2"

[workspace.package]
version = "0.1.17"
edition = "2021"
description = "Ligen (Language Interface Generator) is an extensible automatic binding generator ecosystem."
authors = ["Danilo Guanabara <[email protected]>"]
license = "Apache-2.0"
documentation = "https://docs.rs/ligen"
readme = "README.md"

[workspace.dependencies]
ligen = { path = "ligen" }
ligen-common = { path = "ligen/common" }
ligen-ir = { path = "ligen/ir" }
ligen-macro = { path = "ligen/macro" }
ligen-parsing = { path = "ligen/parsing" }
ligen-traits = { path = "ligen/traits" }
ligen-utils = { path = "ligen/utils" }
ligen-symbols = { path = "ligen/symbols" }
#ligen-c = { path = "ecosystem/c/generator" }
#ligen-cmake = { path = "ecosystem/c/cmake" }
ligen-python-parser = { path = "ecosystem/python/parser" }
#ligen-rust-exporter = { path = "ecosystem/rust/exporter" }
ligen-rust-parser = { path = "ecosystem/rust/parser" }
ligen-cargo = { path = "ecosystem/rust/cargo" }
ligen-gui-runtime = { path = "tools/editor/dependencies/gui-runtime" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
shrinkwraprs = "0.3"
derive_more = "0.99"
lazy_static = "1.4.0"
pretty_assertions = "1.4.0"
syn = { version = "1.0.73", features = [ "full" ] }

[patch.crates-io]
# If you want to use the bleeding edge version of egui and eframe:
# egui = { git = "https://github.com/emilk/egui", branch = "master" }
# eframe = { git = "https://github.com/emilk/egui", branch = "master" }

# If you fork https://github.com/emilk/egui you can test with:
# egui = { path = "../egui/crates/egui" }
# eframe = { path = "../egui/crates/eframe" }

[profile.release]
opt-level = 2 # fast and small wasm
54 changes: 18 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,29 @@
# Ligen
Ligen (Language Interface Generator) is an extensible macro-based multi-language binding
Ligen (Language Interface Generator) is an extensible multi-language binding
generator.

We officially support `ligen-c`, a binding generator for the Programming Language C.
### Features

### Requirements
* Zero-effort binding generation
* ...

`cargo install cargo-ligen`

### How to use

Here is an example on how to use the C generator and the CMake project generator in your crate:
`Cargo.toml`
```toml
[build-dependencies]
ligen = "0.1"
ligen-c = "0.1"
ligen-cmake = "0.1"
```
### Getting started

Now you can use it in your `build.rs` file as following:
```rust
use ligen::prelude::*;
use ligen_c::Generator as CGenerator;
use ligen_cmake::Generator as CMakeGenerator;
TO-DO

fn main() {
if let Ok(project) = Project::read() {
let c_generator = CGenerator::default();
let cmake_generator = CMakeGenerator::default();
cmake_generator.generate(&project).expect("Couldn't generate CMake project.");
c_generator.generate(&project).expect("Couldn't generate C bindings");
}
}
```
### Languages Support

Then to generate the language bindings run: `cargo ligen`
| Language | Runtime | Importer | Exporter |
|----------|---------|----------|----------|
| Rust | Planned | Planned | WIP |
| C | Planned | Planned | Planned |
| C++ | Planned | Planned | Planned |
| Python | Planned | Planned | Planned |

`cargo ligen` passes all its extra parameters to `cargo build`, so you can use `cargo ligen --release` to
generate a library with optimized production code (`--debug` is default).
### Symbols parsing coverage examples

### Getting started
TODO: Add real examples. This is just a placeholder.

Here are a few links to get started:
* [List of officially supported languages](https://github.com/search?q=org%3Asensorial-systems+ligen).
* [Usage example](https://github.com/sensorial-systems/ligen-c/tree/main/examples/counter/README.md).
| Library | Language | Parsed | Total | Percent |
|-----------|----------|--------|-------|---------|
| Diffusers | Python | 531 | 2930 | 18.13% |
File renamed without changes.
12 changes: 12 additions & 0 deletions ecosystem/c/cmake/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
authors.workspace = true
edition.workspace = true
license.workspace = true
name = "ligen-cmake"
version = "0.1.4"
description = "CMake project generator"
documentation = "https://docs.rs/ligen-cmake"
readme = "README.md"

[dependencies]
ligen.workspace = true
File renamed without changes.
File renamed without changes.
34 changes: 34 additions & 0 deletions ecosystem/c/cmake/src/CMakeLists.txt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Auto-generated by ligen-cmake {generator_version}

CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
PROJECT("{project_name}")

IF(TARGET ${{PROJECT_NAME}})
RETURN()
ENDIF()

# INTERFACE is used to create a header-only library.
ADD_LIBRARY(${{PROJECT_NAME}} INTERFACE)
TARGET_INCLUDE_DIRECTORIES(${{PROJECT_NAME}} INTERFACE include)

# Set ligen root directory where we can find the binary libraries.
SET(LIGEN_DIR ${{CMAKE_CURRENT_SOURCE_DIR}}/../..)

IF(UNIX)
ELSEIF(WIN32)
SET(DYLIB_NAME ffi_${{PROJECT_NAME}}.dll)
SET(DYLIB_PATH ${{LIGEN_DIR}}/libraries/${{PROJECT_NAME}}/${{DYLIB_NAME}})
SET(STLIB_PATH ${{DYLIB_PATH}}.lib)
TARGET_LINK_LIBRARIES(${{PROJECT_NAME}} INTERFACE ${{STLIB_PATH}})
ENDIF()

# Detecting build type.
SET(BUILD_TYPE $<IF:$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>,Debug,Release>)

# Setting dynamic library output path.
SET(DYLIB_OUTPUT ${{CMAKE_BINARY_DIR}}/${{BUILD_TYPE}}/${{DYLIB_NAME}})

# Dynamic library copy operation.
ADD_CUSTOM_COMMAND(OUTPUT ${{DYLIB_OUTPUT}} COMMAND ${{CMAKE_COMMAND}} -E copy_if_different ${{DYLIB_PATH}} ${{DYLIB_OUTPUT}} DEPENDS ${{DYLIB_PATH}})
ADD_CUSTOM_TARGET(${{PROJECT_NAME}}_DYLIB DEPENDS ${{DYLIB_OUTPUT}})
ADD_DEPENDENCIES(${{PROJECT_NAME}} ${{PROJECT_NAME}}_DYLIB)
File renamed without changes.
29 changes: 10 additions & 19 deletions ligen-cmake/src/lib.rs → ecosystem/c/cmake/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
use ligen::prelude::*;
use ligen::generator::{FileSet, FileGenerator, FFIGenerator, ProjectVisitor};
use ligen::generator::File;
use ligen::traits::generator::file_generator::{File, FileSet, FileGenerator};
use std::path::PathBuf;
use ligen::ir::conventions::naming::SnakeCase;

/// CMake project generator.
#[derive(Debug, Clone)]
pub struct CMakeGenerator {
language: Language
}
pub struct CMakeGenerator(pub Language);

#[derive(Debug, Clone, Copy)]
pub enum Language {
C,
CPP
}

impl CMakeGenerator {
pub fn new(language: Language) -> Self {
Self { language }
impl FileGenerator for CMakeGenerator {
fn base_path(&self) -> PathBuf {
"c".into()
}
}

impl Generator for CMakeGenerator {}

impl FileGenerator for CMakeGenerator {
fn generate_files(&self, file_set: &mut FileSet, visitor: &ProjectVisitor) {
fn generate_files(&self, project: &Project, file_set: &mut FileSet) -> Result<()> {
let generator_version = env!("CARGO_PKG_VERSION");
let project_name = &visitor.current.arguments.crate_name;
let project_name = SnakeCase::try_from(project.name.clone())?.to_string();

let content = match self.language {
let content = match self.0 {
Language::CPP => format!(
include_str!("CMakeLists.txt.cpp"),
generator_version = generator_version,
Expand All @@ -42,9 +36,6 @@ impl FileGenerator for CMakeGenerator {
};
let file = File::new(PathBuf::from("CMakeLists.txt"), content);
file_set.insert(file);
Ok(())
}
}

impl FFIGenerator for CMakeGenerator {
fn generate_ffi(&self, _file: &mut File, _implementation: &ProjectVisitor) {}
}
File renamed without changes.
15 changes: 15 additions & 0 deletions ecosystem/c/example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
PROJECT("example-c")

IF(TARGET ${PROJECT_NAME})
RETURN()
ENDIF()

ADD_SUBDIRECTORY(deps/ctest)
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/../../target/ligen/c/example example)
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/../../target/ligen/c/ligen_rust_runtime ligen_rust_runtime)

AUX_SOURCE_DIRECTORY(src SOURCES)

ADD_EXECUTABLE(${PROJECT_NAME} ${SOURCES})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC ctest example ligen_rust_runtime)
6 changes: 6 additions & 0 deletions ecosystem/c/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
1. Generate the bindings: `ligen $ cargo build --features=bindings`
2. Running the C example:
1. Generate build directory: `ligen/examples/example-c $ mkdir build`
2. Generate project files: `ligen/examples/example-c/build $ cmake ..`
3. Build: `ligen/examples/example-c/build $ cmake --build .`
4. Run: `ligen/examples/example-c/build/Debug/example-c`
11 changes: 11 additions & 0 deletions ecosystem/c/example/deps/ctest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Auto-generated by ligen-cmake {generator_version}

CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
PROJECT("ctest")

IF(TARGET ${PROJECT_NAME})
RETURN()
ENDIF()

ADD_LIBRARY(${PROJECT_NAME} INTERFACE)
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} INTERFACE include)
8 changes: 8 additions & 0 deletions ecosystem/c/example/deps/ctest/include/ctest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <assert.h>

#define cassert(a) {\
assert(a);\
printf("Assertion succeeded: %s\n" , #a);\
}
Loading

0 comments on commit 872069d

Please sign in to comment.