diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-07-20 08:55:35 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2017-07-20 08:55:35 +0200 |
commit | b86d23391e4b7882ebfca582d146e75c6cc1e454 (patch) | |
tree | 8d002d34199dd24fa5a3898e6943dca62e906d10 /libmhello | |
parent | bffe85ae4c01f126c47ab7ea7b220b91d7c65dac (diff) |
Add modularized version
Diffstat (limited to 'libmhello')
-rw-r--r-- | libmhello/.gitignore | 19 | ||||
-rw-r--r-- | libmhello/INSTALL | 1 | ||||
-rw-r--r-- | libmhello/build/.gitignore | 1 | ||||
-rw-r--r-- | libmhello/build/bootstrap.build | 7 | ||||
-rw-r--r-- | libmhello/build/export.build | 6 | ||||
-rw-r--r-- | libmhello/build/root.build | 10 | ||||
-rw-r--r-- | libmhello/buildfile | 9 | ||||
-rw-r--r-- | libmhello/libmhello/buildfile | 19 | ||||
-rw-r--r-- | libmhello/libmhello/hello.cxx | 20 | ||||
-rw-r--r-- | libmhello/libmhello/hello.mxx | 52 | ||||
-rw-r--r-- | libmhello/manifest | 23 | ||||
-rw-r--r-- | libmhello/tests/.gitignore | 1 | ||||
-rw-r--r-- | libmhello/tests/build/.gitignore | 1 | ||||
-rw-r--r-- | libmhello/tests/build/bootstrap.build | 5 | ||||
-rw-r--r-- | libmhello/tests/build/root.build | 13 | ||||
-rw-r--r-- | libmhello/tests/buildfile | 1 | ||||
-rw-r--r-- | libmhello/tests/test/buildfile | 6 | ||||
-rw-r--r-- | libmhello/tests/test/driver.cxx | 15 | ||||
-rw-r--r-- | libmhello/tests/test/test.out | 3 |
19 files changed, 212 insertions, 0 deletions
diff --git a/libmhello/.gitignore b/libmhello/.gitignore new file mode 100644 index 0000000..1173da4 --- /dev/null +++ b/libmhello/.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/libmhello/INSTALL b/libmhello/INSTALL new file mode 100644 index 0000000..485b10f --- /dev/null +++ b/libmhello/INSTALL @@ -0,0 +1 @@ +Just use build2, bro. diff --git a/libmhello/build/.gitignore b/libmhello/build/.gitignore new file mode 100644 index 0000000..225c27f --- /dev/null +++ b/libmhello/build/.gitignore @@ -0,0 +1 @@ +config.build diff --git a/libmhello/build/bootstrap.build b/libmhello/build/bootstrap.build new file mode 100644 index 0000000..efd74f9 --- /dev/null +++ b/libmhello/build/bootstrap.build @@ -0,0 +1,7 @@ +project = libmhello + +using version +using config +using dist +using test +using install diff --git a/libmhello/build/export.build b/libmhello/build/export.build new file mode 100644 index 0000000..8d39dbb --- /dev/null +++ b/libmhello/build/export.build @@ -0,0 +1,6 @@ +$out_root/: +{ + include libmhello/ +} + +export $out_root/libmhello/lib{mhello} diff --git a/libmhello/build/root.build b/libmhello/build/root.build new file mode 100644 index 0000000..0f4a099 --- /dev/null +++ b/libmhello/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/libmhello/buildfile b/libmhello/buildfile new file mode 100644 index 0000000..2b699a3 --- /dev/null +++ b/libmhello/buildfile @@ -0,0 +1,9 @@ +./: libmhello/ tests/ doc{INSTALL version} file{manifest} + +doc{version}: file{manifest} # Generated by the version module. +doc{version}: dist = true + +# Don't install tests or the INSTALL file. +# +dir{tests/}: install = false +doc{INSTALL}@./: install = false 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 +} diff --git a/libmhello/manifest b/libmhello/manifest new file mode 100644 index 0000000..fb86191 --- /dev/null +++ b/libmhello/manifest @@ -0,0 +1,23 @@ +: 1 +name: libmhello +version: 1.1.0 +summary: The modularized "Hello World" example library +license: MIT +tags: c++, hello, world, example, modules +description: \ +A simple library that implements the "Hello World" example in C++ with +modules. Its primary goal is to show a canonical build2/bpkg project/package. +\ +url: http://www.example.org/libmhello +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 +depends: libmformat [1.0.0 2.0.0-); compatible with libmformat-1.X.Y +depends: libmprint [1.0.0 2.0.0-); compatible with libmprint-1.X.Y diff --git a/libmhello/tests/.gitignore b/libmhello/tests/.gitignore new file mode 100644 index 0000000..e54525b --- /dev/null +++ b/libmhello/tests/.gitignore @@ -0,0 +1 @@ +driver diff --git a/libmhello/tests/build/.gitignore b/libmhello/tests/build/.gitignore new file mode 100644 index 0000000..225c27f --- /dev/null +++ b/libmhello/tests/build/.gitignore @@ -0,0 +1 @@ +config.build diff --git a/libmhello/tests/build/bootstrap.build b/libmhello/tests/build/bootstrap.build new file mode 100644 index 0000000..2c2de24 --- /dev/null +++ b/libmhello/tests/build/bootstrap.build @@ -0,0 +1,5 @@ +project = # Unnamed subproject. + +using config +using dist +using test diff --git a/libmhello/tests/build/root.build b/libmhello/tests/build/root.build new file mode 100644 index 0000000..58dffed --- /dev/null +++ b/libmhello/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/libmhello/tests/buildfile b/libmhello/tests/buildfile new file mode 100644 index 0000000..1a8bcc9 --- /dev/null +++ b/libmhello/tests/buildfile @@ -0,0 +1 @@ +./: test/ diff --git a/libmhello/tests/test/buildfile b/libmhello/tests/test/buildfile new file mode 100644 index 0000000..88a391c --- /dev/null +++ b/libmhello/tests/test/buildfile @@ -0,0 +1,6 @@ +import libs = libmhello%lib{mhello} +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/libmhello/tests/test/driver.cxx b/libmhello/tests/test/driver.cxx new file mode 100644 index 0000000..debf04a --- /dev/null +++ b/libmhello/tests/test/driver.cxx @@ -0,0 +1,15 @@ +// file: tests/test/driver.cxx -*- C++ -*- + +import std.core; +import format; // volume +import hello; + +int +main () +{ + using namespace hello; + + say ("World"); + say ("World", format::volume::loud); + say_formatted ("Hi, World!"); +} diff --git a/libmhello/tests/test/test.out b/libmhello/tests/test/test.out new file mode 100644 index 0000000..a9ec19f --- /dev/null +++ b/libmhello/tests/test/test.out @@ -0,0 +1,3 @@ +Hello, World! +HELLO, World! +Hi, World! |