Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/initial support for rust #35

Merged
merged 44 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
cc06baf
create empty rust project
MLanghammer Mar 19, 2024
327d8c7
add rust model
MLanghammer Mar 22, 2024
4f2e012
add rust builder for mpsr files
MLanghammer Mar 23, 2024
bda80a4
mps-cli-rs: slight improvements
danielratiu May 10, 2024
084c209
first working version
danielratiu May 17, 2024
18f17a5
mini improvement
danielratiu May 17, 2024
416d109
added profiling
danielratiu May 17, 2024
6868e85
rs: cleanup
danielratiu May 18, 2024
69b1c9a
rs: simplify the code
danielratiu May 18, 2024
8ae3f91
mps-cli.rs: cleanup
danielratiu May 20, 2024
87f6f21
mps-cli.rs: support for imported models
danielratiu May 20, 2024
56d857e
mps-cli.rs: get_descendants of nodes, get_nodes of a model - new tests
danielratiu May 21, 2024
58b3d76
mps-cli.rs: cleanup code
danielratiu May 21, 2024
0a82045
mps-cli.rst: cleanup
danielratiu May 22, 2024
aaa3950
mps-cli.rs: added support for SNodeRef
danielratiu May 22, 2024
3ca5588
mini fix
danielratiu May 23, 2024
c7119ed
mini fix for cases when no resolveInfo is found
danielratiu May 24, 2024
df45b3d
mini improvement
danielratiu May 24, 2024
9c894f5
simplified the code
danielratiu May 24, 2024
3bbe8d2
rs: cleanup + restructured tests
danielratiu Jun 6, 2024
ad6681b
rs: improved tests
danielratiu Jun 8, 2024
0b0e2e1
rs: fixed snoderef
danielratiu Jun 8, 2024
dee859c
rs: added node-id decoding utils
danielratiu Jun 16, 2024
63b07d7
rs: cleanup code
danielratiu Jun 19, 2024
851a5cb
py: improved demo.py
danielratiu Jun 19, 2024
ddb3958
rs: cleanup
danielratiu Jun 19, 2024
a175afe
github: initial workflow for rust
danielratiu Jun 19, 2024
8cbfb2e
rs: simplified SNode struct
danielratiu Jul 23, 2024
b0dd4ff
rs: simplified slanguage_builder
danielratiu Jul 23, 2024
14a41cb
rs: simplified smodel builder
danielratiu Jul 23, 2024
c7a874c
rs: simplified srepository
danielratiu Jul 23, 2024
e714672
rs: simplified the code
danielratiu Jul 24, 2024
a788f79
rs: simplification
danielratiu Jul 24, 2024
0af3761
rs: simplification
danielratiu Jul 26, 2024
5ab3fd8
rs: simplify the code
danielratiu Jul 27, 2024
8638a37
rs: cleanup
danielratiu Jul 27, 2024
e16d4bd
rs: cleanup
danielratiu Jul 28, 2024
544bd23
rs: extract common functionality for building models in smodel_builde…
danielratiu Jul 28, 2024
512e194
rs: initial step for support for default persistency
danielratiu Jul 28, 2024
f0bfa90
rs: handling default persistency
danielratiu Jul 28, 2024
ea8cabb
rs: fixed workflow
danielratiu Jul 28, 2024
8d79a91
rs: fixed workflow
danielratiu Jul 28, 2024
20b8bc6
rs: fixed test
danielratiu Jul 28, 2024
9029df2
Merge branch 'main' into feature/mps-cli-rust-initial-support-2
danielratiu Jul 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/mps_cli_rs_build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: MPS-CLI-RS_CI

on:
push:
branches:
- 'main'
pull_request:
workflow_dispatch:

env:
GITHUB_TOKEN: ${{ secrets.MPSCLI_GITHUB_PKG_REGISTRY }}

jobs:
build_mps_cli_rs:
runs-on: ubuntu-latest
env:
DISPLAY: ':99'

steps:
- uses: actions/checkout@v3
- uses: hecrj/setup-rust-action@v1
with:
rust-version: stable
- name: Run tests
working-directory: ./mps-cli-rs
run: cargo test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
**/venv/
**/node_modules/
**/dist/
/mps-cli-rs/target

gradle.properties
**/workspace.xml
Expand Down
3 changes: 2 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ This repository contains tooling for reading MPS models from command line - with
### Repository Structure
- `mps-cli-gradle-plugin` - the gradle plugin to read MPS models
- `mps-cli-py` - a Python library to read MPS models
- `mps-cli-ts` - a Typescript library to read MPS models
- `mps-cli-ts` - a Typescript library to read MPS models
- `mps-cli-ts` - a Rust library to read MPS models
- `demos` - examples for the use of the MPS-CLI tooling
- `gradle-plugin-use` - example of the use of the `mps-cli-gradle-plugin`
- `jupyter-notebook` - example of the use of the `mps-cli-py` library in a Jupyter Notebook
Expand Down
10 changes: 9 additions & 1 deletion mps-cli-py/.idea/workspace.xml

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

5 changes: 3 additions & 2 deletions mps-cli-py/src/mpscli/demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
sys.path.insert(1, '..')

from model.builder.SSolutionsRepositoryBuilder import SSolutionsRepositoryBuilder

builder = SSolutionsRepositoryBuilder()
#repo = builder.build('..\\..\\mps_test_projects\\mps_cli_lanuse_file_per_root')
repo = builder.build('..\\..\\..\\..\\E3_2.0_Solution\\solutions')
repo = builder.build('..\\..\\mps_test_projects\\mps_cli_lanuse_file_per_root')
7 changes: 7 additions & 0 deletions mps-cli-rs/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"rust-analyzer.linkedProjects": [
"./Cargo.toml",
"./Cargo.toml",
"./Cargo.toml"
]
}
67 changes: 67 additions & 0 deletions mps-cli-rs/Cargo.lock

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

22 changes: 22 additions & 0 deletions mps-cli-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "mps-cli"
version = "0.1.0"
edition = "2021"
license = "Eclipse Public License - v 2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
path = "src/lib.rs"

[features]
default = []
std = []

[dependencies]
walkdir = "2.5.0"
roxmltree = "0.20.0"

[profile.release]
lto = "fat"
codegen-units = 1
7 changes: 7 additions & 0 deletions mps-cli-rs/src/builder/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub(crate) mod smodules_repository_builder;
mod ssolution_builder;
mod smodel_builder_base;
mod smodel_builder_default_persistency;
mod smodel_builder_file_per_root_persistency;
mod slanguage_builder;
mod node_id_utils;
56 changes: 56 additions & 0 deletions mps-cli-rs/src/builder/node_id_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use std::collections::HashMap;

struct NodeIdEncodingUtils {
my_index_chars : String,
min_char : u8,
my_char_to_value : HashMap<usize, usize>,
}

impl NodeIdEncodingUtils {
pub(crate) fn new() -> Self {
let my_index_chars = String::from("0123456789abcdefghijklmnopqrstuvwxyz$_ABCDEFGHIJKLMNOPQRSTUVWXYZ");
let min_char = '$' as u8;
let mut my_char_to_value : HashMap<usize, usize> = HashMap::new();
let bytes = my_index_chars.as_bytes();
for i in 0..my_index_chars.len() {
let char_value = bytes[i] as u8;
let ii: usize = (char_value - min_char) as usize;
my_char_to_value.insert(ii, i);
}

NodeIdEncodingUtils {
my_index_chars : my_index_chars,
min_char : min_char,
my_char_to_value : my_char_to_value,
}
}

pub(crate) fn decode(&self, uid_string : String) -> String {
let mut res = 0;
let bytes = uid_string.as_bytes();
let mut c = bytes[0];
let ii : usize = (c as u8 - self.min_char) as usize;
let mut value = self.my_char_to_value[&ii];
res = value;
for idx in 1..uid_string.len() {
res = res << 6;
c = bytes[idx];
value = self.my_index_chars.find(c as char).unwrap();
res = res | value;
}
return res.to_string();
}

}

#[cfg(test)]
mod tests {
use crate::builder::node_id_utils::NodeIdEncodingUtils;

#[test]
fn test_conversion() {
let node_id_utils = NodeIdEncodingUtils::new();

assert_eq!("5731700211660045983", node_id_utils.decode(String::from("4Yb5JA31NUv")));
}
}
20 changes: 20 additions & 0 deletions mps-cli-rs/src/builder/playground.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::cell::RefCell;
use std::rc::Rc;

struct Person {
name: String,
}

struct Company {
employees: RefCell<Vec<Rc<Person>>>,
}

impl Company {
fn search_employee(&self, name: &str) -> Option<Rc<Person>> {
self.employees
.borrow()
.iter()
.find(|employee| employee.name == name)
.map(|employee| Rc::clone(employee))
}
}
57 changes: 57 additions & 0 deletions mps-cli-rs/src/builder/slanguage_builder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;

use crate::model::sconcept::{SConcept, SContainmentLink, SProperty, SReferenceLink};
use crate::model::slanguage::SLanguage;


pub(crate) struct SLanguageBuilder {
pub concept_id_to_concept : RefCell<HashMap<String, Rc<SConcept>>>,
}

impl<'a> SLanguageBuilder {
pub(crate) fn new() -> Self {
SLanguageBuilder {
concept_id_to_concept: RefCell::new(HashMap::new()),
}
}

pub(crate) fn get_or_create_concept(&self, language: &mut SLanguage, concept_id: &str, concept_name: &str) -> Rc<SConcept> {
let mut concept_id_to_concept = self.concept_id_to_concept.borrow_mut();
let concept = concept_id_to_concept.get(concept_id);
if let Some(c) = concept {
return Rc::clone(c);
}

let concept = SConcept::new(concept_name.to_string(), concept_id.to_string());
let rc = Rc::new(concept);
concept_id_to_concept.insert(concept_id.to_string(), rc.clone());
language.concepts.push(rc.clone());
rc
}


pub(crate) fn get_or_create_property(&'a self, concept: Rc<SConcept>, property_id: String, property_name: String) -> Rc<SProperty> {
let mut props = concept.properties.borrow_mut();
let property = props.entry(property_id.clone()).or_insert(Rc::new(SProperty::new(property_name, property_id)));
Rc::clone(property)
}

pub(crate) fn get_or_create_child(&'a self, concept: Rc<SConcept>, child_id: String, child_name: String) -> Rc<SContainmentLink> {
let mut links = concept.containment_links.borrow_mut();
let containment_link = links.entry(child_id.clone()).or_insert(Rc::new(SContainmentLink::new(child_name, child_id)));
Rc::clone(containment_link)
}

pub(crate) fn get_or_create_reference(&'a self, concept: Rc<SConcept>, reference_id: String, reference_name: String) -> Rc<SReferenceLink> {
let mut refs = concept.reference_links.borrow_mut();
let reference_link = refs.entry(reference_id.clone()).or_insert(Rc::new(SReferenceLink::new(reference_name, reference_id)));
Rc::clone(reference_link)
}

}

pub(crate) fn get_or_build_language<'a>(language_id: &String, language_name: &String, language_id_to_slanguage: &'a mut HashMap<String, SLanguage>) -> &'a mut SLanguage {
language_id_to_slanguage.entry(language_id.to_string()).or_insert_with(|| SLanguage::new(language_name.to_string(), language_id.to_string()))
}
Loading
Loading