diff --git a/Makefile b/Makefile index 768395d0..92d18709 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ SANITIZERS := run # SANITIZERS += asan # TODO: tsan msan # endif -.PHONY: default release debug doc run update check ce todo distclean clean codespell clang-tidy build test install all format unstage $(SANITIZERS) +.PHONY: default release debug doc run update check ce todo distclean clean codespell clang-tidy build test install all format unstage $(SANITIZERS) module build-module test-module SYSROOT ?= TOOLCHAIN ?= @@ -134,6 +134,22 @@ build: test: build ctest --test-dir $(BUILD) --rerun-failed --output-on-failure +module build-module: + cmake -G Ninja -S $(SOURCEDIR) -B $(BUILD) $(TOOLCHAIN) $(SYSROOT) \ + -D CMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -D CMAKE_SKIP_INSTALL_RULES=ON \ + -D CMAKE_CXX_STANDARD=23 \ + -D CMAKE_CXX_EXTENSIONS=ON \ + -D CMAKE_CXX_STANDARD_REQUIRED=ON \ + -D CMAKE_CXX_SCAN_FOR_MODULES=ON \ + -D BEMAN_USE_MODULES=ON \ + -D CMAKE_BUILD_TYPE=Release \ + -D CMAKE_CXX_COMPILER=$(CXX) --log-level=VERBOSE + cmake --build $(BUILD) + +test-module: build-module + ctest --test-dir $(BUILD) --rerun-failed --output-on-failure + install: test cmake --install $(BUILD) --prefix /opt/local @@ -141,13 +157,13 @@ CMakeUserPresets.json:: cmake/CMakeUserPresets.json ln -s $< $@ # ========================================================== -release: CMakeUserPresets.json +appleclang-release llvm-release release: #-dk: I'm not sure why that is needed: CMakeUserPresets.json cmake --preset $@ --log-level=TRACE # XXX --fresh ln -fs $(BUILDROOT)/$@/compile_commands.json . cmake --workflow --preset $@ # ========================================================== -debug: CMakeUserPresets.json +appleclang-debug llvm-debug debug: #-dk: I'm not sure why that is needed: CMakeUserPresets.json cmake --preset $@ --log-level=TRACE # XXX --fresh ln -fs $(BUILDROOT)build/$@/compile_commands.json . cmake --workflow --preset $@ diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 71ffabca..464d782f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -18,31 +18,33 @@ if(PROJECT_IS_TOP_LEVEL) endif() set(EXAMPLES - stackoverflow + allocator + doc-just + doc-just_error + doc-just_stopped inspect + intro-1-hello-world + intro-2-hello-async + intro-5-consumer playground sender-demo - when_all-cancel + stackoverflow stop_token stopping - allocator - intro-1-hello-world - intro-2-hello-async - intro-5-consumer - doc-just - doc-just_error - doc-just_stopped + when_all-cancel ) if(BEMAN_USE_MODULES) list(APPEND EXAMPLES modules) # modules.cpp endif() +# set(EXAMPLES) foreach(EXAMPLE ${EXAMPLES}) set(EXAMPLE_TARGET ${PROJECT_NAME}.${EXAMPLE}) add_executable(${EXAMPLE_TARGET}) target_sources(${EXAMPLE_TARGET} PRIVATE ${EXAMPLE}.cpp) if(BEMAN_USE_MODULES) + # target_compile_definitions(${EXAMPLE_TARGET} PUBLIC BEMAN_HAS_MODULES) target_link_libraries(${EXAMPLE_TARGET} PRIVATE beman::execution) else() target_link_libraries( diff --git a/examples/allocator.cpp b/examples/allocator.cpp index 845275ff..3c00ed07 100644 --- a/examples/allocator.cpp +++ b/examples/allocator.cpp @@ -1,10 +1,17 @@ -#include +// examples/allocator.cpp -*-C++-*- +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + #include #include #include #include #include #include +#ifdef BEMAN_HAS_MODULES +import beman.execution; +#else +#include +#endif namespace ex = beman::execution; diff --git a/examples/doc-just.cpp b/examples/doc-just.cpp index a63c2d59..d25ded01 100644 --- a/examples/doc-just.cpp +++ b/examples/doc-just.cpp @@ -1,9 +1,13 @@ // examples/doc-just.cpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#include #include #include +#ifdef BEMAN_HAS_MODULES +import beman.execution; +#else +#include +#endif namespace ex = beman::execution; using namespace std::string_literals; diff --git a/examples/doc-just_error.cpp b/examples/doc-just_error.cpp index c347485b..7acba327 100644 --- a/examples/doc-just_error.cpp +++ b/examples/doc-just_error.cpp @@ -1,9 +1,13 @@ // examples/doc-just_error.cpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#include #include #include +#ifdef BEMAN_HAS_MODULES +import beman.execution; +#else +#include +#endif namespace ex = beman::execution; namespace { diff --git a/examples/doc-just_stopped.cpp b/examples/doc-just_stopped.cpp index 60c854e9..b4fe76f0 100644 --- a/examples/doc-just_stopped.cpp +++ b/examples/doc-just_stopped.cpp @@ -1,10 +1,13 @@ // examples/doc-just_stopped.cpp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#include #include #include -#include //-dk:TODO remove +#ifdef BEMAN_HAS_MODULES +import beman.execution; +#else +#include +#endif namespace ex = beman::execution; namespace { diff --git a/examples/inspect.cpp b/examples/inspect.cpp index e6fcd470..366a6be1 100644 --- a/examples/inspect.cpp +++ b/examples/inspect.cpp @@ -1,16 +1,138 @@ // examples/inspectc.pp -*-C++-*- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#include -#include "meta.hpp" #include +#include #include +#include #include +#include +#include +#ifdef BEMAN_HAS_MODULES +import beman.execution; +#else +#include +#endif namespace ex = beman::execution; // ---------------------------------------------------------------------------- +namespace meta { +// The code in this namespace is a fairly basic way to print types. It can +// almost certainly be done better, in particular using reflection. However, +// that's beside the point of this example. The important part for the +// example is that meta::type::name() yields a string representing the +// type T in some reasonable way +template