Skip to content

Commit

Permalink
non-boost build fixes (#756)
Browse files Browse the repository at this point in the history
* Time.cpp: include <cmath>

Time.cpp uses `std::round` from <cmath>. When SLANG_USE_BOOST is on,
cmath is pulled in somehow from a transitive include. When
SLANG_USE_BOOST is off, at least on some systems, this include
is not pulled in.

Include <cmath> explicitly in Time.cpp to ensure `std::round` is
available, including for certain non-boost-using builds.

* pyslang.h: guard type_casters for flat_hash_map based on SLANG_USE_BOOST

include/slang/util/Hash.h defines the alias templates `flat_hash_map`
and `flat_hash_set` based on the macro SLANG_USE_BOOST. If the macro
is defined, these aliases refer to boost class templates. If the macro
is not defined, they reference standard class templates.

Pybind11 v2.10.4 defines type_casters for `std::unordered_map` and
`std::unordered_set` in include/pybind11/stl.h on lines
302-304 and 294-296, respectively.

As pyslang.h includes <pybind11/stl.h>, avoid multiple definitions
of these type casters by guarding their definitions in pyslang.h
based on the SLANG_USE_BOOST macro.
  • Loading branch information
tdp2110 committed May 19, 2023
1 parent d27d9ac commit 043c177
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bindings/python/pyslang.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ struct type_caster<std::span<T>> {
std::span<T> value;
};

#ifdef SLANG_USE_BOOST
// Convert between flat_hash_map and python dict.
template<typename Key, typename Value, typename Hash, typename Equal, typename Alloc>
struct type_caster<flat_hash_map<Key, Value, Hash, Equal, Alloc>>
Expand All @@ -176,6 +177,7 @@ struct type_caster<flat_hash_map<Key, Value, Hash, Equal, Alloc>>
template<typename Key, typename Hash, typename Equal, typename Alloc>
struct type_caster<flat_hash_set<Key, Hash, Equal, Alloc>>
: set_caster<flat_hash_set<Key, Hash, Equal, Alloc>, Key> {};
#endif

template<typename type>
class type_caster<not_null<type>> {
Expand Down
1 change: 1 addition & 0 deletions source/numeric/Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//------------------------------------------------------------------------------
#include "slang/numeric/Time.h"

#include <cmath>
#include <fmt/core.h>
#include <ostream>

Expand Down

0 comments on commit 043c177

Please sign in to comment.