Skip to content

Commit 40da22b

Browse files
fix header includes
1 parent 68936a0 commit 40da22b

File tree

10 files changed

+86
-33
lines changed

10 files changed

+86
-33
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ function(configure_cargo_toml cargo_toml_dir CARGO_PROJECT_VERSION CARGO_LIB_NAM
133133
${CMAKE_CURRENT_SOURCE_DIR}/include/zenoh.h
134134
${CMAKE_CURRENT_SOURCE_DIR}/include/zenoh_memory.h
135135
${CMAKE_CURRENT_SOURCE_DIR}/include/zenoh_constants.h
136+
${CMAKE_CURRENT_SOURCE_DIR}/include/zenoh_def.h
136137
DESTINATION ${cargo_toml_dir}/include/)
137138
endif()
138139
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Cargo.toml.in" "${cargo_toml_dir}/Cargo.toml" @ONLY)

buildrs/cbindgen_generator.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ fn create_generics_header(path_in: &str, path_out: &str) {
9393
.write_all(
9494
"#pragma once
9595
// clang-format off
96+
#include <stdbool.h>
9697
98+
#include \"zenoh_commons.h\"
99+
#include \"zenoh_opaque.h\"
97100
"
98101
.as_bytes(),
99102
)

buildrs/splitguide.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ const HEADER: &str = r"//
2323
// Contributors:
2424
// ZettaScale Zenoh Team, <[email protected]>
2525
//
26+
27+
#pragma once
2628
// clang-format off
27-
#ifdef DOCS
28-
#define ALIGN(n)
29-
#define ZENOHC_API
30-
#endif
3129
";
3230

3331
enum SplitRule {
@@ -568,6 +566,21 @@ impl FunctionSignature {
568566
}
569567

570568
pub fn split_bindings(genetation_path: impl AsRef<Path>) -> Result<Vec<PathBuf>, String> {
569+
let headers_by_file = HashMap::from([
570+
(
571+
"zenoh_commons.h",
572+
vec![
573+
"zenoh_def.h",
574+
"zenoh_configure.h",
575+
"zenoh_opaque.h",
576+
"zenoh_includes.h",
577+
],
578+
),
579+
(
580+
"zenoh_opaque.h",
581+
vec!["zenoh_def.h", "zenoh_configure.h", "zenoh_includes.h"],
582+
),
583+
]);
571584
let bindings = std::fs::read_to_string(&genetation_path).unwrap();
572585
let split_guide = SplitGuide::from_yaml(SPLITGUIDE_PATH);
573586
let mut files = split_guide
@@ -586,9 +599,17 @@ pub fn split_bindings(genetation_path: impl AsRef<Path>) -> Result<Vec<PathBuf>,
586599
(path as &Path, BufWriter::new(file))
587600
})
588601
.collect::<HashMap<_, _>>();
589-
for file in files.values_mut() {
602+
for (path, file) in files.iter_mut() {
590603
file.write_all(HEADER.as_bytes())
591604
.map_err(|e| e.to_string())?;
605+
if let Some(n) = path.file_name().and_then(|p| p.to_str()) {
606+
if let Some(headers) = headers_by_file.get(n) {
607+
for h in headers {
608+
file.write_all(format!("#include \"{h}\"\n").as_bytes())
609+
.map_err(|e| e.to_string())?;
610+
}
611+
}
612+
}
592613
}
593614
let mut records = group_tokens(Tokenizer {
594615
filename: genetation_path.as_ref(),

include/zenoh.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,8 @@
1010
extern "C" {
1111
#endif
1212

13-
#ifdef _MSC_VER
14-
#define ALIGN(n) __declspec(align(n))
15-
#else
16-
#define ALIGN(n) __attribute__((aligned(n)))
17-
#endif
18-
19-
#if defined(ZENOHC_DYN_LIB) && defined(_MSC_VER)
20-
#define ZENOHC_API __declspec(dllimport)
21-
#else
22-
#define ZENOHC_API
23-
#endif
24-
2513
// clang-format off
26-
// include order is important
27-
#include "zenoh_concrete.h"
14+
#include "zenoh_defines.h"
2815
#include "zenoh_opaque.h"
2916
#include "zenoh_commons.h"
3017
#include "zenoh_constants.h"

include/zenoh_commons.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
// Contributors:
1212
// ZettaScale Zenoh Team, <[email protected]>
1313
//
14+
15+
#pragma once
1416
// clang-format off
15-
#ifdef DOCS
16-
#define ALIGN(n)
17-
#define ZENOHC_API
18-
#endif
17+
#include "zenoh_def.h"
18+
#include "zenoh_configure.h"
19+
#include "zenoh_opaque.h"
20+
#include "zenoh_includes.h"
1921
typedef enum z_congestion_control_t {
2022
/**
2123
* Messages are not dropped in case of congestion.

include/zenoh_def.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
#ifdef DOCS
4+
#define ALIGN(n)
5+
#else
6+
#ifdef _MSC_VER
7+
#define ALIGN(n) __declspec(align(n))
8+
#else
9+
#define ALIGN(n) __attribute__((aligned(n)))
10+
#endif
11+
#endif
12+
13+
#ifdef DOCS
14+
#define ZENOHC_API
15+
#elif defined(ZENOHC_DYN_LIB) && defined(_MSC_VER)
16+
#define ZENOHC_API __declspec(dllimport)
17+
#elif defined(_MSC_VER)
18+
#define ZENOHC_API
19+
#else
20+
#define ZENOHC_API __attribute__((visibility("default")))
21+
#endif

include/zenoh_concrete.h renamed to include/zenoh_defines.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,9 @@
1111
// Contributors:
1212
// ZettaScale Zenoh Team, <[email protected]>
1313
//
14+
15+
#pragma once
1416
// clang-format off
15-
#ifdef DOCS
16-
#define ALIGN(n)
17-
#define ZENOHC_API
18-
#endif
19-
#include <stdarg.h>
20-
#include <stdbool.h>
21-
#include <stddef.h>
22-
#include <stdint.h>
23-
#include <stdlib.h>
2417
#define DEFAULT_SCOUTING_TIMEOUT 1000
2518
#define Z_CHANNEL_DISCONNECTED 1
2619
#define Z_CHANNEL_NODATA 2

include/zenoh_includes.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// Copyright (c) 2024 ZettaScale Technology
3+
//
4+
// This program and the accompanying materials are made available under the
5+
// terms of the Eclipse Public License 2.0 which is available at
6+
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
//
9+
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
//
11+
// Contributors:
12+
// ZettaScale Zenoh Team, <[email protected]>
13+
//
14+
15+
#pragma once
16+
// clang-format off
17+
#include <stdarg.h>
18+
#include <stdbool.h>
19+
#include <stddef.h>
20+
#include <stdint.h>
21+
#include <stdlib.h>

include/zenoh_macros.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#pragma once
22
// clang-format off
3+
#include <stdbool.h>
34

5+
#include "zenoh_commons.h"
6+
#include "zenoh_opaque.h"
47

58
#ifndef __cplusplus
69

splitguide.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ zenoh_commons.h:
33
- :const
44
- :typedefs
55
- :multiples
6-
zenoh_concrete.h:
6+
zenoh_includes.h:
77
- :includes
8+
zenoh_defines.h:
89
- :defines
910
zenoh_opaque.h:
1011
- z_owned_bytes_t!

0 commit comments

Comments
 (0)