Skip to content

Commit

Permalink
Add module support and tests. (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
jzmaddock authored Dec 18, 2024
1 parent f039773 commit 7af2aad
Show file tree
Hide file tree
Showing 81 changed files with 3,018 additions and 321 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,41 @@ jobs:
- name: Test
run: ../../../b2 toolset=$TOOLSET define=CI_SUPPRESS_KNOWN_ISSUES define=SLOW_COMPILER
working-directory: ../boost-root/libs/regex/test
ubuntu-jammy-clang-18-modules:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
with:
fetch-depth: '0'
- uses: mstachniuk/ci-skip@v1
with:
commit-filter: '[skip ci];[ci skip];[CI SKIP];[SKIP CI];***CI SKIP***;***SKIP CI***;[windows];[Windows];[WINDOWS];[apple];[Apple];[APPLE]'
commit-filter-separator: ';'
fail-fast: true
- name: Grab install script
run: wget https://apt.llvm.org/llvm.sh && chmod u+x llvm.sh
- name: Install clang 18 packages
run: sudo ./llvm.sh 18 && clang++-18 --version
- name: Checkout main boost
run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
- name: Update tools/boostdep
run: git submodule update --init tools/boostdep
working-directory: ../boost-root
- name: Copy files
run: cp -r $GITHUB_WORKSPACE/* libs/regex
working-directory: ../boost-root
- name: Install deps
run: python tools/boostdep/depinst/depinst.py -I example -g "--jobs 3" regex
working-directory: ../boost-root
- name: Bootstrap
run: ./bootstrap.sh
working-directory: ../boost-root
- name: Generate headers
run: ./b2 headers
working-directory: ../boost-root
- name: Test
run: CXX=clang++-18 LIBRARIES="-licuuc -licudata -licui18n" ./test_clang.sh
working-directory: ../boost-root/libs/regex/test/module
macos:
runs-on: macos-latest
strategy:
Expand Down Expand Up @@ -339,6 +374,9 @@ jobs:
commit-filter: '[skip ci];[ci skip];[CI SKIP];[SKIP CI];***CI SKIP***;***SKIP CI***;[apple];[Apple];[APPLE];[linux];[Linux];[LINUX]'
commit-filter-separator: ';'
fail-fast: true
- uses: TheMrMilchmann/setup-msvc-dev@v3
with:
arch: x64
- name: Checkout main boost
run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
- name: Update tools/boostdep
Expand All @@ -365,6 +403,9 @@ jobs:
- name: Test
run: ..\..\..\b2 --hash %ARGS%
working-directory: ../boost-root/libs/regex/test
- name: Module Test
run: msvc_test.bat
working-directory: ../boost-root/libs/regex/test/module
ubuntu-cmake-install:
runs-on: ubuntu-20.04
strategy:
Expand Down
6 changes: 3 additions & 3 deletions doc/html/boost_regex/install.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link rel="home" href="../index.html" title="Boost.Regex 7.0.1">
<link rel="up" href="../index.html" title="Boost.Regex 7.0.1">
<link rel="prev" href="configuration/tuning.html" title="Algorithm Tuning">
<link rel="next" href="intro.html" title="Introduction and Overview">
<link rel="next" href="modules.html" title="Module Support (Experimental)">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
Expand All @@ -21,7 +21,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="configuration/tuning.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="intro.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
<a accesskey="p" href="configuration/tuning.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="modules.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
Expand Down Expand Up @@ -109,7 +109,7 @@ <h5>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="configuration/tuning.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="intro.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
<a accesskey="p" href="configuration/tuning.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="modules.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
6 changes: 3 additions & 3 deletions doc/html/boost_regex/intro.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Regex 7.0.1">
<link rel="up" href="../index.html" title="Boost.Regex 7.0.1">
<link rel="prev" href="install.html" title="Building and Installing the Library">
<link rel="prev" href="modules.html" title="Module Support (Experimental)">
<link rel="next" href="unicode.html" title="Unicode and Boost.Regex">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
Expand All @@ -21,7 +21,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="install.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="unicode.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
<a accesskey="p" href="modules.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="unicode.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
Expand Down Expand Up @@ -206,7 +206,7 @@
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="install.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="unicode.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
<a accesskey="p" href="modules.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="unicode.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
108 changes: 108 additions & 0 deletions doc/html/boost_regex/modules.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Module Support (Experimental)</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Regex 7.0.1">
<link rel="up" href="../index.html" title="Boost.Regex 7.0.1">
<link rel="prev" href="install.html" title="Building and Installing the Library">
<link rel="next" href="intro.html" title="Introduction and Overview">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="install.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="intro.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="boost_regex.modules"></a><a class="link" href="modules.html" title="Module Support (Experimental)">Module Support (Experimental)</a>
</h2></div></div></div>
<p>
This library has experimental support for C++ modules (C++20 or later), currently
the support is experimental not least because at the time of writing (2025)
build tools have yet to catch up with module support.
</p>
<p>
In order to use this library as a module you simply add a:
</p>
<pre class="programlisting"><span class="identifier">import</span> <span class="identifier">boost</span><span class="special">.</span><span class="identifier">regex</span><span class="special">;</span>
</pre>
<p>
to your code.
</p>
<p>
Before that you must first build the module, which consists of these steps:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Depending on your compiler, you may need to build the standard library
module, and place the standard module somewhere that your compiler can
find it.
</li>
<li class="listitem">
Build <code class="computeroutput"><span class="identifier">libs</span><span class="special">/</span><span class="identifier">regex</span><span class="special">/</span><span class="identifier">module</span><span class="special">/</span><span class="identifier">regex</span><span class="special">.</span><span class="identifier">cxx</span></code> into the boost.regex module, and
place the module definition file somewhere that your compiler can find
it.
</li>
<li class="listitem">
Build all the source files in <code class="computeroutput"><span class="identifier">libs</span><span class="special">/</span><span class="identifier">regex</span><span class="special">/</span><span class="identifier">module</span></code>
(including regex.cxx) into a library, and place the result somewhere your
linker can find it.
</li>
</ul></div>
<p>
Visual studio users can simplify all of the above into one step, by placing
everything in <code class="computeroutput"><span class="identifier">libs</span><span class="special">/</span><span class="identifier">regex</span><span class="special">/</span><span class="identifier">module</span></code>
into a static library project, and then adding the <code class="computeroutput"><span class="special">/</span><span class="identifier">interface</span></code> command line option to the regex.cxx
source file.
</p>
<p>
Known limitations:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
As of the start of 2025, only very recent versions of clang and msvc are
supported. GCC is definitely not supported.
</li>
<li class="listitem">
The regex library must always be consumed via <code class="computeroutput"><span class="identifier">import</span>
<span class="identifier">boost</span><span class="special">.</span><span class="identifier">regex</span><span class="special">;</span></code>
and you can never mix this with <code class="computeroutput"><span class="preprocessor">#includes</span>
<span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">regex</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>.
</li>
<li class="listitem">
Ideally the standard library should always be used via <code class="computeroutput"><span class="identifier">import</span>
<span class="identifier">std</span></code> and not via #includes: more
recent compilers are mostly making this work, but are still very fragile.
</li>
<li class="listitem">
The regex version imported, is always the "standalone" version
which includes no other Boost headers.
</li>
</ul></div>
<p>
Finally... there are some build and test scripts in <code class="computeroutput"><span class="identifier">libs</span><span class="special">/</span><span class="identifier">regex</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">module</span></code>
for msvc and clang.
</p>
</div>
<div class="copyright-footer">Copyright © 1998-2013 John Maddock<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="install.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="intro.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions doc/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<dt><span class="section"><a href="boost_regex/configuration/tuning.html">Algorithm Tuning</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="boost_regex/install.html">Building and Installing the Library</a></span></dt>
<dt><span class="section"><a href="boost_regex/modules.html">Module Support (Experimental)</a></span></dt>
<dt><span class="section"><a href="boost_regex/intro.html">Introduction and Overview</a></span></dt>
<dt><span class="section"><a href="boost_regex/unicode.html">Unicode and Boost.Regex</a></span></dt>
<dt><span class="section"><a href="boost_regex/captures.html">Understanding Marked Sub-Expressions
Expand Down
40 changes: 40 additions & 0 deletions doc/modules.qbk
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[/
Copyright 2024 John Maddock.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt).
]

[section:modules Module Support (Experimental)]

This library has experimental support for C++ modules (C++20 or later), currently the support is experimental
not least because at the time of writing (2025) build tools have yet to catch up with module support.

In order to use this library as a module you simply add a:

```
import boost.regex;
```

to your code.

Before that you must first build the module, which consists of these steps:

* Depending on your compiler, you may need to build the standard library module, and place the standard module somewhere that your compiler can find it.
* Build `libs/regex/module/regex.cxx` into the boost.regex module, and place the module definition file somewhere that your compiler can find it.
* Build all the source files in `libs/regex/module` (including regex.cxx) into a library, and place the result somewhere your linker can find it.

Visual studio users can simplify all of the above into one step, by placing everything in `libs/regex/module` into a static library project, and then adding the `/interface`
command line option to the regex.cxx source file.

Known limitations:

* As of the start of 2025, only very recent versions of clang and msvc are supported. GCC is definitely not supported.
* The regex library must always be consumed via `import boost.regex;` and you can never mix this with `#includes <boost/regex.hpp>`.
* Ideally the standard library should always be used via `import std` and not via #includes: more recent compilers are mostly making this work, but are still very fragile.
* The regex version imported, is always the "standalone" version which includes no other Boost headers.

Finally... there are some build and test scripts in `libs/regex/test/module` for msvc and clang.

[endsect]

1 change: 1 addition & 0 deletions doc/regex.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ PDF version of this manual is also available].

[include configuration.qbk]
[include install.qbk]
[include modules.qbk]
[include introduction.qbk]
[include unicode.qbk]
[include captures.qbk]
Expand Down
23 changes: 12 additions & 11 deletions include/boost/regex/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <boost/type_traits/is_enum.hpp>
#include <boost/type_traits/is_base_and_derived.hpp>
#include <boost/static_assert.hpp>
#ifndef BOOST_TEST_TR1_REGEX
#if !defined(BOOST_TEST_TR1_REGEX) && !defined(BOOST_REGEX_TEST_MODULE)
#include <boost/regex.hpp>
#endif
#include <bitset>
Expand All @@ -37,6 +37,16 @@
#define RW_NS std
#endif


//
// alter this to std::tr1, to test a std implementation:
//
#ifndef BOOST_TEST_TR1_REGEX
namespace global_regex_namespace = ::boost;
#else
namespace global_regex_namespace = ::std::tr1;
#endif

namespace boost{

//
Expand Down Expand Up @@ -178,15 +188,6 @@ struct regex_traits_architype
regex_traits_architype& operator=(const regex_traits_architype&){ return *this; }
};

//
// alter this to std::tr1, to test a std implementation:
//
#ifndef BOOST_TEST_TR1_REGEX
namespace global_regex_namespace = ::boost;
#else
namespace global_regex_namespace = ::std::tr1;
#endif

template <class Bitmask>
struct BitmaskConcept
{
Expand Down Expand Up @@ -273,7 +274,7 @@ template <class Regex>
struct regex_traits_computer;

template <class charT, class traits>
struct regex_traits_computer< global_regex_namespace::basic_regex<charT, traits> >
struct regex_traits_computer< ::boost::basic_regex<charT, traits> >
{
typedef traits type;
};
Expand Down
22 changes: 20 additions & 2 deletions include/boost/regex/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@
#endif
#endif

#ifndef BOOST_REGEX_MODULE_EXPORT
#define BOOST_REGEX_MODULE_EXPORT
#define BOOST_REGEX_STATIC_CONST static const
#else
#define BOOST_REGEX_STATIC_CONST inline constexpr
#define BOOST_REGEX_STANDALONE
#endif

/*
* Borland C++ Fix/error check
* this has to go *before* we include any std lib headers:
*/
#if defined(__BORLANDC__) && !defined(__clang__)
# include <boost/regex/config/borland.hpp>
#endif

#ifndef BOOST_REGEX_STANDALONE
#include <boost/version.hpp>
#endif
Expand All @@ -40,9 +56,13 @@
*************************************************************************/

#ifdef BOOST_REGEX_STANDALONE
#ifndef BOOST_REGEX_AS_MODULE
#include <cassert>
# define BOOST_REGEX_ASSERT(x) assert(x)
#else
# define BOOST_REGEX_ASSERT(x) do{ if(x == 0) { std::printf("%s:%d Assertion Failed", __FILE__, __LINE__); std::abort(); } }while(0)
#endif
#else
#include <boost/assert.hpp>
# define BOOST_REGEX_ASSERT(x) BOOST_ASSERT(x)
#endif
Expand Down Expand Up @@ -284,8 +304,6 @@
* If there are no exceptions then we must report critical-errors
* the only way we know how; by terminating.
*/
#include <cassert>

# define BOOST_REGEX_NOEH_ASSERT(x) assert(x);
#else
/*
Expand Down
Loading

0 comments on commit 7af2aad

Please sign in to comment.