Skip to content

Commit fcd620d

Browse files
committed
GH-47921: [C++] Implement substrait option in Meson
1 parent 430ad81 commit fcd620d

File tree

8 files changed

+272
-21
lines changed

8 files changed

+272
-21
lines changed

cpp/meson.build

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ endif
5353

5454
needs_benchmarks = get_option('benchmarks').enabled()
5555
needs_csv = get_option('csv').enabled()
56-
needs_dataset = get_option('dataset').enabled()
56+
needs_substrait = get_option('substrait').enabled()
57+
needs_dataset = get_option('dataset').enabled() or needs_substrait
5758
needs_azure = get_option('azure').enabled()
5859
needs_gcs = get_option('gcs').enabled()
5960
needs_hdfs = get_option('hdfs').enabled()
6061
needs_opentelemetry = false
6162
needs_orc = false
62-
needs_parquet = get_option('parquet').enabled()
63+
needs_parquet = get_option('parquet').enabled() or needs_substrait
6364
needs_parquet_encryption = get_option('parquet_require_encryption').enabled()
6465
needs_s3 = get_option('s3').enabled()
6566
needs_filesystem = (get_option('filesystem').enabled()
@@ -82,6 +83,7 @@ needs_ipc = (get_option('ipc').enabled()
8283
or needs_benchmarks
8384
or needs_flight
8485
or needs_parquet
86+
or needs_substrait
8587
)
8688

8789
needs_fuzzing = get_option('fuzzing').enabled()
@@ -109,6 +111,29 @@ needs_zlib = get_option('zlib').enabled()
109111
needs_zstd = get_option('zstd').enabled()
110112
needs_utilities = get_option('utilities').enabled()
111113

114+
if needs_flight or needs_substrait
115+
protobuf_dep = dependency('protobuf')
116+
protoc = find_program('protoc')
117+
118+
# To ensure messages from proto files are created correctly, we need to
119+
# pass in dllexport_decl=<...> . Unfortunately, it doesn't appear that we
120+
# can just pass in dllexport_decl=XXX_EXPORT, as the visibility
121+
# macro won't be easily available to the generated proto file. See also
122+
# https://github.com/protocolbuffers/protobuf/issues/19422
123+
if meson.get_compiler('cpp').get_id() == 'msvc'
124+
if get_option('default_library') != 'static'
125+
proto_visibility = 'dllexport_decl=__declspec(dllexport):'
126+
else
127+
proto_visibility = ''
128+
endif
129+
else
130+
proto_visibility = 'dllexport_decl=__attribute__((visibility("default"))):'
131+
endif
132+
else
133+
protobuf_dep = disabler()
134+
protoc = disabler()
135+
endif
136+
112137
subdir('src/arrow')
113138

114139
if needs_parquet
@@ -126,3 +151,7 @@ if needs_dataset
126151
# with a circular dependency
127152
subdir('src/arrow/dataset')
128153
endif
154+
155+
if needs_substrait
156+
subdir('src/arrow/engine')
157+
endif

cpp/meson.options

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ option(
112112
)
113113

114114
option('snappy', type: 'feature', description: 'Build with snappy compression')
115+
option(
116+
'substrait',
117+
type: 'feature',
118+
description: 'Build the Arrow Substrait Consumer Module',
119+
)
115120
option(
116121
's3',
117122
type: 'feature',

cpp/src/arrow/engine/meson.build

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
install_headers(['api.h'], subdir: 'arrow/engine')
19+
20+
arrow_substrait_protos_dir = meson.project_source_root() / 'proto'
21+
substrait_proto_gen = generator(
22+
protoc,
23+
output: ['@BASENAME@.pb.cc', '@BASENAME@.pb.h'],
24+
arguments: [
25+
'--proto_path=@0@'.format(
26+
subproject('substrait').get_variable('substrait_protos_dir'),
27+
),
28+
'--proto_path=@0@'.format(arrow_substrait_protos_dir),
29+
'--cpp_out=@0@@1@'.format(proto_visibility, '@BUILD_DIR@'),
30+
'@INPUT@',
31+
],
32+
)
33+
ext_proto_gen = substrait_proto_gen.process(
34+
meson.project_source_root() / 'proto' / 'substrait' / 'extension_rels.proto',
35+
preserve_path_from: meson.project_source_root() / 'proto',
36+
)
37+
substrait_ext_dep = declare_dependency(sources: ext_proto_gen)
38+
39+
substrait_dep = dependency('substrait')
40+
arrow_substrait_srcs = files(
41+
'substrait/expression_internal.cc',
42+
'substrait/extended_expression_internal.cc',
43+
'substrait/extension_set.cc',
44+
'substrait/extension_types.cc',
45+
'substrait/options.cc',
46+
'substrait/plan_internal.cc',
47+
'substrait/relation_internal.cc',
48+
'substrait/serde.cc',
49+
'substrait/test_plan_builder.cc',
50+
'substrait/type_internal.cc',
51+
'substrait/util.cc',
52+
'substrait/util_internal.cc',
53+
)
54+
arrow_substrait_deps = [
55+
substrait_dep,
56+
substrait_ext_dep,
57+
arrow_dataset_dep,
58+
protobuf_dep,
59+
]
60+
arrow_substrait_pkgconf_req = ['arrow-dataset']
61+
62+
arrow_substrait_lib = library(
63+
'arrow_substrait',
64+
sources: arrow_substrait_srcs,
65+
dependencies: arrow_substrait_deps,
66+
cpp_static_args: ['-DARROW_ENGINE_STATIC'],
67+
cpp_shared_args: ['-DARROW_ENGINE_EXPORTING'],
68+
gnu_symbol_visibility: 'inlineshidden',
69+
)
70+
71+
arrow_substrait_args = []
72+
if get_option('default_library') == 'static'
73+
arrow_substrait_args += ['-DARROW_ENGINE_STATIC']
74+
endif
75+
arrow_substrait_dep = declare_dependency(
76+
link_with: arrow_substrait_lib,
77+
dependencies: arrow_substrait_deps,
78+
compile_args: arrow_substrait_args,
79+
)
80+
meson.override_dependency('arrow-substrait', arrow_substrait_dep)
81+
82+
pkg_config_cflags = get_option('default_library') == 'static' ? '-DARROW_ENGINE_STATIC' : ''
83+
pkg.generate(
84+
arrow_substrait_lib,
85+
filebase: 'arrow-substrait',
86+
name: 'Apache Arrow Substrait Consumer',
87+
description: 'Apache Arrow\'s Substrait Consumer.',
88+
extra_cflags: [pkg_config_cflags],
89+
requires: arrow_substrait_pkgconf_req,
90+
variables: {'Cflags.private': '-DARROW_ENGINE_STATIC'},
91+
)
92+
93+
arrow_substrait_test = executable(
94+
'substrait-test',
95+
sources: files(
96+
'substrait/ext_test.cc',
97+
'substrait/function_test.cc',
98+
'substrait/protobuf_test_util.cc',
99+
'substrait/serde_test.cc',
100+
'substrait/test_util.cc',
101+
),
102+
dependencies: [arrow_substrait_dep, arrow_compute_test_dep],
103+
)
104+
test('substrait-test', arrow_substrait_test)
105+
106+
subdir('substrait')
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
install_headers(
19+
[
20+
'api.h',
21+
'extension_set.h',
22+
'extension_types.h',
23+
'options.h',
24+
'relation.h',
25+
'serde.h',
26+
'test_plan_builder.h',
27+
'test_util.h',
28+
'type_fwd.h',
29+
'util.h',
30+
'visibility.h',
31+
],
32+
subdir: 'arrow/engine/substrait',
33+
)
34+

cpp/src/arrow/flight/meson.build

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,11 @@ install_headers(
4545
)
4646

4747
grpc_dep = dependency('grpc++')
48-
protobuf_dep = dependency('protobuf')
4948
abseil_sync_dep = dependency('absl_synchronization')
5049

5150
fs = import('fs')
52-
protoc = find_program('protoc')
5351

5452
flight_proto_path = fs.parent(meson.project_source_root()) / 'format'
55-
56-
# To ensure messages from proto files are created correctly, we need to
57-
# pass in dllexport_decl=<...> . Unfortunately, it doesn't appear that we
58-
# can just pass in dllexport_decl=ARROW_FLIGHT_EXPORT, as the visibility
59-
# macro won't be easily available to the generated proto file. See also
60-
# https://github.com/protocolbuffers/protobuf/issues/19422
61-
if cpp_compiler.get_id() == 'msvc'
62-
if get_option('default_library') != 'static'
63-
proto_visibility = 'dllexport_decl=__declspec(dllexport):'
64-
else
65-
proto_visibility = ''
66-
endif
67-
else
68-
proto_visibility = 'dllexport_decl=__attribute__((visibility("default"))):'
69-
endif
70-
7153
flight_proto_files = custom_target(
7254
'arrow-flight-proto-files',
7355
input: [flight_proto_path / 'Flight.proto'],

cpp/src/arrow/util/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ conf_data.set('ARROW_JSON', needs_json)
5151
conf_data.set('ARROW_MIMALLOC', false)
5252
conf_data.set('ARROW_ORC', false)
5353
conf_data.set('ARROW_PARQUET', needs_parquet)
54-
conf_data.set('ARROW_SUBSTRAIT', false)
54+
conf_data.set('ARROW_SUBSTRAIT', needs_substrait)
5555
conf_data.set('ARROW_AZURE', false)
5656
conf_data.set('ARROW_ENABLE_THREADING', true)
5757
conf_data.set('ARROW_GCS', false)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
project('substrait', 'cpp')
19+
20+
protobuf_dep = dependency('protobuf')
21+
protoc = find_program('protoc')
22+
23+
# To ensure messages from proto files are created correctly, we need to
24+
# pass in dllexport_decl=<...> . Unfortunately, it doesn't appear that we
25+
# can just pass in dllexport_decl=SUBSTRAIT_EXPORT, as the visibility
26+
# macro won't be easily available to the generated proto file. See also
27+
# https://github.com/protocolbuffers/protobuf/issues/19422
28+
if meson.get_compiler('cpp').get_id() == 'msvc'
29+
if get_option('default_library') != 'static'
30+
proto_visibility = 'dllexport_decl=__declspec(dllexport):'
31+
else
32+
proto_visibility = ''
33+
endif
34+
else
35+
proto_visibility = 'dllexport_decl=__attribute__((visibility("default"))):'
36+
endif
37+
38+
substrait_protos_dir = meson.current_source_dir() / 'proto'
39+
gen = generator(
40+
protoc,
41+
output: ['@BASENAME@.pb.cc', '@BASENAME@.pb.h'],
42+
arguments: [
43+
'--proto_path=@0@'.format(substrait_protos_dir),
44+
'--cpp_out=@0@@1@'.format(proto_visibility, '@BUILD_DIR@'),
45+
'@INPUT@',
46+
],
47+
)
48+
protos = [
49+
'substrait/algebra.proto',
50+
'substrait/extended_expression.proto',
51+
'substrait/extensions/extensions.proto',
52+
'substrait/plan.proto',
53+
'substrait/type.proto',
54+
]
55+
generated_sources = []
56+
foreach proto : protos
57+
generated_sources += [
58+
gen.process(
59+
meson.current_source_dir() / 'proto' / proto,
60+
preserve_path_from: substrait_protos_dir,
61+
),
62+
]
63+
endforeach
64+
65+
substrait_dep = declare_dependency(
66+
sources: generated_sources,
67+
include_directories: include_directories('.'),
68+
)
69+
meson.override_dependency('substrait', substrait_dep)

cpp/subprojects/substrait.wrap

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
[wrap-file]
19+
source_url = https://github.com/substrait-io/substrait/archive/v0.44.0.tar.gz
20+
source_filename = substrait-0.44.0.tar.gz
21+
source_hash = f989a862f694e7dbb695925ddb7c4ce06aa6c51aca945105c075139aed7e55a2
22+
directory = substrait-0.44.0
23+
patch_directory=substrait
24+
25+
[provide]
26+
dependency_names = substrait

0 commit comments

Comments
 (0)