From b86d23391e4b7882ebfca582d146e75c6cc1e454 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 20 Jul 2017 08:55:35 +0200 Subject: Add modularized version --- libmhello/libmhello/buildfile | 19 ++++++++++++++++ libmhello/libmhello/hello.cxx | 20 +++++++++++++++++ libmhello/libmhello/hello.mxx | 52 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 libmhello/libmhello/buildfile create mode 100644 libmhello/libmhello/hello.cxx create mode 100644 libmhello/libmhello/hello.mxx (limited to 'libmhello/libmhello') diff --git a/libmhello/libmhello/buildfile b/libmhello/libmhello/buildfile new file mode 100644 index 0000000..5b46722 --- /dev/null +++ b/libmhello/libmhello/buildfile @@ -0,0 +1,19 @@ +import int_libs = libmformat%lib{mformat} +import imp_libs = libmprint%lib{mprint} +import imp_libs += libstd-modules%liba{std-modules} + +lib{mhello}: {mxx cxx}{hello} $imp_libs $int_libs + +# For pre-releases use the complete version to make sure they cannot be used +# in place of another pre-release or the final version. +# +if $version.pre_release + lib{mhello}: bin.lib.version = @"-$version.project_id" +else + lib{mhello}: bin.lib.version = @"-$version.major.$version.minor" + +lib{mhello}: cxx.export.libs = $int_libs + +# Install into the libmhello/ subdirectory of, say, /usr/include/. +# +install.include = $install.include/$project/ diff --git a/libmhello/libmhello/hello.cxx b/libmhello/libmhello/hello.cxx new file mode 100644 index 0000000..c94f921 --- /dev/null +++ b/libmhello/libmhello/hello.cxx @@ -0,0 +1,20 @@ +// file: libmhello/hello.cxx -*- C++ -*- + +module hello; + +#ifdef __clang__ +import std.core; +#endif + +import print; + +using namespace std; + +namespace hello +{ + void + say_formatted (const string& m) + { + print::to_stdout (m); + } +} diff --git a/libmhello/libmhello/hello.mxx b/libmhello/libmhello/hello.mxx new file mode 100644 index 0000000..c9ed8e1 --- /dev/null +++ b/libmhello/libmhello/hello.mxx @@ -0,0 +1,52 @@ +// file: libmhello/hello.mxx -*- C++ -*- + +export module hello; + +import std.core; + +#ifndef __clang__ +export +#endif +import format; + +export namespace hello +{ + // If you compare this interface to version 1.0, then you will notice that + // while it is API/source-compatible (the call via the old signature of + // say() is still valid) it is not ABI/binary-compatible (say() now has an + // extra argument and is inline). + // + // Notice also that inline say() now uses a type and calls a function from + // format which means libmformat is an "interface dependency" of libmhello. + // + // Note that for the default argument (and thus source-compatibility) to + // work as expected we have to re-export the format module. Failed that, + // users of our API that don't care about the volume will still have to + // explicitly import format which would be a strange requirement indeed. + + __symexport void + say_formatted (const std::string& message); + +#ifndef _MSC_VER + inline void + say (const std::string& name, format::volume v = format::volume::normal) + { + say_formatted (format::message ("Hello", name, v)); + } +#else + // - modulewriter.cpp:4730: sorry: not yet implemented + // - also, now need to symexport inline functions for some reason + + __symexport inline void + say (const std::string& name) + { + say_formatted (format::message ("Hello", name, format::volume::normal)); + } + + __symexport inline void + say (const std::string& name, format::volume v) + { + say_formatted (format::message ("Hello", name, v)); + } +#endif +} -- cgit v1.1