Skip to content

Commit

Permalink
feat(C++): Enable Windows C++ CI and fix some compilation errors
Browse files Browse the repository at this point in the history
Signed-off-by: LiangliangSui <coolsui.coding@gmail.com>
  • Loading branch information
LiangliangSui committed Jan 10, 2024
1 parent 18527e3 commit 1138798
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ jobs:
name: C++ CI
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-latest, windows-2022]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down
5 changes: 4 additions & 1 deletion bazel/arrow/BUILD.tpl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cc_library(
name = "arrow",
hdrs = [":arrow_header_include"],
includes = ["include"],
deps = [":arrow_shared_library"],
deps = [%{ARROW_DEPS}],
visibility = ["//visibility:public"],
)

Expand Down Expand Up @@ -35,7 +35,10 @@ cc_library(
includes=["python_numpy_include"],
)

%{IMPORT_STATIC_LIBRARY}

%{ARROW_HEADER_GENRULE}
%{ARROW_LIBRARY_GENRULE}
%{ARROW_STATIC_LIBRARY_GENRULE}
%{ARROW_PYTHON_LIBRARY_GENRULE}
%{PYTHON_NUMPY_INCLUDE_GENRULE}
54 changes: 51 additions & 3 deletions bazel/arrow/pyarrow_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ def _symlink_genrule_for_dir(
cmd = "cp -f"
command.append(cmd + ' "%s" "%s"' % (src_files[i], dest))
outs.append(' "' + dest_dir + dest_files[i] + '",')

if _is_windows(repository_ctx):
command = [cmd.replace("\\", "\\\\") for cmd in command]
outs = [out.replace("\\", "\\\\") for out in outs]

genrule = _genrule(
genrule_name,
" && ".join(command),
Expand All @@ -177,7 +182,20 @@ def _get_pyarrow_include(repository_ctx, python_bin="python3"):
def _get_pyarrow_shared_library(repository_ctx, library_name, python_bin="python3"):
"""Gets the pyarrow shared library path."""
code = """import pyarrow, os, glob;print(glob.glob(os.path.join(""" +\
"""os.path.dirname(pyarrow.__file__), 'lib{}.*'))[0])""".format(library_name)
"""os.path.dirname(pyarrow.__file__), '*{}.*'))[0])""".format(library_name)
result = _execute(
repository_ctx, [
python_bin, "-c", code
],
error_msg="Problem getting pyarrow shared library path.",
error_details=(
"Is the Python binary path set up right? " + "(See ./configure or "
+ python_bin + ".) " + "Is distutils installed?"))
return result.stdout.splitlines()[0]

def _get_pyarrow_static_library_for_windows(repository_ctx, library_name, python_bin="python3"):
code = """import pyarrow, os, glob;print(glob.glob(os.path.join(""" +\
"""os.path.dirname(pyarrow.__file__), '{}.lib'))[0])""".format(library_name)
result = _execute(
repository_ctx, [
python_bin, "-c", code
Expand All @@ -201,6 +219,24 @@ def _get_python_numpy_include(repository_ctx, python_bin="python3"):
+ python_bin + ".) " + "Is distutils installed?"))
return result.stdout.splitlines()[0]

def _get_import_static_library(repository_ctx):
import_lib = ""
if _is_windows(repository_ctx):
import_lib = """cc_import(
name = \"arrow_static_library\",
static_library = \":libarrow_static\",
visibility = [\"//visibility:public\"]
)"""
return import_lib

def _get_arrow_deps(repository_ctx):
if _is_windows(repository_ctx):
deps = "\":arrow_shared_library\", \"arrow_static_library\""
else:
deps = "\":arrow_shared_library\""

return deps

def _pyarrow_pip_impl(repository_ctx):
arrow_header_dir = _get_pyarrow_include(repository_ctx)
arrow_header_rule = _symlink_genrule_for_dir(
Expand All @@ -210,13 +246,22 @@ def _pyarrow_pip_impl(repository_ctx):
"arrow_header_include",
)

split_letter = "\\" if _is_windows(repository_ctx) else "/"
arrow_library_path = _get_pyarrow_shared_library(repository_ctx, "arrow")
arrow_library = arrow_library_path.rsplit("/",1 )[-1]
arrow_library = arrow_library_path.rsplit(split_letter, 1)[-1]
arrow_library_rule = _symlink_genrule_for_dir(
repository_ctx, None, "", "libarrow", [arrow_library_path], [arrow_library])

if _is_windows(repository_ctx):
arrow_static_library_path = _get_pyarrow_static_library_for_windows(repository_ctx, "arrow")
arrow_static_library = arrow_static_library_path.rsplit(split_letter, 1)[-1]
arrow_static_library_rule = _symlink_genrule_for_dir(
repository_ctx, None, "", "libarrow_static", [arrow_static_library_path], [arrow_static_library])
else:
arrow_static_library_rule = ""

arrow_python_library_path = _get_pyarrow_shared_library(repository_ctx, "arrow_python")
arrow_python_library = arrow_python_library_path.rsplit("/",1 )[-1]
arrow_python_library = arrow_python_library_path.rsplit(split_letter, 1)[-1]
arrow_python_library_rule = _symlink_genrule_for_dir(
repository_ctx, None, "", "libarrow_python",
[arrow_python_library_path], [arrow_python_library])
Expand All @@ -227,8 +272,11 @@ def _pyarrow_pip_impl(repository_ctx):

build_tpl = repository_ctx.path(Label("//bazel/arrow:BUILD.tpl.bzl"))
repository_ctx.template("BUILD", build_tpl, {
"%{ARROW_DEPS}": _get_arrow_deps(repository_ctx),
"%{IMPORT_STATIC_LIBRARY}": _get_import_static_library(repository_ctx),
"%{ARROW_HEADER_GENRULE}": arrow_header_rule,
"%{ARROW_LIBRARY_GENRULE}": arrow_library_rule,
"%{ARROW_STATIC_LIBRARY_GENRULE}": arrow_static_library_rule,
"%{ARROW_PYTHON_LIBRARY_GENRULE}": arrow_python_library_rule,
"%{PYTHON_NUMPY_INCLUDE_GENRULE}": python_numpy_include_rule,
})
Expand Down
4 changes: 3 additions & 1 deletion src/fury/encoder/row_encode_trait.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* under the License.
*/

#pragma once
#ifndef __ROW_ENCODER_TRAIT_HEADER
#define __ROW_ENCODER_TRAIT_HEADER

#include "fury/meta/field_info.h"
#include "fury/meta/type_traits.h"
Expand Down Expand Up @@ -342,3 +343,4 @@ struct RowEncodeTrait<T,
} // namespace encoder

} // namespace fury
#endif
4 changes: 3 additions & 1 deletion src/fury/encoder/row_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* under the License.
*/

#pragma once
#ifndef __ROW_ENCODER_HEADER
#define __ROW_ENCODER_HEADER

#include "fury/encoder/row_encode_trait.h"
#include "src/fury/row/writer.h"
Expand Down Expand Up @@ -112,3 +113,4 @@ template <typename T> struct RowEncoder {
} // namespace encoder

} // namespace fury
#endif
24 changes: 22 additions & 2 deletions src/fury/meta/field_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ template <typename FieldInfo> constexpr bool IsValidFieldInfo() {

} // namespace fury

#define FURY_FIELD_INFO_NAMES_FUNC(field) #field,
#define FURY_FIELD_INFO_PTRS_FUNC(type, field) &type::field,
#define FURY_FIELD_INFO_NAMES_FUNC(field) #field
#define FURY_FIELD_INFO_PTRS_FUNC(type, field) &type::field

// here we define function overloads in the current namespace rather than
// template specialization of classes since specialization of template in
// different namespace is hard
// NOTE: for performing ADL (argument-dependent lookup),
// `FURY_FIELD_INFO(T, ...)` must be defined in the same namespace as `T`
#ifndef _WIN32
#define FURY_FIELD_INFO(type, ...) \
static_assert(std::is_class_v<type>, "it must be a class type"); \
template <typename> struct FuryFieldInfoImpl; \
Expand All @@ -85,3 +86,22 @@ template <typename FieldInfo> constexpr bool IsValidFieldInfo() {
inline constexpr auto FuryFieldInfo(const type &) noexcept { \
return FuryFieldInfoImpl<type>{}; \
};
#else
#define FURY_FIELD_INFO(type, ...) \
static_assert(std::is_class_v<type>, "it must be a class type"); \
template <typename> struct FuryFieldInfoImpl; \
template <> struct FuryFieldInfoImpl<type> { \
static inline constexpr size_t Size = FURY_PP_NARG(__VA_ARGS__); \
static inline constexpr std::string_view Name = #type; \
static inline constexpr std::array<std::string_view, Size> Names = { \
EXTEND(FURY_PP_FOREACH(FURY_FIELD_INFO_NAMES_FUNC, __VA_ARGS__))}; \
static inline constexpr auto Ptrs = std::tuple{EXTEND( \
FURY_PP_FOREACH_1(FURY_FIELD_INFO_PTRS_FUNC, type, __VA_ARGS__))}; \
}; \
static_assert( \
fury::meta::IsValidFieldInfo<FuryFieldInfoImpl<type>>(), \
"duplicated fields in FURY_FIELD_INFO arguments are detected"); \
inline constexpr auto FuryFieldInfo(const type &) noexcept { \
return FuryFieldInfoImpl<type>{}; \
};
#endif
Loading

0 comments on commit 1138798

Please sign in to comment.