Skip to main content

Generate Fortran and Python wrappers for C and C++ Libraries

Project description

Shroud: generate Fortran and Python wrappers for C and C++ libraries.

Shroud is a tool for creating a Fortran or Python interface to a C or C++ library. It can also create a C API for a C++ library.

The user creates a YAML file with the C/C++ declarations to be wrapped along with some annotations to provide semantic information and code generation options. Shroud produces a wrapper for the library. The generated code is highly-readable and intended to be similar to code that would be hand-written to create the bindings.

verb

  1. wrap or dress (a body) in a shroud for burial.
  2. cover or envelop so as to conceal from view.

Build Status Documentation Status

Goals

  • Simplify the creating of wrapper for a C++ library.
  • Preserves the object-oriented style of C++ classes.
  • Create an idiomatic wrapper API from the C++ API.
  • Generate code which is easy to understand.
  • No dependent runtime library.

Example

The user creates a YAML file which includes declarations from zoo.hpp.

library: zoo
cxx_header: zoo.hpp

declarations:
- decl: class Animal
  declarations:
  - decl: Animal()
  - decl: void speak(const std::string &word)

This creates a Fortran interface which can be used as:

use zoo_mod
type(Animal) dog
dog = Animal()
dog%speak("woof")

And from Python

import zoo
dog = zoo.Animal()
dog.speak("woof")

Documentation

To get started using Shroud, check out the full documentation:

http://shroud.readthedocs.io/en/develop

Presentation at FortranCon2020

https://www.youtube.com/watch?v=1mdI-M94vDc Slides

For development processes see the HACKING file.

Mailing List

shroud-users@groups.io

https://groups.io/g/shroud-users

Required Packages

C++ to C to Fortran

The generated Fortran requires a Fortran 2003 compiler.

C++ or C to Python

The generated Python requires Python 2.7 or 3.7+.

Python features:

  • Uses NumPy for arrays. Also able to use Python lists if NumPy is overkill.
  • Uses extension type for classes.
  • Creates readable source.

Getting started

Shroud can be installed using pip

pip install llnl-shroud

This can be done in a virtual environment as

cd my_project_folder
virtualenv my_project
source my_project/bin/activate
pip install llnl-shroud

This assumes the bash shell. Source activate.csh for csh.

In addition, a file created by shiv is available from the github release. Shroud and PyYAML are bundled into a single executable which uses the Python3 on your path. Shiv requires Python 3.7+.

wget https://github.com/LLNL/shroud/archive/shroud-0.14.0.pyz

License

Copyright (c) 2017-2025, Lawrence Livermore National Security, LLC. Produced at the Lawrence Livermore National Laboratory.

SPDX-License-Identifier: (BSD-3-Clause)

See LICENSE for details

Unlimited Open Source - BSD 3-clause Distribution LLNL-CODE-738041 OCEC-17-143

SPDX usage

Individual files contain SPDX tags instead of the full license text. This enables machine processing of license information based on the SPDX License Identifiers that are available here: https://spdx.org/licenses/

Files that are licensed as BSD 3-Clause contain the following text in the license header:

SPDX-License-Identifier: (BSD-3-Clause)

External Packages

Shroud bundles some of its external dependencies in its repository. These packages are covered by various permissive licenses. A summary listing follows. See the license included with each package for full details.

PackageName: fruit
PackageHomePage: https://sourceforge.net/projects/fortranxunit/
PackageLicenseDeclared: BSD-3-Clause

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llnl_shroud-0.14.0.tar.gz (218.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llnl_shroud-0.14.0-py3-none-any.whl (227.8 kB view details)

Uploaded Python 3

File details

Details for the file llnl_shroud-0.14.0.tar.gz.

File metadata

  • Download URL: llnl_shroud-0.14.0.tar.gz
  • Upload date:
  • Size: 218.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for llnl_shroud-0.14.0.tar.gz
Algorithm Hash digest
SHA256 d4b952e7ead8373df9e9f9dabd3476e459601260c748168b83f034c1a29144d5
MD5 3c3687bbe85fcec20ee99a66f3e73c48
BLAKE2b-256 36c2df5e44805c1327747894333406c09f6428423153754c630aea996019f9d8

See more details on using hashes here.

File details

Details for the file llnl_shroud-0.14.0-py3-none-any.whl.

File metadata

  • Download URL: llnl_shroud-0.14.0-py3-none-any.whl
  • Upload date:
  • Size: 227.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for llnl_shroud-0.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c7b3c93672600e939b63db66e338c88e1bafe2034a919c8d940f954d2f79136
MD5 d027aa4696368d17e4b8cd5975d89c2f
BLAKE2b-256 ee69642a93c673303386edaf32da4191478680aed94a380073976098ad0ff43e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page