From 290ea7840c979e38a2108030a99e7e9c61f40a8c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 23 Nov 2017 11:43:02 +0200 Subject: Restructure and install std-detect.hxx We have to install this header since it needs to be included'able during module sidebuilds. --- build/export.build | 4 +- build/root.build | 1 + buildfile | 91 +--------------------------- dummy.cxx | 5 -- libstd-modules/buildfile | 97 ++++++++++++++++++++++++++++++ libstd-modules/dummy.cxx | 5 ++ libstd-modules/std-core.mxx | 127 +++++++++++++++++++++++++++++++++++++++ libstd-modules/std-detect.hxx | 15 +++++ libstd-modules/std-io.mxx | 28 +++++++++ libstd-modules/std-regex.mxx | 57 ++++++++++++++++++ libstd-modules/std-threading.mxx | 60 ++++++++++++++++++ std-core.mxx | 126 -------------------------------------- std-detect.hxx | 15 ----- std-io.mxx | 28 --------- std-regex.mxx | 57 ------------------ std-threading.mxx | 60 ------------------ 16 files changed, 393 insertions(+), 383 deletions(-) delete mode 100644 dummy.cxx create mode 100644 libstd-modules/buildfile create mode 100644 libstd-modules/dummy.cxx create mode 100644 libstd-modules/std-core.mxx create mode 100644 libstd-modules/std-detect.hxx create mode 100644 libstd-modules/std-io.mxx create mode 100644 libstd-modules/std-regex.mxx create mode 100644 libstd-modules/std-threading.mxx delete mode 100644 std-core.mxx delete mode 100644 std-detect.hxx delete mode 100644 std-io.mxx delete mode 100644 std-regex.mxx delete mode 100644 std-threading.mxx diff --git a/build/export.build b/build/export.build index 334181e..6f0347c 100644 --- a/build/export.build +++ b/build/export.build @@ -4,7 +4,7 @@ $out_root/: { - include buildfile + include libstd-modules/ } -export $($out_root/:export_target) +export $($out_root/libstd-modules/:export_target) diff --git a/build/root.build b/build/root.build index 9f670f8..4e7e989 100644 --- a/build/root.build +++ b/build/root.build @@ -9,5 +9,6 @@ using cxx if! $cxx.features.modules warn 'c++ compiler does not support modules' +hxx{*}: extension = hxx mxx{*}: extension = mxx cxx{*}: extension = cxx diff --git a/buildfile b/buildfile index f301ef1..2a5ec7a 100644 --- a/buildfile +++ b/buildfile @@ -2,7 +2,7 @@ # copyright : Copyright (c) 2014-2017 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -./: tests/ doc{INSTALL LICENSE NEWS README version} file{manifest} +./: {*/ -build/} doc{INSTALL LICENSE NEWS README version} file{manifest} # The version file is auto-generated (by the version module) from manifest. # Include it in distribution and don't remove when cleaning in src (so that @@ -16,92 +16,3 @@ doc{version}: clean = ($src_root != $out_root) # dir{tests/}: install = false doc{INSTALL}@./: install = false - -if! $cxx.features.modules -{ - # List sources as files so that we can prepare a distribution with any - # compiler. - # - ./: {mxx cxx}{*} -} -else -{ - # We only do the static library since this is what we would have gotten - # should we have used headers (i.e., whatever object code generated from - # those headers would have ended up in each executable/library). - # - ./: liba{std-modules} - - # Building of the modules gets rather compiler-specific. - # - if ($cxx.id.type == 'clang') - { - # Use the naming scheme expected by -fprebuilt-module-path=. Can also be - # specified with -fmodule-file=. - # - core = std.core.pcm - io = std.io.pcm - regex = std.regex.pcm - threading = std.threading.pcm - - liba{std-modules}: bmia{$core $io $regex $threading} - - export_target = $out_root/liba{std-modules} - } - elif ($cxx.id.type == 'msvc') - { - # Use the naming scheme expected by /module:stdIfcDir. Note that IFCPATH - # would require an extra directory (x64 or x86; e.g., x64/Release/). - # - # @@ Currently VC looks in Release regardless of /MD or /MDd. - # - dir = release/ - core = $dir/std.core.ifc - io = $dir/std.io.ifc - regex = $dir/std.regex.ifc - threading = $dir/std.threading.ifc - - bmia{$core $io $regex $threading}: fsdir{$dir} - - # VC expects to find std.lib next to the .ifc's. Make it the real one - # while std-modules -- a dummy. - # - ./: $dir/liba{std} - $dir/liba{std}: bmia{$core $io $regex $threading} - liba{std-modules}: cxx{dummy.cxx} - - # @@ Doesn't work if installed so we don't bother installing it. But we - # still install dummy std-modules; the idea is to link a dummy and - # (try) to use Microsoft-shipped .ifc's. - # - $dir/liba{std}: install = false - - # Include std-modules to trigger install. - # - export_target = $out_root/$dir/liba{std} $out_root/liba{std-modules} - } - - # @@ TMP: use utility library instead? - # - if ($cxx.target.class == 'linux' || $cxx.target.class == 'bsd') - cxx.coptions += -fPIC - - # Clang with libc++ (sometimes) needs it -- go figure. - # - if ($cxx.target.class != "windows") - cxx.libs += -lpthread - - bmia{$core}: mxx{std-core} - bmia{$io}: mxx{std-io} bmia{$core} - bmia{$regex}: mxx{std-regex} bmia{$core} bmia{$io} - bmia{$threading}: mxx{std-threading} bmia{$core} - - mxx{std-core}@./: cc.module_name = std.core - mxx{std-io}@./: cc.module_name = std.io - mxx{std-regex}@./: cc.module_name = std.regex - mxx{std-threading}@./: cc.module_name = std.threading - - # Install into the libstd-modules/ subdirectory of, say, /usr/include/. - # - mxx{*}: install = include/$project/ -} diff --git a/dummy.cxx b/dummy.cxx deleted file mode 100644 index fabedbf..0000000 --- a/dummy.cxx +++ /dev/null @@ -1,5 +0,0 @@ -// file : dummy.cxx -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -// Dummy translation unit used to create dummy std.lib for VC. diff --git a/libstd-modules/buildfile b/libstd-modules/buildfile new file mode 100644 index 0000000..a04d103 --- /dev/null +++ b/libstd-modules/buildfile @@ -0,0 +1,97 @@ +# file : libstd-modules/buildfile +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +if! $cxx.features.modules +{ + # List sources as files so that we can prepare a distribution with any + # compiler. + # + ./: {hxx mxx cxx}{*} +} +else +{ + # We only do the static library since this is what we would have gotten + # should we have used headers (i.e., whatever object code generated from + # those headers would have ended up in each executable/library). + # + ./: liba{std-modules} + + # Building of the modules gets rather compiler-specific. + # + if ($cxx.id.type == 'clang') + { + # Use the naming scheme expected by -fprebuilt-module-path=. Can also be + # specified with -fmodule-file=. + # + core = std.core.pcm + io = std.io.pcm + regex = std.regex.pcm + threading = std.threading.pcm + + liba{std-modules}: bmia{$core $io $regex $threading} + + export_target = $out_base/liba{std-modules} + } + elif ($cxx.id.type == 'msvc') + { + # Use the naming scheme expected by /module:stdIfcDir. Note that IFCPATH + # would require an extra directory (x64 or x86; e.g., x64/Release/). + # + # @@ Currently VC looks in Release regardless of /MD or /MDd. + # + dir = release/ + core = $dir/std.core.ifc + io = $dir/std.io.ifc + regex = $dir/std.regex.ifc + threading = $dir/std.threading.ifc + + bmia{$core $io $regex $threading}: fsdir{$dir} + + # VC expects to find std.lib next to the .ifc's. Make it the real one + # while std-modules -- a dummy. + # + ./: $dir/liba{std} + $dir/liba{std}: bmia{$core $io $regex $threading} + liba{std-modules}: cxx{dummy.cxx} + + # @@ Doesn't work if installed so we don't bother installing it. But we + # still install dummy std-modules; the idea is to link a dummy and + # (try) to use Microsoft-shipped .ifc's. + # + $dir/liba{std}: install = false + + # Include std-modules to trigger install. + # + export_target = $out_base/$dir/liba{std} $out_base/liba{std-modules} + } + + liba{std-modules}: hxx{*} + + # @@ TMP: use utility library instead? + # + if ($cxx.target.class == 'linux' || $cxx.target.class == 'bsd') + cxx.coptions += -fPIC + + # Clang with libc++ (sometimes) needs it -- go figure. + # + if ($cxx.target.class != "windows") + cxx.libs += -lpthread + + bmia{$core}: mxx{std-core} + bmia{$io}: mxx{std-io} bmia{$core} + bmia{$regex}: mxx{std-regex} bmia{$core} bmia{$io} + bmia{$threading}: mxx{std-threading} bmia{$core} + + mxx{std-core}@./: cc.module_name = std.core + mxx{std-io}@./: cc.module_name = std.io + mxx{std-regex}@./: cc.module_name = std.regex + mxx{std-threading}@./: cc.module_name = std.threading + + cxx.poptions =+ "-I$out_root" "-I$src_root" + liba{std-modules}: cxx.export.poptions = "-I$out_root" "-I$src_root" + + # Install into the libstd-modules/ subdirectory of, say, /usr/include/. + # + {hxx mxx}{*}: install = include/$project/ +} diff --git a/libstd-modules/dummy.cxx b/libstd-modules/dummy.cxx new file mode 100644 index 0000000..68ebd58 --- /dev/null +++ b/libstd-modules/dummy.cxx @@ -0,0 +1,5 @@ +// file : libstd-modules/dummy.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +// Dummy translation unit used to create dummy std.lib for VC. diff --git a/libstd-modules/std-core.mxx b/libstd-modules/std-core.mxx new file mode 100644 index 0000000..c3f3566 --- /dev/null +++ b/libstd-modules/std-core.mxx @@ -0,0 +1,127 @@ +// file : libstd-modules/std-core.mxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +// For some standard library implementations we need to pre-include certain +// headers to prevent their exporting. + +#include + +#if defined(_MSC_VER) +/* +# include +# include +# include +# include +# include // struct tm; +*/ +#elif defined(__GLIBCXX__) +# include +# include +# include // struct tm forward declaration. +# include +# include +# include +# include +# include +# include // Names with internal linkage. +#elif defined(_LIBCPP_VERSION) +#endif + +export module std.core; + +export +{ + // These are defined in which we have pre-included. + // +#ifdef __GLIBCXX__ + namespace std + { + typedef __SIZE_TYPE__ size_t; + typedef __PTRDIFF_TYPE__ ptrdiff_t; + typedef decltype(nullptr) nullptr_t; + } +#endif + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +} + +export +{ +#include +#include +#include + +#include +#include // @@ Not in the proposal. + +#include +#include +#include +#include +#include +#include +#include +} + +#if defined(_MSC_VER) || defined(__clang__) +export +{ +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#ifndef __GLIBCXX__ +# include +#else +// Contents of without static __ioinit. +// +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + extern istream cin; + extern ostream cout; + extern ostream cerr; + extern ostream clog; + + //static ios_base::Init __ioinit; +_GLIBCXX_END_NAMESPACE_VERSION +} +#endif +} +#endif + +// std.threading +// +export +{ +#include +#include +#include +#include +} diff --git a/libstd-modules/std-detect.hxx b/libstd-modules/std-detect.hxx new file mode 100644 index 0000000..b2998b5 --- /dev/null +++ b/libstd-modules/std-detect.hxx @@ -0,0 +1,15 @@ +// To detect the standard library we need to include a certain header first. +// +#if defined(__clang__) +# if __has_include(<__config>) // libc++ _LIBCPP_VERSION +# include <__config> +# elif __has_include() // libstdc++ __GLIBCXX__ +# include +# endif +#elif defined(__GNUC__) +# include // libstdc++ __GLIBCXX__ +#endif + +#if !defined(_MSC_VER) && !defined(__GLIBCXX__) && !defined(_LIBCPP_VERSION) +# error unknown standard library implementation +#endif diff --git a/libstd-modules/std-io.mxx b/libstd-modules/std-io.mxx new file mode 100644 index 0000000..701e1b9 --- /dev/null +++ b/libstd-modules/std-io.mxx @@ -0,0 +1,28 @@ +// file : libstd-modules/std-io.mxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +export module std.io; + +#ifdef _MSC_VER + +export import std.core; + +#elif defined(__clang__) +// Empty: can't handle the below and doesn't suppor re-export. +#else + +import std.core; + +export +{ +#include +#include +#include +#include +#include +#include +#include +} + +#endif diff --git a/libstd-modules/std-regex.mxx b/libstd-modules/std-regex.mxx new file mode 100644 index 0000000..427642c --- /dev/null +++ b/libstd-modules/std-regex.mxx @@ -0,0 +1,57 @@ +// file : libstd-modules/std-regex.mxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +// Pre-includes. +// +#include + +#if defined(_MSC_VER) +# include +# include +# include +# include +# include +# include +# include + +# include +# include +# include +# include +#elif defined(__GLIBCXX__) +# define _GLIBCXX_ALGORITHM +# define _GLIBCXX_BITSET +# define _GLIBCXX_IOSFWD +# define _GLIBCXX_ITERATOR +# define _GLIBCXX_LOCALE +# define _GLIBCXX_MEMORY +# define _GLIBCXX_SSTREAM +# define _GLIBCXX_STACK +# define _GLIBCXX_STDEXCEPT +# define _GLIBCXX_STRING +# define _GLIBCXX_UTILITY +# define _GLIBCXX_VECTOR +# define _GLIBCXX_MAP +# define _GLIBCXX_CSTRING + +# define _GLIBCXX_STD_FUNCTION_H // +# define _ALIGNED_BUFFER_H // + +# include + +# include // Missing include. +#elif defined(_LIBCPP_VERSION) +#endif + +export module std.regex; + +#ifdef __GLIBCXX__ +import std.core; +import std.io; +#endif + +export +{ +#include +} diff --git a/libstd-modules/std-threading.mxx b/libstd-modules/std-threading.mxx new file mode 100644 index 0000000..b03f55f --- /dev/null +++ b/libstd-modules/std-threading.mxx @@ -0,0 +1,60 @@ +// file : libstd-modules/std-threading.mxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +export module std.threading; // Dummy. + +#if 0 +// Pre-includes. +// +#include + +#if defined(_MSC_VER) +#error TODO +#elif defined(__GLIBCXX__) + +// +# define _GLIBCXX_TUPLE +# define _GLIBCXX_CHRONO +# define __EXCEPTION__ // +# define _GLIBCXX_TYPE_TRAITS +# define _GLIBCXX_SYSTEM_ERROR +# define _GLIBCXX_STD_FUNCTION_H // +# define _FUNCTEXCEPT_H +# define _MOVE_H + +// +# include // Missing include. + +// +# define _CONCURRENCE_H // +# define _ALLOC_TRAITS_H // +# define _ALLOCATOR_H // +# define _UNIQUE_PTR_H // +# define _SHARED_PTR_H // +# define _CXXABI_FORCED_H // +# include // Missing include. + +// +# define _GLIBCXX_MEMORY +# define _FUNCTIONAL_HASH_H // +# define _GLIBCXX_INVOKE_H // + +# include +#elif defined(_LIBCPP_VERSION) +#endif + +export module std.threading; + +#ifdef __GLIBCXX__ +import std.core; +#endif + +export +{ +#include +#include +#include +#include +} +#endif diff --git a/std-core.mxx b/std-core.mxx deleted file mode 100644 index ace9b59..0000000 --- a/std-core.mxx +++ /dev/null @@ -1,126 +0,0 @@ -// file : std-core.mxx -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -// For some standard library implementations we need to pre-include certain -// headers to prevent their exporting. - -#include "std-detect.hxx" - -#if defined(_MSC_VER) -/* -# include -# include -# include -# include -# include // struct tm; -*/ -#elif defined(__GLIBCXX__) -# include -# include -# include // struct tm forward declaration. -# include -# include -# include -# include -# include // Names with internal linkage. -#elif defined(_LIBCPP_VERSION) -#endif - -export module std.core; - -export -{ - // These are defined in which we have pre-included. - // -#ifdef __GLIBCXX__ - namespace std - { - typedef __SIZE_TYPE__ size_t; - typedef __PTRDIFF_TYPE__ ptrdiff_t; - typedef decltype(nullptr) nullptr_t; - } -#endif - -#include -#include -#include - -#include -#include - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -} - -export -{ -#include -#include -#include - -#include -#include // @@ Not in the proposal. - -#include -#include -#include -#include -#include -#include -#include -} - -#if defined(_MSC_VER) || defined(__clang__) -export -{ -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#ifndef __GLIBCXX__ -# include -#else -// Contents of without static __ioinit. -// -namespace std _GLIBCXX_VISIBILITY(default) -{ -_GLIBCXX_BEGIN_NAMESPACE_VERSION - extern istream cin; - extern ostream cout; - extern ostream cerr; - extern ostream clog; - - //static ios_base::Init __ioinit; -_GLIBCXX_END_NAMESPACE_VERSION -} -#endif -} -#endif - -// std.threading -// -export -{ -#include -#include -#include -#include -} diff --git a/std-detect.hxx b/std-detect.hxx deleted file mode 100644 index b2998b5..0000000 --- a/std-detect.hxx +++ /dev/null @@ -1,15 +0,0 @@ -// To detect the standard library we need to include a certain header first. -// -#if defined(__clang__) -# if __has_include(<__config>) // libc++ _LIBCPP_VERSION -# include <__config> -# elif __has_include() // libstdc++ __GLIBCXX__ -# include -# endif -#elif defined(__GNUC__) -# include // libstdc++ __GLIBCXX__ -#endif - -#if !defined(_MSC_VER) && !defined(__GLIBCXX__) && !defined(_LIBCPP_VERSION) -# error unknown standard library implementation -#endif diff --git a/std-io.mxx b/std-io.mxx deleted file mode 100644 index 5370817..0000000 --- a/std-io.mxx +++ /dev/null @@ -1,28 +0,0 @@ -// file : std-io.mxx -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -export module std.io; - -#ifdef _MSC_VER - -export import std.core; - -#elif defined(__clang__) -// Empty: can't handle the below and doesn't suppor re-export. -#else - -import std.core; - -export -{ -#include -#include -#include -#include -#include -#include -#include -} - -#endif diff --git a/std-regex.mxx b/std-regex.mxx deleted file mode 100644 index 7edfd94..0000000 --- a/std-regex.mxx +++ /dev/null @@ -1,57 +0,0 @@ -// file : std-regex.mxx -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -// Pre-includes. -// -#include "std-detect.hxx" - -#if defined(_MSC_VER) -# include -# include -# include -# include -# include -# include -# include - -# include -# include -# include -# include -#elif defined(__GLIBCXX__) -# define _GLIBCXX_ALGORITHM -# define _GLIBCXX_BITSET -# define _GLIBCXX_IOSFWD -# define _GLIBCXX_ITERATOR -# define _GLIBCXX_LOCALE -# define _GLIBCXX_MEMORY -# define _GLIBCXX_SSTREAM -# define _GLIBCXX_STACK -# define _GLIBCXX_STDEXCEPT -# define _GLIBCXX_STRING -# define _GLIBCXX_UTILITY -# define _GLIBCXX_VECTOR -# define _GLIBCXX_MAP -# define _GLIBCXX_CSTRING - -# define _GLIBCXX_STD_FUNCTION_H // -# define _ALIGNED_BUFFER_H // - -# include - -# include // Missing include. -#elif defined(_LIBCPP_VERSION) -#endif - -export module std.regex; - -#ifdef __GLIBCXX__ -import std.core; -import std.io; -#endif - -export -{ -#include -} diff --git a/std-threading.mxx b/std-threading.mxx deleted file mode 100644 index ab397cc..0000000 --- a/std-threading.mxx +++ /dev/null @@ -1,60 +0,0 @@ -// file : std-threading.mxx -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -export module std.threading; // Dummy. - -#if 0 -// Pre-includes. -// -#include "std-detect.hxx" - -#if defined(_MSC_VER) -#error TODO -#elif defined(__GLIBCXX__) - -// -# define _GLIBCXX_TUPLE -# define _GLIBCXX_CHRONO -# define __EXCEPTION__ // -# define _GLIBCXX_TYPE_TRAITS -# define _GLIBCXX_SYSTEM_ERROR -# define _GLIBCXX_STD_FUNCTION_H // -# define _FUNCTEXCEPT_H -# define _MOVE_H - -// -# include // Missing include. - -// -# define _CONCURRENCE_H // -# define _ALLOC_TRAITS_H // -# define _ALLOCATOR_H // -# define _UNIQUE_PTR_H // -# define _SHARED_PTR_H // -# define _CXXABI_FORCED_H // -# include // Missing include. - -// -# define _GLIBCXX_MEMORY -# define _FUNCTIONAL_HASH_H // -# define _GLIBCXX_INVOKE_H // - -# include -#elif defined(_LIBCPP_VERSION) -#endif - -export module std.threading; - -#ifdef __GLIBCXX__ -import std.core; -#endif - -export -{ -#include -#include -#include -#include -} -#endif -- cgit v1.1