Skip to content

Commit

Permalink
Adds simple example
Browse files Browse the repository at this point in the history
Signed-off-by: Yauheni Khnykin <[email protected]>
  • Loading branch information
Hsilgos committed Nov 5, 2023
1 parent 9447c95 commit b6afd33
Show file tree
Hide file tree
Showing 47 changed files with 1,979 additions and 55 deletions.
27 changes: 19 additions & 8 deletions .github/workflows/functional-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install JDK
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Cache Gradle packages
uses: actions/cache@v2
with:
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Install JDK
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Cache Gradle packages
uses: actions/cache@v2
with:
Expand Down Expand Up @@ -115,6 +115,12 @@ jobs:
export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools
./scripts/build-android-namerules --publish
working-directory: functional-tests
- name: Build examples
run: |
export ANDROID_HOME=${HOME}/android-sdk-linux
pushd examples/calculator/android
./gradlew build
popd
swift:
name: Swift on Linux
Expand All @@ -125,7 +131,7 @@ jobs:
- name: Install JDK
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Cache Gradle packages
uses: actions/cache@v2
with:
Expand Down Expand Up @@ -188,14 +194,14 @@ jobs:

swift-mac:
name: Swift on MacOS
runs-on: macos-11
runs-on: macos-12

steps:
- uses: actions/checkout@v2
- name: Install JDK
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Cache Gradle packages
uses: actions/cache@v2
with:
Expand All @@ -221,6 +227,11 @@ jobs:
run: |
./scripts/build-swift-namerules --publish
working-directory: functional-tests
- name: Build examples
run: |
mkdir build_example_calculator
cmake -B build_example_calculator examples/calculator -GXcode -DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_SYSTEM_NAME=iOS
cmake --build build_example_calculator
dart:
name: Dart
Expand All @@ -231,7 +242,7 @@ jobs:
- name: Install JDK
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Cache Gradle packages
uses: actions/cache@v2
with:
Expand Down Expand Up @@ -270,7 +281,7 @@ jobs:
- name: Install JDK
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Cache Gradle packages
uses: actions/cache@v2
with:
Expand Down Expand Up @@ -334,7 +345,7 @@ jobs:
- name: Install JDK
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Cache Gradle packages
uses: actions/cache@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Install JDK
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Cache Gradle packages
uses: actions/cache@v2
with:
Expand Down
3 changes: 3 additions & 0 deletions .idea/kotlinc.xml

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

49 changes: 3 additions & 46 deletions docs/lime_idl.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,54 +25,11 @@ LimeIDL syntax

### Example

This example only shows how syntax looks like, it's not ready to use out of the box.
For working examples check lime files in [functional tests](https://github.com/heremaps/gluecodium/tree/master/functional-tests/functional/input/lime).
Also [cmake tests](https://github.com/heremaps/gluecodium/tree/master/cmake/tests/unit) demonstrate how
to integrate Gluecodium to CMake-based project and how to use it for more complex scenarios when you need
multiple modules which interact with each other.
Start with [examples](../examples/README.md).

```
package com.example
import com.example.utils.GenericResult
class SomeImportantProcessor {
constructor create(options: Options?) throws SomethingWrongException
fun process(mode: Mode, input: String): GenericResult
property processingTime: ProcessorHelperTypes.Timestamp { get }
@Internal
static property secretDelegate: ProcessorDelegate?
enum Mode {
SLOW,
FAST,
CHEAP
}
@Immutable
struct Options {
flagOption: Boolean
uintOption: UShort
additionalOptions: List<String> = {}
}
For more advanced lime examples check [functional tests](https://github.com/heremaps/gluecodium/tree/master/functional-tests/functional/input/lime).

exception SomethingWrongException(String)
}
interface ProcessorDelegate: com.example.utils.GenericDelegate {
fun onProcessorEvent(message: String)
}
struct ProcessorHelperTypes {
typealias Timestamp = Date
const DefaultOptions: SomeImportantProcessor.Options = {flagOption = true, uintOption = 42, {}}
}
```
Also [cmake tests](https://github.com/heremaps/gluecodium/tree/master/cmake/tests/unit) demonstrate how to use CMake scripts for more complex scenarios when you need multiple modules which interact with each other.

### General remarks on syntax

Expand Down
31 changes: 31 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Overview

[README.md](../README.md) in the root provides basic information about Gluecodium.
It's simplier to keep C++ code in shared library when binding is necessary for Java and for Swift.
In examples simpliest configuration is used. For more advanced check `cmake/tests/unit` tests.

## CMake Gluecodium wraper.

This is set of cmake functions which provide the following functionality:
- Download Gluecodium from artifactory.
- Add step to generate code.
- Set options to configure generated code.
- Help to configure a target to include generated C++/Swift/Java/Flutter sources, add include directories, etc.

While examples work with shipped CMake Gluecodium wraper in real application it's handy to clone only subtree `cmake/modules`.

## Example `calculator`.

What this example demonstrates:
- How to configure the project to generate C++, Java and Swift source code.
- How to use the generated code in Android and iOS applications.
- How to describe basic primitives like `class`, `interface`, `struct` and how to interact with them
- How to make platform-only comment and links.

What this example DOESN'T demonstrate:
- How to make complex build setup with several modules.
- How to describe custom types.
- How to make Flutter plugin.
- How to use advanced Gluecodium features: tags, advanced manupulations with comments, properties, etc.

For detailed desription check [calculator/README.md](calculator/README.md)
77 changes: 77 additions & 0 deletions examples/calculator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright (C) 2016-2023 HERE Europe B.V.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# License-Filename: LICENSE

cmake_minimum_required(VERSION 3.12)

project(gluecodium.calculator)

option(ENABLE_APP "Enables iOS app which demostrates how to use the generated code" ON)

set(CMAKE_CXX_STANDARD 17)

if(CMAKE_GENERATOR STREQUAL "Xcode")
enable_language(Swift)
endif()

# Path to Gluecodium CMake wrapper
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../../cmake/modules")

include(gluecodium/Gluecodium)

# Android requires C++ code to be built as shared library.
# For iOS it's recommended (but not required) to do Framework because it's consistent
# to Android setup and simplifies CMake scripts and it allows to use framework with
# Xcode projects which are not originated from CMake (for example cocoapods or
# generated by Xcode itself).
add_library(mylibrary SHARED "${CMAKE_CURRENT_LIST_DIR}/cpp/CalculatorImpl.cpp")

# C++ (cpp) generator usually always necessary, android and swift depend on current platform.
set (_generators cpp)
if (ANDROID)
list (APPEND _generators android)
elseif (CMAKE_GENERATOR STREQUAL "Xcode")
list (APPEND _generators swift)
endif()

# Add step to generate sources. Lime files are specified below.
gluecodium_generate(mylibrary GENERATORS ${_generators})

# Gluecodium has plenty options which can be configured with target properties
# prfixed with `GLUECODIUM_`. To learn all the properties configure the project
# with `-DGLUECODIUM_PRINT_KNOWN_PROPERTIES=ON` parameter.
set_target_properties(mylibrary PROPERTIES
# Not required, but highly desired Java annotations.
GLUECODIUM_JAVA_NONNULL_ANNOTATION "androidx.annotation.NonNull"
GLUECODIUM_JAVA_NULLABLE_ANNOTATION "androidx.annotation.Nullable"

# Set prefix for java package.
GLUECODIUM_JAVA_PACKAGE "com")

# This is the most convenient way to add lime files from which Gluecodium generates code.
set_property(TARGET mylibrary APPEND PROPERTY GLUECODIUM_LIME_SOURCES
"${CMAKE_CURRENT_LIST_DIR}/lime/Calculator.lime")

if (CMAKE_GENERATOR STREQUAL "Xcode")
# Make CMake to build framework.
set_target_properties(mylibrary PROPERTIES
FRAMEWORK TRUE
XCODE_ATTRIBUTE_DEFINES_MODULE YES)

if(ENABLE_APP AND IOS)
add_subdirectory("ios")
endif()
endif()
Loading

0 comments on commit b6afd33

Please sign in to comment.