From 0c71feb0363b337152f11e301303f85f9621c148 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 20 Jul 2017 08:55:31 +0200 Subject: Add modularized version --- libmformat/.gitignore | 19 +++++++++++++++++++ libmformat/build/.gitignore | 1 + libmformat/build/bootstrap.build | 7 +++++++ libmformat/build/export.build | 6 ++++++ libmformat/build/root.build | 10 ++++++++++ libmformat/buildfile | 8 ++++++++ libmformat/libmformat/buildfile | 15 +++++++++++++++ libmformat/libmformat/format.cxx | 31 +++++++++++++++++++++++++++++++ libmformat/libmformat/format.mxx | 13 +++++++++++++ libmformat/manifest | 21 +++++++++++++++++++++ libmformat/tests/.gitignore | 1 + libmformat/tests/build/.gitignore | 1 + libmformat/tests/build/bootstrap.build | 5 +++++ libmformat/tests/build/root.build | 13 +++++++++++++ libmformat/tests/buildfile | 1 + libmformat/tests/test/buildfile | 5 +++++ libmformat/tests/test/driver.cxx | 16 ++++++++++++++++ libmformat/tests/test/test.out | 3 +++ 18 files changed, 176 insertions(+) create mode 100644 libmformat/.gitignore create mode 100644 libmformat/build/.gitignore create mode 100644 libmformat/build/bootstrap.build create mode 100644 libmformat/build/export.build create mode 100644 libmformat/build/root.build create mode 100644 libmformat/buildfile create mode 100644 libmformat/libmformat/buildfile create mode 100644 libmformat/libmformat/format.cxx create mode 100644 libmformat/libmformat/format.mxx create mode 100644 libmformat/manifest create mode 100644 libmformat/tests/.gitignore create mode 100644 libmformat/tests/build/.gitignore create mode 100644 libmformat/tests/build/bootstrap.build create mode 100644 libmformat/tests/build/root.build create mode 100644 libmformat/tests/buildfile create mode 100644 libmformat/tests/test/buildfile create mode 100644 libmformat/tests/test/driver.cxx create mode 100644 libmformat/tests/test/test.out diff --git a/libmformat/.gitignore b/libmformat/.gitignore new file mode 100644 index 0000000..1173da4 --- /dev/null +++ b/libmformat/.gitignore @@ -0,0 +1,19 @@ +# Compiler/linker output. +# +*.d +*.ii +*.o +*.obj +*.nms +*.pcm +*.ifc +*.so +*.dll +*.a +*.lib +*.exp +*.exe +*.exe.dlls/ +*.exe.manifest + +version diff --git a/libmformat/build/.gitignore b/libmformat/build/.gitignore new file mode 100644 index 0000000..225c27f --- /dev/null +++ b/libmformat/build/.gitignore @@ -0,0 +1 @@ +config.build diff --git a/libmformat/build/bootstrap.build b/libmformat/build/bootstrap.build new file mode 100644 index 0000000..9bf0463 --- /dev/null +++ b/libmformat/build/bootstrap.build @@ -0,0 +1,7 @@ +project = libmformat + +using version +using config +using dist +using test +using install diff --git a/libmformat/build/export.build b/libmformat/build/export.build new file mode 100644 index 0000000..3416bd3 --- /dev/null +++ b/libmformat/build/export.build @@ -0,0 +1,6 @@ +$out_root/: +{ + include libmformat/ +} + +export $out_root/libmformat/lib{mformat} diff --git a/libmformat/build/root.build b/libmformat/build/root.build new file mode 100644 index 0000000..0f4a099 --- /dev/null +++ b/libmformat/build/root.build @@ -0,0 +1,10 @@ +cxx.std = experimental + +cxx.features.symexport = true + +using cxx + +assert $cxx.features.modules 'c++ compiler does not support modules' + +mxx{*}: extension = mxx +cxx{*}: extension = cxx diff --git a/libmformat/buildfile b/libmformat/buildfile new file mode 100644 index 0000000..83b174d --- /dev/null +++ b/libmformat/buildfile @@ -0,0 +1,8 @@ +./: libmformat/ tests/ doc{version} file{manifest} + +doc{version}: file{manifest} # Generated by the version module. +doc{version}: dist = true + +# Don't install tests. +# +dir{tests/}: install = false diff --git a/libmformat/libmformat/buildfile b/libmformat/libmformat/buildfile new file mode 100644 index 0000000..24acee5 --- /dev/null +++ b/libmformat/libmformat/buildfile @@ -0,0 +1,15 @@ +import libs = libstd-modules%liba{std-modules} + +lib{mformat}: {mxx cxx}{format} $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{mformat}: bin.lib.version = @"-$version.project_id" +else + lib{mformat}: bin.lib.version = @"-$version.major.$version.minor" + +# Install into the libmformat/ subdirectory of, say, /usr/include/. +# +install.include = $install.include/$project/ diff --git a/libmformat/libmformat/format.cxx b/libmformat/libmformat/format.cxx new file mode 100644 index 0000000..fe6ad15 --- /dev/null +++ b/libmformat/libmformat/format.cxx @@ -0,0 +1,31 @@ +// file: libmformat/format.cxx -*- C++ -*- + +module format; + +import std.core; // transform() +import std.io; // to{upper,lower}() + +using namespace std; + +namespace format +{ + string + message (const string& g, const string& n, volume v) + { + string r (g); + + auto tr = [&r] (char (*t) (char)) + { + transform (r.begin (), r.end (), r.begin (), t); + }; + + switch (v) + { + case volume::quiet: tr ([](char c) -> char {return tolower (c);}); break; + case volume::normal: break; + case volume::loud: tr ([](char c) -> char {return toupper (c);}); break; + } + + return r += ", " + n + '!'; + } +} diff --git a/libmformat/libmformat/format.mxx b/libmformat/libmformat/format.mxx new file mode 100644 index 0000000..c1e69ee --- /dev/null +++ b/libmformat/libmformat/format.mxx @@ -0,0 +1,13 @@ +// file: libmformat/format.mxx -*- C++ -*- + +export module format; + +import std.core; + +export namespace format +{ + enum class volume {quiet, normal, loud}; + + __symexport std::string + message (const std::string& greeting, const std::string& name, volume); +} diff --git a/libmformat/manifest b/libmformat/manifest new file mode 100644 index 0000000..97ee836 --- /dev/null +++ b/libmformat/manifest @@ -0,0 +1,21 @@ +: 1 +name: libmformat +version: 1.0.0 +summary: The modularized "Hello World" example formatter library +license: MIT +tags: c++, hello, world, formatter, example, modules +description: \ +A simple library that implements the "Hello World" formatting in C++ with +modules. +\ +url: http://www.example.org/libmformat +email: hello-users@example.org +build-email: builds@build2.org +build-exclude: *-msvc_15u0* ; Broken C++ modules support +build-include: *-msvc_15* +build-include: *-clang_5.0* +build-exclude: * ; Requires C++ modules support +requires: c++20 +depends: * build2 >= 0.6.0- +depends: * bpkg >= 0.6.0- +depends: libstd-modules diff --git a/libmformat/tests/.gitignore b/libmformat/tests/.gitignore new file mode 100644 index 0000000..e54525b --- /dev/null +++ b/libmformat/tests/.gitignore @@ -0,0 +1 @@ +driver diff --git a/libmformat/tests/build/.gitignore b/libmformat/tests/build/.gitignore new file mode 100644 index 0000000..225c27f --- /dev/null +++ b/libmformat/tests/build/.gitignore @@ -0,0 +1 @@ +config.build diff --git a/libmformat/tests/build/bootstrap.build b/libmformat/tests/build/bootstrap.build new file mode 100644 index 0000000..2c2de24 --- /dev/null +++ b/libmformat/tests/build/bootstrap.build @@ -0,0 +1,5 @@ +project = # Unnamed subproject. + +using config +using dist +using test diff --git a/libmformat/tests/build/root.build b/libmformat/tests/build/root.build new file mode 100644 index 0000000..58dffed --- /dev/null +++ b/libmformat/tests/build/root.build @@ -0,0 +1,13 @@ +cxx.std = experimental + +using cxx + +cxx{*}: extension = cxx + +# Every exe{} in this subproject is by default a test. +# +exe{*}: test = true + +# Specify the test target for cross-testing. +# +test.target = $cxx.target diff --git a/libmformat/tests/buildfile b/libmformat/tests/buildfile new file mode 100644 index 0000000..1a8bcc9 --- /dev/null +++ b/libmformat/tests/buildfile @@ -0,0 +1 @@ +./: test/ diff --git a/libmformat/tests/test/buildfile b/libmformat/tests/test/buildfile new file mode 100644 index 0000000..19d311d --- /dev/null +++ b/libmformat/tests/test/buildfile @@ -0,0 +1,5 @@ +import libs = libmformat%lib{mformat} +import libs += libstd-modules%liba{std-modules} + +exe{driver}: cxx{driver} $libs +exe{driver}: test.output = test.out diff --git a/libmformat/tests/test/driver.cxx b/libmformat/tests/test/driver.cxx new file mode 100644 index 0000000..9cc8748 --- /dev/null +++ b/libmformat/tests/test/driver.cxx @@ -0,0 +1,16 @@ +// file: tests/test/driver.cxx -*- C++ -*- + +import std.core; +import std.io; +import format; + +int +main () +{ + using namespace std; + using namespace format; + + cout << message ("Hello", "World", volume::quiet) << endl; + cout << message ("Hello", "World", volume::normal) << endl; + cout << message ("Hello", "World", volume::loud) << endl; +} diff --git a/libmformat/tests/test/test.out b/libmformat/tests/test/test.out new file mode 100644 index 0000000..7ce133b --- /dev/null +++ b/libmformat/tests/test/test.out @@ -0,0 +1,3 @@ +hello, World! +Hello, World! +HELLO, World! -- cgit v1.1