Skip to content

Commit

Permalink
Merge pull request #24 from Tolc-Software/release
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
srydell authored Feb 28, 2022
2 parents dd24f91 + 0dd221d commit b8e9bc6
Show file tree
Hide file tree
Showing 45 changed files with 1,310 additions and 261 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ jobs:
steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v2
with:
node-version: '16'

- name: Set up Python
uses: actions/setup-python@v2
with:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ jobs:
steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v2
with:
node-version: '16'

- name: Set up Python
uses: actions/setup-python@v2
with:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ jobs:
build:

runs-on: windows-2019
if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[ci skip]')"
env:
VCVARS: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat

steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v2
with:
node-version: '16'

- name: Set up Python
uses: actions/setup-python@v2
with:
Expand Down
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.17)

project(
tolc
VERSION 0.2.0
VERSION 0.3.0
LANGUAGES CXX)

configure_file(docs/ReleaseNotes/version.in
Expand Down Expand Up @@ -31,10 +31,15 @@ include(${modules}/Sanitizers.cmake)
include(${modules}/StaticAnalyzers.cmake)

include(${modules}/GetFrontend.cmake)
get_frontend(NAME Frontend.py VERSION v0.2.0)
get_frontend(NAME Frontend.py VERSION v0.3.0)
copy_frontend_docs(NAME Frontend.py SRC_DIR ${frontend.py_SOURCE_DIR} COPY_TO
${CMAKE_CURRENT_LIST_DIR}/docs/packaging/docs/python)

get_frontend(NAME Frontend.wasm VERSION v0.4.1)
copy_frontend_docs(
NAME Frontend.wasm SRC_DIR ${frontend.wasm_SOURCE_DIR} COPY_TO
${CMAKE_CURRENT_LIST_DIR}/docs/packaging/docs/webassembly)

include(${modules}/GetParser.cmake)
get_parser(VERSION v0.2.0)

Expand Down Expand Up @@ -105,8 +110,9 @@ add_library(
target_include_directories(TolcInternal PUBLIC src)
target_include_directories(TolcInternal SYSTEM
PRIVATE ${cli11_content_SOURCE_DIR}/include)
target_link_libraries(TolcInternal PUBLIC Tolc::Parser Tolc::Frontend.py
spdlog::spdlog fmt::fmt)
target_link_libraries(
TolcInternal PUBLIC Tolc::Parser Tolc::Frontend.py Tolc::Frontend.wasm
spdlog::spdlog fmt::fmt)
set_target_properties(TolcInternal PROPERTIES CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@
`Tolc` provides easy to use abstractions to create a bindings library directly from `CMake`:

```cmake
tolc_create_translation(
tolc_create_bindings(
TARGET MyLib
LANGUAGE python
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/python-bindings
)
```

This will extract the public API from the target `MyLib`, give it to `Tolc` to create bindings, and expose it to `CMake` as the target `MyLib_python`. To see all options available for `tolc_create_translation`, please see the [the documentation](https://docs.tolc.io/cmake/reference/).
This will extract the public API from the target `MyLib`, give it to `Tolc` to create bindings, and expose it to `CMake` as the target `MyLib_python`. To see all options available for `tolc_create_bindings`, please see the [the documentation](https://docs.tolc.io/cmake/reference/).

In this example you will find the built `CPython` library under `<build_directory>/tolc`, so you can use it straight away with:

Expand Down
48 changes: 48 additions & 0 deletions cmake/GetEmscripten.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
include_guard()

function(get_emscripten)
# Define the supported set of keywords
set(prefix ARG)
set(noValues)
set(singleValues VERSION)
set(multiValues)
# Process the arguments passed in can be used e.g. via ARG_NAME
cmake_parse_arguments(${prefix} "${noValues}" "${singleValues}"
"${multiValues}" ${ARGN})

if(NOT ARG_VERSION)
message(
FATAL_ERROR "Must provide a version. e.g. getEmscripten(VERSION 3.1.3)")
endif()

# Download the SDK
set(emsdk_version ${ARG_VERSION})
include(FetchContent)
FetchContent_Declare(
emsdk_entry
URL https://github.com/emscripten-core/emsdk/archive/refs/tags/${emsdk_version}.tar.gz
)

FetchContent_GetProperties(emsdk_entry)
if(NOT emscripten_entry_POPULATED)
FetchContent_Populate(emsdk_entry)
endif()

set(sdkCommand ./emsdk)
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows)
set(sdkCommand emsdk.bat)
endif()

# Installs the Emscripten compiler
execute_process(COMMAND ${sdkCommand} install ${emsdk_version}
WORKING_DIRECTORY ${emsdk_entry_SOURCE_DIR})

# Writes the .emscripten file
execute_process(COMMAND ${sdkCommand} activate ${emsdk_version}
WORKING_DIRECTORY ${emsdk_entry_SOURCE_DIR})

# Export the variables
set(emsdk_SOURCE_DIR
${emsdk_entry_SOURCE_DIR}
PARENT_SCOPE)
endfunction()
1 change: 0 additions & 1 deletion cmake/packaging/scripts/gather_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def parseArguments():

def main():
args = parseArguments()
print(args)

# Make sure the directory of the output exists
Path(args.combined_header).parent.mkdir(parents=True, exist_ok=True)
Expand Down
49 changes: 0 additions & 49 deletions cmake/packaging/tolc/tolcAddTarget.cmake

This file was deleted.

5 changes: 2 additions & 3 deletions cmake/packaging/tolc/tolcConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ find_tolc()
message(STATUS "Using tolc executable: ${tolc_EXECUTABLE}")

### Config variables: These determine the behaviour of tolc ###
set(tolc_pybind11_version 2.8.1)
set(tolc_pybind11_version 2.9.1)
# Comma separated list of supported languages
set(tolc_supported_languages "python")
set(tolc_supported_languages "python, wasm")

include(${CMAKE_CURRENT_LIST_DIR}/tolcTranslate.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/GetPybind11.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/tolcAddTarget.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/tolcCreateTranslation.cmake)
49 changes: 35 additions & 14 deletions cmake/packaging/tolc/tolcCreateTranslation.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include_guard()

function(tolc_create_translation)
function(tolc_create_bindings)
# Define the supported set of keywords
set(prefix ARG)
set(noValues DO_NOT_SEARCH_TARGET_INCLUDES NO_ANALYTICS)
Expand All @@ -13,7 +13,7 @@ function(tolc_create_translation)

# Variables related to error messages:
# Cannot assume too new CMake version
set(function_name tolc_create_translation)
set(function_name tolc_create_bindings)
set(usage "Usage: ${function_name}(TARGET myLibrary LANGUAGE python)")

# Helper function
Expand Down Expand Up @@ -48,11 +48,9 @@ function(tolc_create_translation)
endif()

# What the actual target name will be
set(tolcTargetName ${ARG_TARGET}_${ARG_LANGUAGE})
set(tolc_target_name ${ARG_TARGET}_${ARG_LANGUAGE})
message(
STATUS
"Creating translation to language ${ARG_LANGUAGE} in target ${tolcTargetName}"
)
STATUS "Creating bindings to ${ARG_LANGUAGE} in target ${tolc_target_name}")

# Use the input target to create the translation
tolc_translate_target(
Expand All @@ -65,22 +63,45 @@ function(tolc_create_translation)
${ARG_LANGUAGE}
OUTPUT
${ARG_OUTPUT})
# Add a new target, representing the translation
# TODO: This should be changed when tolc can handle outputs explicitly (not just a directory, but a file)
tolc_add_library(TARGET ${tolcTargetName} LANGUAGE ${ARG_LANGUAGE} INPUT
${ARG_OUTPUT}/${ARG_TARGET}.cpp)

if(${ARG_LANGUAGE} MATCHES "python")
# NOTE: Variable injected from tolcConfig file
get_pybind11(VERSION ${tolc_pybind11_version})
# Create the python module
pybind11_add_module(${tolc_target_name} ${ARG_OUTPUT}/${ARG_TARGET}.cpp
SYSTEM)
elseif(${ARG_LANGUAGE} MATCHES "wasm")
# Assumes that the Emscripten toolchain file is used
# Will result in a .js and a .wasm file
add_executable(${tolc_target_name} ${ARG_OUTPUT}/${ARG_TARGET}.cpp)

# Export Promise as 'loadMyLib' for module 'MyLib'
# -s MODULARIZE=1 sets it as a promise based load
# Note that this is necessary for preJS to work properly
set_target_properties(
${tolc_target_name}
PROPERTIES
LINK_FLAGS
"-s MODULARIZE=1 -s EXPORT_NAME=\"load${ARG_TARGET}\" --pre-js ${ARG_OUTPUT}/pre.js -lembind"
)
else()
error_with_usage(
"Unknown language input: ${ARG_LANGUAGE}. Valid input: [${tolc_supported_languages}]"
)
endif()

# The added library target depends on the target being translated
add_dependencies(${tolcTargetName} tolc_translate_file_${ARG_TARGET})
add_dependencies(${tolc_target_name} tolc_translate_file_${ARG_TARGET})

# NOTE: The user may need to provide additional links if they have their PUBLIC/PRIVATE dependencies missmatched
target_link_libraries(${tolcTargetName} PRIVATE ${ARG_TARGET})
target_link_libraries(${tolc_target_name} PRIVATE ${ARG_TARGET})

set_target_properties(
${tolcTargetName}
${tolc_target_name}
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tolc"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tolc"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tolc")
# This allows the target to be called target_language, but still be imported e.g. in python as 'import target'
set_target_properties(${tolcTargetName} PROPERTIES OUTPUT_NAME ${ARG_TARGET})
set_target_properties(${tolc_target_name} PROPERTIES OUTPUT_NAME
${ARG_TARGET})
endfunction()
16 changes: 2 additions & 14 deletions cmake/packaging/tolc/tolcTranslate.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function(tolc_translate_file)
set(prefix ARG)
set(noValues NO_ANALYTICS)
set(singleValues INPUT LANGUAGE MODULE_NAME OUTPUT)
set(multiValues INCLUDES)
set(multiValues)
# Process the arguments passed in
# can be used e.g. via ARG_TARGET
cmake_parse_arguments(${prefix} "${noValues}" "${singleValues}"
Expand All @@ -14,7 +14,7 @@ function(tolc_translate_file)
# Cannot assume too new CMake version
set(function_name tolc_translate_file)
set(usage
"Usage: ${function_name}(MODULE_NAME myLibrary LANGUAGE python INPUT include/myLibrary.hpp OUTPUT out [INCLUDES include])"
"Usage: ${function_name}(MODULE_NAME myLibrary LANGUAGE python INPUT include/myLibrary.hpp OUTPUT out)"
)

# Helper function
Expand Down Expand Up @@ -51,16 +51,6 @@ function(tolc_translate_file)
set(noAnalytics "--no-analytics")
endif()

# Turn the include directories to valid input flags
if(ARG_INCLUDES)
set(includes "")
foreach(include ${ARG_INCLUDES})
list(APPEND includes -I ${include})
endforeach()
else()
set(includes "")
endif()

set(command
${tolc_EXECUTABLE}
${ARG_LANGUAGE}
Expand All @@ -70,10 +60,8 @@ function(tolc_translate_file)
${ARG_INPUT}
--output
${ARG_OUTPUT}
${includes}
${noAnalytics})

# TODO: This should be changed when tolc can handle outputs explicitly (not just a directory, but a file)
add_custom_target(
tolc_translate_file_${ARG_MODULE_NAME} ALL
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
Expand Down
10 changes: 10 additions & 0 deletions docs/ReleaseNotes/v0.3.0.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# News #

## Features ##

* Now supports generating bindings to WebAssembly via [`frontend.wasm`](https://github.com/Tolc-Software/frontend.wasm)
* Checkout the [documentation](https://docs.tolc.io) for more info.


## Breaking ##

* Renamed `CMake` function `tolc_create_translation` to `tolc_create_bindings`.
12 changes: 12 additions & 0 deletions docs/packaging/docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,15 @@ int const Example::i;

For more information you can read about [static member declaration/instantiation on cppreference](https://en.cppreference.com/w/cpp/language/static), or [a discussion on this topic in the pybind repository](https://github.com/pybind/pybind11/issues/682).

## I get a link error while building `WebAssembly` on Windows with `Visual Studio` ##

At the time of writing there is only experimental support for the `Visual Studio` generator for `Emscripten`. If you see error such as:

```shell
LINK : warning LNK4044: unrecognized option '/-default-obj-ext'; ignored [MyProject.vcxproj]
LINK : fatal error LNK1104: cannot open file '.obj' [MyProject.vcxproj]
cl : command line warning D9002: ignoring unknown option '-g' [MyProject_wasm.vcxproj] myLib.cpp
```shell
Then consider using the `Ninja` generator. It is the default on Windows with `Visual Studio`.
Loading

0 comments on commit b8e9bc6

Please sign in to comment.