Skip to content

Syniurge/Calypso

 
 

Repository files navigation

Calypso notes

Calypso creates a bridge between DMD/LDC and Clang, both at the AST level (DMD <=> Clang's AST, Sema, ...) and at the code generation level (LDC <=> Clang's Codegen) to make D interface directly with the almost entire spectrum of C++ features.

It's not a separate tool, but a fork of LDC which enables you to directly import/include a C/C++ header and use the declarations from within D. No intermediate file is necessary, and no binding is involved.

Calypso introduces a new pragma, cppmap, and new « import (C++) xxx.yyy; » imports. Interfacing with C++ declarations comes down to:

pragma (cppmap, "cppheader.h");  // tells Clang to parse cppheader.h but do not import anything

import (C++) NamespaceA.Class1;  // imports NamespaceA::Class1
import (C++) NamespaceA;         // imports the full namespace
import (C++) *;                  // imports the entire translation unit

The resulting imported symbols are usable like their D counterparts. For more detailed examples see tests/calypso and examples.

Although Calypso is currently soldered to LDC, separating the two and placing Calypso and its bulky Clang dependency in an optional shared library should be easy. In this way, D compilers won't have to depend on a C/C++ compiler, and wider C++ support than what D currently has won't result in too cumbersome intrusions in core DMD/LDC.

Installation notes

Refer to the LDC wiki (Linux and OS X and Windows).

There are only a few requirements specific to Calypso:

  • CMake minimum version is 3.4+
  • Clang is tied to its corresponding LLVM version, it's therefore strongly recommended to build Calypso which introduces a Clang 9.0 submodule against LLVM 9.0
  • MSVC (Windows) builds require Ninja

cmake -G Ninja is recommended instead of make to take advantage by default of all available CPU cores while building the Clang external module (it's also possible to set cmake -DCLANG_BUILD_FLAGS="-jX").

Calypso may also have nightly builds in the future.

Passing arguments to Clang

The -cpp-flags option was added to LDC to pass arguments to Clang during header parsing, e.g to enable C++14:

$ ldc2 -cpp-args -std=c++14 main.d

Missing features

Exception handling

  • C++ exception rethrowing
  • catch (C++) {} i.e catch any C++ exception instead of specifying a type with catch (C++) (ref T e) (#74)
  • MSVC exception handling

Other

  • Register the destructor of C++ classes and structs while allocating a C++ class through the GC (as is being done for D structs)
  • Map macro functions as enums and templates (#66). Currently only macro constants get mapped.

LDC – the LLVM-based D Compiler

Latest stable release Build status Build status Build status Build status Build status Bountysource

The LDC project provides a portable D programming language compiler with modern optimization and code generation capabilities.

The compiler uses the official DMD frontend to support the latest version of D2, and relies on the LLVM Core libraries for code generation.

LDC is fully Open Source; the parts of the source code not taken/adapted from other projects are BSD-licensed (see the LICENSE file for details).

Please consult the D wiki for further information: https://wiki.dlang.org/LDC

D1 is no longer available; see the d1 Git branch for the last version supporting it.

Installation

From a pre-built package

Portable stand-alone binary builds for common platforms (incl. Linux, macOS and Windows) are available at the GitHub release page.

For bleeding-edge users, we also provide the latest successful Continuous Integration builds with enabled LLVM & LDC assertions (increasing compile times by roughly 50%).

The dlang.org install script can also be used to install LDC:

curl -fsS https://dlang.org/install.sh | bash -s ldc

In addition, LDC is available from various package managers (but note that these packages might be outdated as they are not currently integrated into the project release process):

Command
Android in Termux app: pkg install ldc
Arch Linux pacman -S ldc
Debian apt install ldc
Fedora dnf install ldc
Gentoo layman -a ldc
Homebrew brew install ldc
Ubuntu apt install ldc
Snap snap install --classic --channel=edge ldc2
Nix/NixOS nix-env -i ldc
Chocolatey choco install ldc
Docker docker pull dlang2/ldc-ubuntu

Targeting Android

You can find full instructions on cross-compiling or natively compiling for Android on the wiki.

Building from source

In-depth material on building and installing LDC and the standard libraries is available on the project wiki for Linux, macOS, BSD, and Android and Windows.

If you have a working C++/D build environment, CMake, and a current LLVM version (≥ 3.9) available, there should be no big surprises. Do not forget to make sure all the submodules (druntime, phobos, dmd-testsuite) are up to date:

$ cd ldc
$ git submodule update --init

(DMD and LDC are supported as host compilers. For bootstrapping purposes, LDC 0.17, the last version not to require a D compiler, is maintained in the ltsmaster branch).

Cross-compiling

We've recently added a cross-compilation tool to make it easier to build the D runtime and standard library for other platforms, ldc-build-runtime. Full instructions and example invocations are provided on its wiki page.

Contact

The best way to get in touch with the developers is either via the digitalmars.D.ldc forum/newsgroup/mailing list or our Gitter chat. There is also the #ldc IRC channel on FreeNode.

For further documentation, contributor information, etc. please see the D wiki.

Feedback of any kind is very much appreciated!

About

LDC fork to experiment direct interfacing with C++

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • D 62.6%
  • C++ 35.3%
  • CMake 1.6%
  • Shell 0.3%
  • C 0.1%
  • Makefile 0.1%