Skip to content

Commit 80bf4d5

Browse files
authored
Initial commit
0 parents  commit 80bf4d5

126 files changed

Lines changed: 7229 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build-lib.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: Build Electrostatic-Library
4+
5+
# Controls when the workflow will run
6+
on:
7+
# Triggers the workflow on push or pull request events but only for the "master" branch
8+
push:
9+
branches: [ "master" ]
10+
pull_request:
11+
branches: [ "master" ]
12+
13+
# Allows you to run this workflow manually from the Actions tab
14+
workflow_dispatch:
15+
16+
jobs:
17+
build-electrostatic-app:
18+
# runner images with architectures (variants)
19+
runs-on: ${{ matrix.os }}
20+
strategy:
21+
matrix:
22+
os: [ 'ubuntu-latest' ]
23+
name: Build Electrostatic Library
24+
25+
# Steps represent a sequence of tasks that will be executed as part of the job
26+
steps:
27+
- name: Checkout Job
28+
uses: actions/checkout@v3
29+
30+
- name: Setup Electrostatic-Sandbox Workstation
31+
run: chmod +rwx ./helper-scripts/setup-environment/setup-sandbox.sh && ./helper-scripts/setup-environment/setup-sandbox.sh
32+
33+
- name: User's Permissions Granting
34+
run: chmod +rwx ./helper-scripts/project-impl/*.sh && chmod +rwx ./helper-scripts/project-impl/post-compile/*.sh
35+
36+
- name: Building Electrostatic-Library Binaries
37+
run: sudo ./helper-scripts/project-impl/compile-all.sh
38+
39+
- name: Building Electrostatic-Library Examples
40+
run: sudo ./helper-scripts/project-impl/compile-examples.sh "-m64" "main.cpp" "executable-example" "linux" "x86-64" "x86-64/exe"
41+
42+
- name: Testing Electrostatic-app ELF
43+
run: sudo ./cmake-build/linux/x86-64/exe/executable-example.elf

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.buildconfig
2+
.Makefile
3+
# Ignore Gradle project-specific cache directory
4+
.gradle
5+
# Ignore Gradle/CMake build output directory
6+
build
7+
docs/doxygen
8+
cmake-build
9+
.so
10+
.cache
11+
.idea
12+
.vscode

CMakeLists.txt

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
cmake_minimum_required(VERSION 3.18.1)
2+
3+
# define a project with a version
4+
project(electrostatic-library VERSION 1.0)
5+
6+
# To generate compile_commands.json for your project,
7+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
8+
9+
###################### CMake Predefined Variables ######################
10+
############################################################
11+
12+
message(STATUS "Project: electrostatic-library")
13+
message(STATUS "Current Output in-comission: ${COMMISSION_OUTPUT}")
14+
message(STATUS "GCC: ${GCC_BIN}")
15+
message(STATUS "GPP: ${GPP_BIN}")
16+
message(STATUS "Build Static Library: ${BUILD_STATIC}")
17+
message(STATUS "Build Shared Library: ${BUILD_SHARED}")
18+
message(STATUS "Build Executable binary: ${BUILD_EXE}")
19+
message(STATUS "Compiler Options: ${INPUT_COMPILER_OPTIONS}")
20+
message(STATUS "Target architecture: ${TARGET}")
21+
message(STATUS "Toolchain Headers: ${HEADERS}")
22+
message(STATUS "Source Directory: ${SOURCES_DIR}")
23+
message(STATUS "Project sources: ${PROJECT_SOURCES}")
24+
message(STATUS "Dependencies: ${DEPENDENCIES}")
25+
message(STATUS "Building the binaries to: ${BUILD_DIR}")
26+
27+
###################### CMake Variables ######################
28+
############################################################
29+
30+
set(PROJECT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${SOURCES_DIR}")
31+
32+
set(commission_so "${COMMISSION_OUTPUT}")
33+
set(commission_a "${COMMISSION_OUTPUT}-a")
34+
set(commission_exe "${COMMISSION_OUTPUT}.elf")
35+
36+
set(CMAKE_C_COMPILER "${GCC_BIN}")
37+
set(CMAKE_CXX_COMPILER "${GPP_BIN}")
38+
set(COMPILER_OPTIONS "${TARGET} ${INPUT_COMPILER_OPTIONS}")
39+
40+
set(headers "${HEADERS}")
41+
42+
###################### Build routines ######################
43+
############################################################
44+
45+
# build an executable
46+
if (BUILD_EXE)
47+
# add a library target
48+
add_executable(${commission_exe}) # executable based on the static archive
49+
set_target_properties(${commission_exe} PROPERTIES COMPILE_FLAGS "${COMPILER_OPTIONS}" LINK_FLAGS "${COMPILER_OPTIONS}")
50+
# include headers for the target
51+
target_include_directories(${commission_exe} PUBLIC ${lib_headers} ${headers})
52+
target_link_libraries(${commission_exe} PUBLIC "${DEPENDENCIES}")
53+
# Start building the target
54+
target_sources(${commission_exe} PUBLIC "${PROJECT_SOURCES}")
55+
endif ()
56+
57+
if (BUILD_STATIC)
58+
# add a library target
59+
add_library(${commission_a} STATIC)
60+
# set both COMPILE_FLAGS and LINK_FLAGS to the specified binary architecture
61+
set_target_properties(${commission_a} PROPERTIES COMPILE_FLAGS "${COMPILER_OPTIONS}" LINK_FLAGS "${COMPILER_OPTIONS}")
62+
# include headers for the target
63+
target_include_directories(${commission_a} PUBLIC ${headers})
64+
target_link_libraries(${commission_a} PUBLIC "${DEPENDENCIES}")
65+
# Start building the target
66+
target_sources(${commission_a} PUBLIC "${PROJECT_SOURCES}")
67+
endif ()
68+
69+
# build a shared library version
70+
if (BUILD_SHARED)
71+
add_library(${commission_so} SHARED)
72+
set_target_properties(${commission_so} PROPERTIES COMPILE_FLAGS "${COMPILER_OPTIONS}" LINK_FLAGS "${COMPILER_OPTIONS}")
73+
target_include_directories(${commission_so} PUBLIC ${headers})
74+
target_link_libraries(${commission_so} PUBLIC "${DEPENDENCIES}")
75+
target_sources(${commission_so} PUBLIC "${PROJECT_SOURCES}")
76+
endif()

LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2025-2026, Electrostatic-Sandbox, Electrostat-Lab
4+
Author: Pavly G.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Electrostatic-Library
2+
> A library template utilizing the Electrostatic-Sandbox SDK, acting as an extension pack.
3+
4+
This is a template that builds a cross-platform native library for Linux variants, Android variants, and AVR MCU variants linking them against the Electrostatic-Sandbox SDK libraries. The library is built into static archives, and dynamic libraries. The template is also provided by `examples` module in which a single source file with a `main` function could be compiled and run on its respective system.
5+
6+
<img width="1147" height="290" alt="image" src="https://github.com/user-attachments/assets/d2b9a685-a063-4bf1-b0ee-bf4ce5e1d4f4" />
7+
8+
## System Requirements
9+
1) A GNU/Linux System or a WSL System.
10+
2) A minimum of 1GB RAM, and 4GB Disk Space.
11+
3) If planned Microcontroller development; ATMega32 and/or ATMega328p are the currently supported ones.
12+
4) If planned Android development; all Android variants are supported.
13+
14+
## Setup the Electrostatic Environment
15+
This will install missing dependencies (CLI tools and toolchains) in `/opt/electrostatic-sandbox` that shall be utilized by the SDK build front-end and CMake to build the applications.
16+
17+
```bash
18+
chmod +rwx ./helper-scripts/setup-environment/setup-sandbox.sh && \
19+
./helper-scripts/setup-environment/setup-sandbox.sh
20+
```
21+
22+
## Build the application binary (.elf)
23+
This will build the application binary to all supported platforms; usually if a new build routine is to be built, it has to go here.
24+
25+
```bash
26+
chmod +x ./helper-scripts/project-impl/compile-all.sh && \
27+
./helper-scripts/project-impl/compile-all.sh
28+
```
29+
30+
## Introducing other building routines using Bash
31+
Introducing other building routines is far easy. However, it's mostly dependent on whether the original SDK is supporting those platforms. If not yet, you will have to build a pre-compilation header that excludes the SDK for those unsupported systems or else you will get linking errors.
32+
33+
Usually the build routines will look like that in general:
34+
https://github.com/Electrostat-Lab/Electrostatic-Library/blob/a6d9669dde096c02285e28c5657aa2438793b367/helper-scripts/project-impl/compile-all-linux.sh#L1-L17
35+
36+
They are dependent on that abstraction:
37+
https://github.com/Electrostat-Lab/Electrostatic-Library/blob/a6d9669dde096c02285e28c5657aa2438793b367/helper-scripts/abstract/abstract-compile.sh#L1-L41
38+
39+
## Changing the project output name
40+
This could be attained by changing the variable `COMMISSION_LIB` and `COMMISSION_LIB_AR` in the `./helper-scripts/project-impl/variables.sh`:
41+
https://github.com/Electrostat-Lab/Electrostatic-Library/blob/a6d9669dde096c02285e28c5657aa2438793b367/helper-scripts/project-impl/variables.sh#L8-L9
42+
43+
## Adding new dependencies
44+
Add your dependencies in the `libs` directory with the system directory of choice if required (in case of platform-dependent binaries); the build script finds all libraries listed under this directory through this code snippet:
45+
https://github.com/Electrostat-Lab/Electrostatic-Library/blob/a6d9669dde096c02285e28c5657aa2438793b367/helper-scripts/project-impl/compile-electrostatic.sh#L27-L38
46+
47+
## Adding new examples to test the introduced APIs
48+
* Adding new examples could be achieved by creating new source code (single source files) under the `examples` module, and using the following command to compile and run the example:
49+
```bash
50+
$ ./helper-scripts/project-impl/compile-examples.sh "-m64" "main.cpp" "executable-example" "linux" "x86-64" "x86-64/exe"
51+
$ ./cmake-build/linux/x86-64/exe/executable-example.elf
52+
```
53+
> [!NOTE]
54+
> This command links the specified source example against the `Electrostatic-Sandbox SDK` libraries and the `Electroextension` library (your native library).
55+
56+
* Adding new examples for microcontroller programming is much the same, but will require uploading as a post-compilation script.
57+
58+
## Excluding parts of the source code (dissociating the source code into modules)
59+
This could be attained through the build routines of the supported systems by decomposing the source directory into sub-directories and pass them as source modules to the compilation front-end (Ccoffee); the following shows the use of all the source code as a single module:
60+
https://github.com/Electrostat-Lab/Electrostatic-Library/blob/a6d9669dde096c02285e28c5657aa2438793b367/helper-scripts/project-impl/compile-all-android.sh#L4-L12
61+
62+
## Build front-end automata, CMake, and Toolchains
63+
Essentially, the build architecture of the Electrostatic-Sandbox SDK is based on the idea of creating a front-end scripted API that creates a building automata, which entails taking an input and passing into a chain of states, and eventually ending with a terminal state; thus the recognition of the machine to the building holds if the terminal state is being reached by the program counter. The initial input to the automata is mainly a building routine instruction and the outputs are proceeded and could be found at the filesystems cmake-build and build, where the terminal output is produced.
64+
65+
The build of the Electrostatic-applications is much simpler than the SDK; it's literally a subset of it.
66+
67+
For more; refer to the [build architecture of the Electrostatic-Sandbox SDK](https://github.com/Electrostat-Lab/Electrostatic-Sandbox/blob/master/electrostatic-sandbox-framework/docs/system-build/architecture.md).

examples/main.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <stdio.h>
2+
#include <electrostatic/electronetsoft/comm/comm.h>
3+
4+
comm_protocol serial;
5+
comm_protocol parallel;
6+
7+
int main() {
8+
init_protocol_default(&serial, SERIAL_RS232, NULL);
9+
init_protocol_default(&parallel, IEEE_1284, NULL);
10+
parallel.open(0);
11+
serial.open(0);
12+
return 0;
13+
}
14+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
function build_sdk_() {
4+
# specify build targets
5+
BUILD_LINUX="${1}"
6+
BUILD_ANDROID="${2}"
7+
BUILD_MCU="${3}"
8+
9+
# compilation
10+
11+
# create the SDK build
12+
13+
# Zip the SDK build into a tar
14+
15+
# publish to maven-central
16+
}
17+
18+
function build_sdk__() {
19+
##
20+
return $?
21+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
function compile() {
4+
local GCC_BIN=${1}
5+
local GPP_BIN=${2}
6+
local INPUT_COMPILER_OPTIONS=${3}
7+
local TARGET=${4}
8+
local TOOLCHAIN_INCLUDES=${5}
9+
local JAVA_HOME=${6}
10+
local ELECTROSTATIC_CORE=${7}
11+
local BUILD_DIR=${8}
12+
local SOURCE_DIR=${9}
13+
14+
local TEMP=$(pwd)
15+
cd ${SOURCE_DIR}
16+
17+
cmake-3.19 "-DGCC_BIN=${GCC_BIN}" \
18+
"-DGPP_BIN=${GPP_BIN}" \
19+
"-DINPUT_COMPILER_OPTIONS=${INPUT_COMPILER_OPTIONS}" \
20+
"-DTARGET=${TARGET}" \
21+
"-DTOOLCHAIN_INCLUDES=${TOOLCHAIN_INCLUDES}" \
22+
"-DJAVA_HOME=${JAVA_HOME}" \
23+
"-DELECTROSTATIC_CORE=${ELECTROSTATIC_CORE}" \
24+
"-DBUILD_DIR=${BUILD_DIR}" \
25+
-S . -B "./cmake-build/${BUILD_DIR}"
26+
27+
cmake --build "./cmake-build/${BUILD_DIR}"
28+
cd ${TEMP}
29+
}
30+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
function compile() {
4+
local COMMISSION_OUTPUT=${1}
5+
local GCC_BIN=${2}
6+
local GPP_BIN=${3}
7+
local BUILD_STATIC=${4}
8+
local BUILD_SHARED=${5}
9+
local BUILD_EXE=${6}
10+
local INPUT_COMPILER_OPTIONS=${7}
11+
local TARGET=${8}
12+
local HEADERS=${9}
13+
local SOURCES_DIR=${10}
14+
local PROJECT_SOURCES=${11}
15+
local DEPENDENCIES=${12}
16+
local BUILD_DIR=${13}
17+
local CMAKE_DIR=${14}
18+
19+
local TEMP=$(pwd)
20+
21+
cd "${CMAKE_DIR}" || exit $?
22+
23+
cmake-3.19 "-DCOMMISSION_OUTPUT=${COMMISSION_OUTPUT}" \
24+
"-DGCC_BIN=${GCC_BIN}" \
25+
"-DGPP_BIN=${GPP_BIN}" \
26+
"-DBUILD_STATIC=${BUILD_STATIC}" \
27+
"-DBUILD_SHARED=${BUILD_SHARED}" \
28+
"-DBUILD_EXE=${BUILD_EXE}" \
29+
"-DINPUT_COMPILER_OPTIONS=${INPUT_COMPILER_OPTIONS}" \
30+
"-DTARGET=${TARGET}" \
31+
"-DHEADERS=${HEADERS}" \
32+
"-DSOURCES_DIR=${SOURCES_DIR}" \
33+
"-DPROJECT_SOURCES=${PROJECT_SOURCES}" \
34+
"-DDEPENDENCIES=${DEPENDENCIES}" \
35+
"-DBUILD_DIR=${BUILD_DIR}" \
36+
-S . -B "$(pwd)/${SOURCES_DIR}/cmake-build/${BUILD_DIR}"
37+
38+
cmake-3.19 --build "$(pwd)/${SOURCES_DIR}/cmake-build/${BUILD_DIR}" || exit $?
39+
40+
cd "${TEMP}" || exit $?
41+
}
42+

0 commit comments

Comments
 (0)