Skip to content

Commit

Permalink
Tweak CMake flag passthrough from setup.py, fix macos platform target…
Browse files Browse the repository at this point in the history
… and remove soon-to-be-unnecessary ld_classic flags, fix missing header, fix windows vcpkg initialization in preparation for windows build

Fix FindCSP for math library, remove vestigial path from findcsp_autogen cmake helper
Turn off C++ tests, will do in separate PR

Signed-off-by: Tim Paine <[email protected]>
  • Loading branch information
timkpaine committed Mar 20, 2024
1 parent 47c1c50 commit bbd986f
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 52 deletions.
16 changes: 14 additions & 2 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Team Review
* @robambalu @AdamGlustein @svatasoiu @alexddobkin

.github @robambalu @timkpaine @ngoldbaum @alexddobkin @AdamGlustein @svatasoiu
.github/CODEOWNERS @robambalu
# Packaging code
CMakeLists.txt @robambalu @AdamGlustein @svatasoiu @alexddobkin @timkpaine
setup.py @robambalu @AdamGlustein @svatasoiu @alexddobkin @timkpaine
pyproject.toml @robambalu @AdamGlustein @svatasoiu @alexddobkin @timkpaine
Makefile @robambalu @AdamGlustein @svatasoiu @alexddobkin @timkpaine
MANIFEST.in @robambalu @AdamGlustein @svatasoiu @alexddobkin @timkpaine
.bumpversion.cfg @robambalu @AdamGlustein @svatasoiu @alexddobkin @timkpaine

# CI/CD
.github @robambalu @AdamGlustein @svatasoiu @alexddobkin @timkpaine
ci @robambalu @AdamGlustein @svatasoiu @alexddobkin @timkpaine

# Administrative
.github/CODEOWNERS @robambalu
26 changes: 0 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,35 +115,9 @@ if(MACOS)
set(CMAKE_USE_PTHREADS_INIT 1)
set(THREADS_PREFER_PTHREAD_FLAG ON)

# for exception unwinding on macOS
# TODO this does not work, which would be the
# proper cmake way of doing it, so instead we
# use a vanilla option
# check_linker_flag(CXX "-Wl,-ld_classic" CSP_USE_LD_CLASSIC_MAC)
if(CSP_USE_LD_CLASSIC_MAC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-ld_classic")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-ld_classic")
endif()

set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "Minimum OS X deployment version")

# don't link against build python
# https://blog.tim-smith.us/2015/09/python-extension-modules-os-x/
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")

# Support cross build
check_c_compiler_flag("-arch x86_64" x86_64Supported)
check_c_compiler_flag("-arch arm64" arm64Supported)

if(x86_64Supported AND arm64Supported)
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Build universal architecture for OSX" FORCE)
elseif(x86_64Supported)
set(CMAKE_REQUIRED_LINK_OPTIONS "-arch;x86_64")
set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build universal architecture for OSX" FORCE)
elseif(arm64Supported)
set(CMAKE_REQUIRED_LINK_OPTIONS "-arch;arm64")
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "Build universal architecture for OSX" FORCE)
endif()
endif()


Expand Down
5 changes: 5 additions & 0 deletions cpp/cmake/modules/FindCSP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# CSP_BASELIB_STATIC_LIBRARY
# CSP_BASKETLIB_LIBRARY
# CSP_BASKETLIB_STATIC_LIBRARY
# CSP_MATH_LIBRARY
# CSP_MATH_STATIC_LIBRARY
# CSP_STATS_LIBRARY
# CSP_STATS_STATIC_LIBRARY
# CSP_NPSTATS_LIBRARY
Expand Down Expand Up @@ -72,6 +74,9 @@ find_library(CSP_BASELIB_STATIC_LIBRARY NAMES libbaselibimpl_static.a PATHS "${_
find_library(CSP_BASKETLIB_LIBRARY NAMES _cspbasketlibimpl.so PATHS "${__csp_lib_path}" NO_DEFAULT_PATH)
find_library(CSP_BASKETLIB_STATIC_LIBRARY NAMES libbasketlibimpl_static.a PATHS "${__csp_lib_path}" NO_DEFAULT_PATH)

find_library(CSP_MATH_LIBRARY NAMES _cspmathimpl.so PATHS "${__csp_lib_path}" NO_DEFAULT_PATH)
find_library(CSP_MATH_STATIC_LIBRARY NAMES libmathimpl_static.a PATHS "${__csp_lib_path}" NO_DEFAULT_PATH)

find_library(CSP_STATS_LIBRARY NAMES _cspstatsimpl.so PATHS "${__csp_lib_path}" NO_DEFAULT_PATH)
find_library(CSP_STATS_STATIC_LIBRARY NAMES libstatsimpl_static.a PATHS "${__csp_lib_path}" NO_DEFAULT_PATH)

Expand Down
2 changes: 1 addition & 1 deletion cpp/cmake/modules/Findcsp_autogen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function(csp_autogen MODULE_NAME DEST_FILENAME HEADER_NAME_OUTVAR SOURCE_NAME_OU
endif()

add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/csp_autogen/${DEST_FILENAME}.cpp" "${CMAKE_CURRENT_BINARY_DIR}/csp_autogen/${DEST_FILENAME}.h"
COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${PROJECT_BINARY_DIR}/lib:${CMAKE_SOURCE_DIR}:ext:$$PYTHONPATH" "LD_LIBRARY_PATH=${PROJECT_BINARY_DIR}/lib:$$LD_LIBRARY_PATH}" ${Python_EXECUTABLE} ${CSP_AUTOGEN} -m ${MODULE_NAME} -d ${CMAKE_CURRENT_BINARY_DIR}/csp_autogen -o ${DEST_FILENAME} ${CSP_AUTOGEN_EXTRA_ARGS}
COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${PROJECT_BINARY_DIR}/lib:${CMAKE_SOURCE_DIR}:$$PYTHONPATH" "LD_LIBRARY_PATH=${PROJECT_BINARY_DIR}/lib:$$LD_LIBRARY_PATH}" ${Python_EXECUTABLE} ${CSP_AUTOGEN} -m ${MODULE_NAME} -d ${CMAKE_CURRENT_BINARY_DIR}/csp_autogen -o ${DEST_FILENAME} ${CSP_AUTOGEN_EXTRA_ARGS}
COMMENT "generating csp c++ types from module ${MODULE_NAME} ${PROJECT_BINARY_DIR} ${CSP_AUTOGEN}"
DEPENDS mkdir_autogen_${MODULE_NAME} ${CMAKE_SOURCE_DIR}/${MODULE_FILENAME})

Expand Down
21 changes: 11 additions & 10 deletions cpp/csp/engine/Scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cassert>
#include <functional>
#include <map>
#include <unordered_map>
#include <unordered_set>

namespace csp
Expand All @@ -18,9 +19,9 @@ class Scheduler
struct Event;

public:
//For non-collapsing inputs, the callback should return a pointer to the input adapter that is
//For non-collapsing inputs, the callback should return a pointer to the input adapter that is
//unrolling / not collapsing. This will ensure pending events for a given input adapter will get deferred
//to the next cycle until its completely unrolled. This avoids a O(n^2) loop of reprocessing multiple pending events on
//to the next cycle until its completely unrolled. This avoids a O(n^2) loop of reprocessing multiple pending events on
//a given input adapter. If the callback isnt for an input adapter or if it is able to consume / process the tick, return nullptr
using Callback = std::function<const InputAdapter *()>;

Expand All @@ -31,13 +32,13 @@ class Scheduler
Handle( const Handle & rhs ) = default;
bool expired() const;
bool active() const { return !expired(); }

operator bool() const { return active(); }

//Only valid if handle is active, otherwise returns NONE
DateTime time() const;

void reset()
void reset()
{
event = nullptr;
id = 0;
Expand Down Expand Up @@ -70,17 +71,17 @@ class Scheduler
};

Scheduler();
~Scheduler();
~Scheduler();

//Callback can return false which means it should stick around
//Callback can return false which means it should stick around
//and re-execute next engine cycle
Handle scheduleCallback( Handle reserved, DateTime time, Callback &&cb );
Handle scheduleCallback( DateTime time, Callback &&cb );
Handle rescheduleCallback( Handle handle, DateTime time );
bool cancelCallback( Handle handle );

//useful to break circular dep of a callback needing its own handle
Handle reserveHandle();
Handle reserveHandle();

bool hasEvents() { return !m_map.empty() || m_pendingEvents.hasEvents(); }
DateTime nextTime() const { return m_pendingEvents.hasEvents() ? m_pendingEvents.time() : m_map.begin() -> first; }
Expand All @@ -104,7 +105,7 @@ class Scheduler
return m_allocator.allocate();
}

void deallocate( T* p, std::size_t n ) noexcept
void deallocate( T* p, std::size_t n ) noexcept
{
assert( n == 1 );
m_allocator.free( p );
Expand Down Expand Up @@ -160,7 +161,7 @@ class Scheduler

private:
//NOTE the reason that this isnt simply kept as an unordered_map<InputAdapter*,Event> list is to ensure
//simulated runs have complete reproducibility and are deterministic. If we key by InputAdapter * pointer, ordering of
//simulated runs have complete reproducibility and are deterministic. If we key by InputAdapter * pointer, ordering of
//invocations will vary across runs ( this generally wouldnt matter if all code was side-effect free, but even so basket input
//tickeditems() order depends on order of basket elemnt ticks in a given cycle )
//Instead we maintain an unordered_map<InputAdapter*, list iterator> to ensure we keep an adapter once in the m_pendingEvents list
Expand All @@ -177,7 +178,7 @@ class Scheduler
};

//time of all pending events
DateTime m_time;
DateTime m_time;

//Every list entry is *PER ADAPTER*, each entry will have a linked list of Event objects
std::list<PendingEventList> m_pendingEvents;
Expand Down
4 changes: 2 additions & 2 deletions cpp/tests/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ target_link_libraries(test_time csp_core GTest::gtest GTest::gtest_main rt)
install(TARGETS test_basic_allocator
test_dynamicbitset
test_enum
test_srmwlockfreequeue
test_tagged_pointer_union
test_srmwlockfreequeue
test_tagged_pointer_union
test_time
RUNTIME DESTINATION tests/bin/
LIBRARY DESTINATION tests/lib/
Expand Down
53 changes: 42 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@
from shutil import which
from skbuild import setup

CSP_USE_VCPKG = os.environ.get("CSP_USE_VCPKG", "1") == "1"
# CMake Options
CSP_USE_VCPKG = os.environ.get("CSP_USE_VCPKG", "1").lower() in ("1", "on")
CMAKE_OPTIONS = (
("CSP_BUILD_NO_CXX_ABI", "0"),
("CSP_BUILD_TESTS", "0"),
("CSP_MANYLINUX", "0"),
("CSP_BUILD_KAFKA_ADAPTER", "1"),
("CSP_BUILD_PARQUET_ADAPTER", "1"),
# NOTE:
# - omit vcpkg, need to test for presence
# - omit ccache, need to test for presence
# - omit coverage/gprof, not implemented
)

# This will be used for e.g. the sdist
if CSP_USE_VCPKG:
Expand All @@ -18,8 +30,8 @@
if not os.path.exists("vcpkg/buildtrees"):
subprocess.call(["git", "pull"], cwd="vcpkg")
if os.name == "nt":
subprocess.call(["bootstrap-vcpkg.bat"], cwd="vcpkg")
subprocess.call(["vcpkg", "install"], cwd="vcpkg")
subprocess.call(["bootstrap-vcpkg.bat"], cwd="vcpkg", shell=True)
subprocess.call(["vcpkg.bat", "install"], cwd="vcpkg", shell=True)
else:
subprocess.call(["./bootstrap-vcpkg.sh"], cwd="vcpkg")
subprocess.call(["./vcpkg", "install"], cwd="vcpkg")
Expand Down Expand Up @@ -50,20 +62,39 @@
if "DEBUG" in os.environ:
cmake_args.append("-DCMAKE_BUILD_TYPE=Debug")

if "CSP_MANYLINUX" in os.environ:
cmake_args.append("-DCSP_MANYLINUX=ON")
if platform.system() == "Windows":
import distutils.msvccompiler as dm

# https://wiki.python.org/moin/WindowsCompilers#Microsoft_Visual_C.2B-.2B-_14.0_with_Visual_Studio_2015_.28x86.2C_x64.2C_ARM.29
msvc = {
"12": "Visual Studio 12 2013",
"14": "Visual Studio 14 2015",
"14.0": "Visual Studio 14 2015",
"14.1": "Visual Studio 15 2017",
"14.2": "Visual Studio 16 2019",
"14.3": "Visual Studio 17 2022",
}.get(str(dm.get_build_version()), "Visual Studio 15 2017")
cmake_args.extend(
[
"-G",
os.environ.get("CSP_GENERATOR", msvc),
]
)

for cmake_option, default in CMAKE_OPTIONS:
if os.environ.get(cmake_option, default).lower() in ("1", "on"):
cmake_args.append(f"-D{cmake_option}=ON")
else:
cmake_args.append(f"-D{cmake_option}=OFF")

if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
os.environ["CMAKE_BUILD_PARALLEL_LEVEL"] = str(multiprocessing.cpu_count())

if platform.system() == "Darwin":
os.environ["OSX_DEPLOYMENT_TARGET"] = os.environ.get("OSX_DEPLOYMENT_TARGET", "10.13")
os.environ["MACOSX_DEPLOYMENT_TARGET"] = os.environ.get("OSX_DEPLOYMENT_TARGET", "10.13")

if hasattr(platform, "mac_ver") and platform.mac_ver()[0].startswith("14"):
cmake_args.append("-DCSP_USE_LD_CLASSIC_MAC=ON")
os.environ["MACOSX_DEPLOYMENT_TARGET"] = os.environ.get("OSX_DEPLOYMENT_TARGET", "10.15")
cmake_args.append(f'-DCMAKE_OSX_DEPLOYMENT_TARGET={os.environ.get("OSX_DEPLOYMENT_TARGET", "10.15")}')

if which("ccache"):
if which("ccache") and os.environ.get("CSP_USE_CCACHE", "") != "0":
cmake_args.append("-DCSP_USE_CCACHE=On")

print(f"CMake Args: {cmake_args}")
Expand Down

0 comments on commit bbd986f

Please sign in to comment.