Skip to content

Commit

Permalink
(#25388) boost v1.86.0: add process library
Browse files Browse the repository at this point in the history
* Build boost::process::v2 lib for v1.86.0

See changelog:
https://www.boost.org/users/history/version_1_86_0.html

* Add test for boost::process

* Whoops

* Debugging

* Correctly populate system_libs when without_process=False

See boostorg/process@8b3e902#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20aR60

* Remove assertion in test code

* Add defines for boost process

* Debugging

* Add patch for boost 1.86.0 - fix process dll import

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Use BOOST_PROCESS_DYN_LINK instead of private BOOST_PROCESS_SOURCE

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Revert "Add patch for boost 1.86.0 - fix process dll import"

This reverts commit dc05670.

* Disable process on Windows only for 1.86.0

Signed-off-by: Uilian Ries <uilianries@gmail.com>

---------

Signed-off-by: Uilian Ries <uilianries@gmail.com>
Co-authored-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
robomics and uilianries authored Oct 5, 2024
1 parent 6b0eb2c commit 9ad1e51
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 5 deletions.
19 changes: 19 additions & 0 deletions recipes/boost/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"math",
"mpi",
"nowide",
"process",
"program_options",
"python",
"random",
Expand Down Expand Up @@ -588,6 +589,13 @@ def disable_cobalt():
elif not self._has_cppstd_14_supported:
disable_graph()

# TODO: Revisit on Boost 1.87.0
# It's not possible to disable process only when having shared parsed already.
# https://github.com/boostorg/process/issues/408
# https://github.com/boostorg/process/pull/409
if Version(self.version) == "1.86.0" and is_msvc(self):
setattr(self.options, "without_process", True)

@property
def _configure_options(self):
return self._dependencies["configure_options"]
Expand Down Expand Up @@ -757,6 +765,10 @@ def validate(self):
raise ConanInvalidConfiguration("Boost.Cobalt requires a C++20 capable compiler. "
"Please, set compiler.cppstd and use a newer compiler version, or disable from building.")

# TODO: Revisit on Boost 1.87.0. Remove in case Process is fixed.
if Version(self.version) == "1.86.0" and is_msvc(self) and self.options.get_safe("shared") and self.options.get_safe("without_process", None) == False:
raise ConanInvalidConfiguration(f"{self.ref} Boost.Process will fail to be consumed as shared library on MSVC. See https://github.com/boostorg/process/issues/408.")

def _with_dependency(self, dependency):
"""
Return true when dependency is required according to the dependencies-x.y.z.yml file
Expand Down Expand Up @@ -2034,6 +2046,13 @@ def filter_transform_module_libraries(names):

self.cpp_info.components[f"numpy{pyversion.major}{pyversion.minor}"].requires = ["numpy"]

if not self.options.get_safe("without_process"):
if self.settings.os == "Windows":
self.cpp_info.components["process"].system_libs.extend(["ntdll", "shell32", "Advapi32", "user32"])
if self._shared:
self.cpp_info.components["process"].defines.append("BOOST_PROCESS_DYN_LINK")


if is_msvc(self) or self._is_clang_cl:
# https://github.com/conan-community/conan-boost/issues/127#issuecomment-404750974
self.cpp_info.components["_libboost"].system_libs.append("bcrypt")
Expand Down
11 changes: 9 additions & 2 deletions recipes/boost/all/dependencies/dependencies-1.86.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ configure_options:
- math
- mpi
- nowide
- process
- program_options
- python
- random
Expand All @@ -40,6 +41,7 @@ dependencies:
- system
cobalt:
- container
- context
- system
container: []
context: []
Expand Down Expand Up @@ -115,6 +117,9 @@ dependencies:
- python
prg_exec_monitor:
- test
process:
- filesystem
- system
program_options: []
python: []
random:
Expand All @@ -128,14 +133,14 @@ dependencies:
- stacktrace
stacktrace_basic:
- stacktrace
stacktrace_from_exception:
- stacktrace
stacktrace_noop:
- stacktrace
stacktrace_windbg:
- stacktrace
stacktrace_windbg_cached:
- stacktrace
stacktrace_from_exception:
- stacktrace
system: []
test:
- exception
Expand Down Expand Up @@ -226,6 +231,8 @@ libs:
- boost_numpy{py_major}{py_minor}
prg_exec_monitor:
- boost_prg_exec_monitor
process:
- boost_process
program_options:
- boost_program_options
python:
Expand Down
1 change: 1 addition & 0 deletions recipes/boost/all/rebuild-dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"math",
"mpi",
"nowide",
"process",
"program_options",
"python",
"random",
Expand Down
8 changes: 8 additions & 0 deletions recipes/boost/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ if(NOT HEADER_ONLY)
endif()
endif()

if (WITH_PROCESS)
find_package(Boost COMPONENTS process REQUIRED)
add_executable(process_exe process.cpp)
target_link_libraries(process_exe PRIVATE Boost::process)
set_property(TARGET process_exe PROPERTY CXX_STANDARD 11)
add_test(NAME boost_process COMMAND process_exe)
endif()

if(WITH_PYTHON)
find_package(Boost COMPONENTS python REQUIRED)
add_library(hello_ext MODULE python.cpp)
Expand Down
7 changes: 4 additions & 3 deletions recipes/boost/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def generate(self):
tc.cache_variables["WITH_LOCALE"] = not self.dependencies["boost"].options.without_locale
tc.cache_variables["WITH_NOWIDE"] = not self._boost_option("without_nowide", True)
tc.cache_variables["WITH_JSON"] = not self._boost_option("without_json", True)
tc.cache_variables["WITH_PROCESS"] = not self._boost_option("without_process", True)
tc.cache_variables["WITH_STACKTRACE"] = not self.dependencies["boost"].options.without_stacktrace
tc.cache_variables["WITH_STACKTRACE_ADDR2LINE"] = self.dependencies["boost"].conf_info.get("user.boost:stacktrace_addr2line_available")
tc.cache_variables["WITH_STACKTRACE_BACKTRACE"] = self._boost_option("with_stacktrace_backtrace", False)
Expand All @@ -59,12 +60,12 @@ def test(self):
return
with chdir(self, self.folders.build_folder):
# When boost and its dependencies are built as shared libraries,
# the test executables need to locate them. Typically the
# the test executables need to locate them. Typically the
# `conanrun` env should be enough, but this may cause problems on macOS
# where the CMake installation has dependencies on Apple-provided
# system libraries that are incompatible with Conan-provided ones.
# system libraries that are incompatible with Conan-provided ones.
# When `conanrun` is enabled, DYLD_LIBRARY_PATH will also apply
# to ctest itself. Given that CMake already embeds RPATHs by default,
# to ctest itself. Given that CMake already embeds RPATHs by default,
# we can bypass this by using the `conanbuild` environment on
# non-Windows platforms, while still retaining the correct behaviour.
env = "conanrun" if self.settings.os == "Windows" else "conanbuild"
Expand Down
44 changes: 44 additions & 0 deletions recipes/boost/all/test_package/process.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2022 Klemens Morgenstern
//
// 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)

// This comes from the following Boost example:
// https://github.com/boostorg/process/blob/boost-1.86.0/example/v2/intro.cpp

// clang-format: off
#include <boost/asio/read.hpp>
#include <boost/asio/readable_pipe.hpp>
// clang-format: on

#include <boost/process/v2.hpp>
#include <boost/system/error_code.hpp>

#include <string>
#include <iostream>

#if defined(BOOST_NAMESPACE)
namespace boost = BOOST_NAMESPACE;
#endif

namespace proc = boost::process::v2;
namespace asio = boost::asio;

int main()
{
asio::io_context ctx;
asio::readable_pipe p{ctx};

const auto exe = proc::environment::find_executable("cmake");

proc::process c{ctx, exe, {"--version"}, proc::process_stdio{nullptr, p}};

std::string line;
boost::system::error_code ec;

auto sz = asio::read(p, asio::dynamic_buffer(line), ec);

std::cout << "CMake version: '" << line << "'" << std::endl;

c.wait();
}

0 comments on commit 9ad1e51

Please sign in to comment.