itsi-server 0.1.11 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/CODE_OF_CONDUCT.md +7 -0
  4. data/Cargo.lock +1536 -45
  5. data/README.md +4 -0
  6. data/_index.md +6 -0
  7. data/exe/itsi +33 -74
  8. data/ext/itsi_error/src/lib.rs +9 -0
  9. data/ext/itsi_error/target/debug/build/clang-sys-da71b0344e568175/out/common.rs +355 -0
  10. data/ext/itsi_error/target/debug/build/clang-sys-da71b0344e568175/out/dynamic.rs +276 -0
  11. data/ext/itsi_error/target/debug/build/clang-sys-da71b0344e568175/out/macros.rs +49 -0
  12. data/ext/itsi_error/target/debug/build/rb-sys-49f554618693db24/out/bindings-0.9.110-mri-arm64-darwin23-3.4.2.rs +8865 -0
  13. data/ext/itsi_error/target/debug/incremental/itsi_error-1mmt5sux7jb0i/s-h510z7m8v9-0bxu7yd.lock +0 -0
  14. data/ext/itsi_error/target/debug/incremental/itsi_error-2vn3jey74oiw0/s-h5113n0e7e-1v5qzs6.lock +0 -0
  15. data/ext/itsi_error/target/debug/incremental/itsi_error-37uv9dicz7awp/s-h510ykifhe-0tbnep2.lock +0 -0
  16. data/ext/itsi_error/target/debug/incremental/itsi_error-37uv9dicz7awp/s-h510yyocpj-0tz7ug7.lock +0 -0
  17. data/ext/itsi_error/target/debug/incremental/itsi_error-37uv9dicz7awp/s-h510z0xc8g-14ol18k.lock +0 -0
  18. data/ext/itsi_error/target/debug/incremental/itsi_error-3g5qf4y7d54uj/s-h5113n0e7d-1trk8on.lock +0 -0
  19. data/ext/itsi_error/target/debug/incremental/itsi_error-3lpfftm45d3e2/s-h510z7m8r3-1pxp20o.lock +0 -0
  20. data/ext/itsi_error/target/debug/incremental/itsi_error-3o4qownhl3d7n/s-h510ykifek-1uxasnk.lock +0 -0
  21. data/ext/itsi_error/target/debug/incremental/itsi_error-3o4qownhl3d7n/s-h510yyocki-11u37qm.lock +0 -0
  22. data/ext/itsi_error/target/debug/incremental/itsi_error-3o4qownhl3d7n/s-h510z0xc93-0pmy0zm.lock +0 -0
  23. data/ext/itsi_rb_helpers/Cargo.toml +1 -0
  24. data/ext/itsi_rb_helpers/src/heap_value.rs +18 -0
  25. data/ext/itsi_rb_helpers/src/lib.rs +34 -7
  26. data/ext/itsi_rb_helpers/target/debug/build/clang-sys-da71b0344e568175/out/common.rs +355 -0
  27. data/ext/itsi_rb_helpers/target/debug/build/clang-sys-da71b0344e568175/out/dynamic.rs +276 -0
  28. data/ext/itsi_rb_helpers/target/debug/build/clang-sys-da71b0344e568175/out/macros.rs +49 -0
  29. data/ext/itsi_rb_helpers/target/debug/build/rb-sys-eb9ed4ff3a60f995/out/bindings-0.9.110-mri-arm64-darwin23-3.4.2.rs +8865 -0
  30. data/ext/itsi_rb_helpers/target/debug/incremental/itsi_rb_helpers-040pxg6yhb3g3/s-h5113n7a1b-03bwlt4.lock +0 -0
  31. data/ext/itsi_rb_helpers/target/debug/incremental/itsi_rb_helpers-131g1u4dzkt1a/s-h51113xnh3-1eik1ip.lock +0 -0
  32. data/ext/itsi_rb_helpers/target/debug/incremental/itsi_rb_helpers-131g1u4dzkt1a/s-h5111704jj-0g4rj8x.lock +0 -0
  33. data/ext/itsi_rb_helpers/target/debug/incremental/itsi_rb_helpers-1q2d3drtxrzs5/s-h5113n79yl-0bxcqc5.lock +0 -0
  34. data/ext/itsi_rb_helpers/target/debug/incremental/itsi_rb_helpers-374a9h7ovycj0/s-h51113xoox-10de2hp.lock +0 -0
  35. data/ext/itsi_rb_helpers/target/debug/incremental/itsi_rb_helpers-374a9h7ovycj0/s-h5111704w7-0vdq7gq.lock +0 -0
  36. data/ext/itsi_server/Cargo.toml +69 -30
  37. data/ext/itsi_server/src/lib.rs +79 -147
  38. data/ext/itsi_server/src/{body_proxy → ruby_types/itsi_body_proxy}/big_bytes.rs +10 -5
  39. data/ext/itsi_server/src/{body_proxy/itsi_body_proxy.rs → ruby_types/itsi_body_proxy/mod.rs} +22 -3
  40. data/ext/itsi_server/src/ruby_types/itsi_grpc_request.rs +147 -0
  41. data/ext/itsi_server/src/ruby_types/itsi_grpc_response.rs +19 -0
  42. data/ext/itsi_server/src/ruby_types/itsi_grpc_stream/mod.rs +216 -0
  43. data/ext/itsi_server/src/{request/itsi_request.rs → ruby_types/itsi_http_request.rs} +101 -117
  44. data/ext/itsi_server/src/{response/itsi_response.rs → ruby_types/itsi_http_response.rs} +72 -41
  45. data/ext/itsi_server/src/ruby_types/itsi_server/file_watcher.rs +225 -0
  46. data/ext/itsi_server/src/ruby_types/itsi_server/itsi_server_config.rs +355 -0
  47. data/ext/itsi_server/src/ruby_types/itsi_server.rs +82 -0
  48. data/ext/itsi_server/src/ruby_types/mod.rs +55 -0
  49. data/ext/itsi_server/src/server/bind.rs +13 -5
  50. data/ext/itsi_server/src/server/byte_frame.rs +32 -0
  51. data/ext/itsi_server/src/server/cache_store.rs +74 -0
  52. data/ext/itsi_server/src/server/itsi_service.rs +172 -0
  53. data/ext/itsi_server/src/server/lifecycle_event.rs +3 -0
  54. data/ext/itsi_server/src/server/listener.rs +102 -2
  55. data/ext/itsi_server/src/server/middleware_stack/middleware.rs +153 -0
  56. data/ext/itsi_server/src/server/middleware_stack/middlewares/allow_list.rs +47 -0
  57. data/ext/itsi_server/src/server/middleware_stack/middlewares/auth_api_key.rs +58 -0
  58. data/ext/itsi_server/src/server/middleware_stack/middlewares/auth_basic.rs +82 -0
  59. data/ext/itsi_server/src/server/middleware_stack/middlewares/auth_jwt.rs +321 -0
  60. data/ext/itsi_server/src/server/middleware_stack/middlewares/cache_control.rs +139 -0
  61. data/ext/itsi_server/src/server/middleware_stack/middlewares/compression.rs +300 -0
  62. data/ext/itsi_server/src/server/middleware_stack/middlewares/cors.rs +287 -0
  63. data/ext/itsi_server/src/server/middleware_stack/middlewares/deny_list.rs +48 -0
  64. data/ext/itsi_server/src/server/middleware_stack/middlewares/error_response.rs +127 -0
  65. data/ext/itsi_server/src/server/middleware_stack/middlewares/etag.rs +191 -0
  66. data/ext/itsi_server/src/server/middleware_stack/middlewares/grpc_service.rs +72 -0
  67. data/ext/itsi_server/src/server/middleware_stack/middlewares/header_interpretation.rs +85 -0
  68. data/ext/itsi_server/src/server/middleware_stack/middlewares/intrusion_protection.rs +195 -0
  69. data/ext/itsi_server/src/server/middleware_stack/middlewares/log_requests.rs +82 -0
  70. data/ext/itsi_server/src/server/middleware_stack/middlewares/mod.rs +82 -0
  71. data/ext/itsi_server/src/server/middleware_stack/middlewares/proxy.rs +216 -0
  72. data/ext/itsi_server/src/server/middleware_stack/middlewares/rate_limit.rs +124 -0
  73. data/ext/itsi_server/src/server/middleware_stack/middlewares/redirect.rs +76 -0
  74. data/ext/itsi_server/src/server/middleware_stack/middlewares/request_headers.rs +43 -0
  75. data/ext/itsi_server/src/server/middleware_stack/middlewares/response_headers.rs +34 -0
  76. data/ext/itsi_server/src/server/middleware_stack/middlewares/ruby_app.rs +93 -0
  77. data/ext/itsi_server/src/server/middleware_stack/middlewares/static_assets.rs +162 -0
  78. data/ext/itsi_server/src/server/middleware_stack/middlewares/string_rewrite.rs +158 -0
  79. data/ext/itsi_server/src/server/middleware_stack/middlewares/token_source.rs +12 -0
  80. data/ext/itsi_server/src/server/middleware_stack/mod.rs +315 -0
  81. data/ext/itsi_server/src/server/mod.rs +8 -1
  82. data/ext/itsi_server/src/server/process_worker.rs +38 -12
  83. data/ext/itsi_server/src/server/rate_limiter.rs +565 -0
  84. data/ext/itsi_server/src/server/request_job.rs +11 -0
  85. data/ext/itsi_server/src/server/serve_strategy/cluster_mode.rs +119 -42
  86. data/ext/itsi_server/src/server/serve_strategy/mod.rs +9 -6
  87. data/ext/itsi_server/src/server/serve_strategy/single_mode.rs +256 -111
  88. data/ext/itsi_server/src/server/signal.rs +19 -0
  89. data/ext/itsi_server/src/server/static_file_server.rs +984 -0
  90. data/ext/itsi_server/src/server/thread_worker.rs +139 -94
  91. data/ext/itsi_server/src/server/types.rs +43 -0
  92. data/ext/itsi_tracing/Cargo.toml +1 -0
  93. data/ext/itsi_tracing/src/lib.rs +216 -45
  94. data/ext/itsi_tracing/target/debug/incremental/itsi_tracing-0994n8rpvvt9m/s-h510hfz1f6-1kbycmq.lock +0 -0
  95. data/ext/itsi_tracing/target/debug/incremental/itsi_tracing-0bob7bf4yq34i/s-h5113125h5-0lh4rag.lock +0 -0
  96. data/ext/itsi_tracing/target/debug/incremental/itsi_tracing-2fcodulrxbbxo/s-h510h2infk-0hp5kjw.lock +0 -0
  97. data/ext/itsi_tracing/target/debug/incremental/itsi_tracing-2iak63r1woi1l/s-h510h2in4q-0kxfzw1.lock +0 -0
  98. data/ext/itsi_tracing/target/debug/incremental/itsi_tracing-2kk4qj9gn5dg2/s-h5113124kv-0enwon2.lock +0 -0
  99. data/ext/itsi_tracing/target/debug/incremental/itsi_tracing-2mwo0yas7dtw4/s-h510hfz1ha-1udgpei.lock +0 -0
  100. data/lib/itsi/{request.rb → http_request.rb} +29 -5
  101. data/lib/itsi/http_response.rb +39 -0
  102. data/lib/itsi/server/Itsi.rb +11 -19
  103. data/lib/itsi/server/config/dsl.rb +506 -0
  104. data/lib/itsi/server/config.rb +103 -8
  105. data/lib/itsi/server/default_app/default_app.rb +38 -0
  106. data/lib/itsi/server/grpc_interface.rb +213 -0
  107. data/lib/itsi/server/rack/handler/itsi.rb +8 -17
  108. data/lib/itsi/server/rack_interface.rb +23 -4
  109. data/lib/itsi/server/scheduler_interface.rb +1 -1
  110. data/lib/itsi/server/scheduler_mode.rb +4 -0
  111. data/lib/itsi/server/signal_trap.rb +7 -1
  112. data/lib/itsi/server/version.rb +1 -1
  113. data/lib/itsi/server.rb +74 -63
  114. data/lib/itsi/standard_headers.rb +86 -0
  115. metadata +84 -15
  116. data/ext/itsi_scheduler/extconf.rb +0 -6
  117. data/ext/itsi_server/src/body_proxy/mod.rs +0 -2
  118. data/ext/itsi_server/src/request/mod.rs +0 -1
  119. data/ext/itsi_server/src/response/mod.rs +0 -1
  120. data/ext/itsi_server/src/server/itsi_server.rs +0 -288
  121. data/lib/itsi/server/options_dsl.rb +0 -401
  122. data/lib/itsi/stream_io.rb +0 -38
  123. /data/lib/itsi/{index.html → server/default_app/index.html} +0 -0
@@ -0,0 +1,276 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ use std::env;
4
+ use std::fs::File;
5
+ use std::io::{self, Error, ErrorKind, Read, Seek, SeekFrom};
6
+ use std::path::{Path, PathBuf};
7
+
8
+ use super::common;
9
+
10
+ //================================================
11
+ // Validation
12
+ //================================================
13
+
14
+ /// Extracts the ELF class from the ELF header in a shared library.
15
+ fn parse_elf_header(path: &Path) -> io::Result<u8> {
16
+ let mut file = File::open(path)?;
17
+ let mut buffer = [0; 5];
18
+ file.read_exact(&mut buffer)?;
19
+ if buffer[..4] == [127, 69, 76, 70] {
20
+ Ok(buffer[4])
21
+ } else {
22
+ Err(Error::new(ErrorKind::InvalidData, "invalid ELF header"))
23
+ }
24
+ }
25
+
26
+ /// Extracts the magic number and machine type from the PE header in a shared library.
27
+ fn parse_pe_header(path: &Path) -> io::Result<(u16, u16)> {
28
+ let mut file = File::open(path)?;
29
+
30
+ // Extract the header offset.
31
+ let mut buffer = [0; 4];
32
+ let start = SeekFrom::Start(0x3C);
33
+ file.seek(start)?;
34
+ file.read_exact(&mut buffer)?;
35
+ let offset = i32::from_le_bytes(buffer);
36
+
37
+ // Check the validity of the header.
38
+ file.seek(SeekFrom::Start(offset as u64))?;
39
+ file.read_exact(&mut buffer)?;
40
+ if buffer != [80, 69, 0, 0] {
41
+ return Err(Error::new(ErrorKind::InvalidData, "invalid PE header"));
42
+ }
43
+
44
+ // Extract the magic number.
45
+ let mut buffer = [0; 2];
46
+ file.seek(SeekFrom::Current(20))?;
47
+ file.read_exact(&mut buffer)?;
48
+ let magic_number = u16::from_le_bytes(buffer);
49
+
50
+ // Extract the machine type.
51
+ let mut buffer = [0; 2];
52
+ file.seek(SeekFrom::Current(-22))?;
53
+ file.read_exact(&mut buffer)?;
54
+ let machine_type = u16::from_le_bytes(buffer);
55
+
56
+ return Ok((magic_number, machine_type));
57
+ }
58
+
59
+ /// Checks that a `libclang` shared library matches the target platform.
60
+ fn validate_library(path: &Path) -> Result<(), String> {
61
+ if target_os!("linux") || target_os!("freebsd") {
62
+ let class = parse_elf_header(path).map_err(|e| e.to_string())?;
63
+
64
+ if target_pointer_width!("32") && class != 1 {
65
+ return Err("invalid ELF class (64-bit)".into());
66
+ }
67
+
68
+ if target_pointer_width!("64") && class != 2 {
69
+ return Err("invalid ELF class (32-bit)".into());
70
+ }
71
+
72
+ Ok(())
73
+ } else if target_os!("windows") {
74
+ let (magic, machine_type) = parse_pe_header(path).map_err(|e| e.to_string())?;
75
+
76
+ if target_pointer_width!("32") && magic != 267 {
77
+ return Err("invalid DLL (64-bit)".into());
78
+ }
79
+
80
+ if target_pointer_width!("64") && magic != 523 {
81
+ return Err("invalid DLL (32-bit)".into());
82
+ }
83
+
84
+ let arch_mismatch = match machine_type {
85
+ 0x014C if !target_arch!("x86") => Some("x86"),
86
+ 0x8664 if !target_arch!("x86_64") => Some("x86-64"),
87
+ 0xAA64 if !target_arch!("aarch64") => Some("ARM64"),
88
+ _ => None,
89
+ };
90
+
91
+ if let Some(arch) = arch_mismatch {
92
+ Err(format!("invalid DLL ({arch})"))
93
+ } else {
94
+ Ok(())
95
+ }
96
+ } else {
97
+ Ok(())
98
+ }
99
+ }
100
+
101
+ //================================================
102
+ // Searching
103
+ //================================================
104
+
105
+ /// Extracts the version components in a `libclang` shared library filename.
106
+ fn parse_version(filename: &str) -> Vec<u32> {
107
+ let version = if let Some(version) = filename.strip_prefix("libclang.so.") {
108
+ version
109
+ } else if filename.starts_with("libclang-") {
110
+ &filename[9..filename.len() - 3]
111
+ } else {
112
+ return vec![];
113
+ };
114
+
115
+ version.split('.').map(|s| s.parse().unwrap_or(0)).collect()
116
+ }
117
+
118
+ /// Finds `libclang` shared libraries and returns the paths to, filenames of,
119
+ /// and versions of those shared libraries.
120
+ fn search_libclang_directories(runtime: bool) -> Result<Vec<(PathBuf, String, Vec<u32>)>, String> {
121
+ let mut files = vec![format!(
122
+ "{}clang{}",
123
+ env::consts::DLL_PREFIX,
124
+ env::consts::DLL_SUFFIX
125
+ )];
126
+
127
+ if target_os!("linux") {
128
+ // Some Linux distributions don't create a `libclang.so` symlink, so we
129
+ // need to look for versioned files (e.g., `libclang-3.9.so`).
130
+ files.push("libclang-*.so".into());
131
+
132
+ // Some Linux distributions don't create a `libclang.so` symlink and
133
+ // don't have versioned files as described above, so we need to look for
134
+ // suffix versioned files (e.g., `libclang.so.1`). However, `ld` cannot
135
+ // link to these files, so this will only be included when linking at
136
+ // runtime.
137
+ if runtime {
138
+ files.push("libclang.so.*".into());
139
+ files.push("libclang-*.so.*".into());
140
+ }
141
+ }
142
+
143
+ if target_os!("freebsd") || target_os!("haiku") || target_os!("netbsd") || target_os!("openbsd") {
144
+ // Some BSD distributions don't create a `libclang.so` symlink either,
145
+ // but use a different naming scheme for versioned files (e.g.,
146
+ // `libclang.so.7.0`).
147
+ files.push("libclang.so.*".into());
148
+ }
149
+
150
+ if target_os!("windows") {
151
+ // The official LLVM build uses `libclang.dll` on Windows instead of
152
+ // `clang.dll`. However, unofficial builds such as MinGW use `clang.dll`.
153
+ files.push("libclang.dll".into());
154
+ }
155
+
156
+ // Find and validate `libclang` shared libraries and collect the versions.
157
+ let mut valid = vec![];
158
+ let mut invalid = vec![];
159
+ for (directory, filename) in common::search_libclang_directories(&files, "LIBCLANG_PATH") {
160
+ let path = directory.join(&filename);
161
+ match validate_library(&path) {
162
+ Ok(()) => {
163
+ let version = parse_version(&filename);
164
+ valid.push((directory, filename, version))
165
+ }
166
+ Err(message) => invalid.push(format!("({}: {})", path.display(), message)),
167
+ }
168
+ }
169
+
170
+ if !valid.is_empty() {
171
+ return Ok(valid);
172
+ }
173
+
174
+ let message = format!(
175
+ "couldn't find any valid shared libraries matching: [{}], set the \
176
+ `LIBCLANG_PATH` environment variable to a path where one of these files \
177
+ can be found (invalid: [{}])",
178
+ files
179
+ .iter()
180
+ .map(|f| format!("'{}'", f))
181
+ .collect::<Vec<_>>()
182
+ .join(", "),
183
+ invalid.join(", "),
184
+ );
185
+
186
+ Err(message)
187
+ }
188
+
189
+ /// Finds the "best" `libclang` shared library and returns the directory and
190
+ /// filename of that library.
191
+ pub fn find(runtime: bool) -> Result<(PathBuf, String), String> {
192
+ search_libclang_directories(runtime)?
193
+ .iter()
194
+ // We want to find the `libclang` shared library with the highest
195
+ // version number, hence `max_by_key` below.
196
+ //
197
+ // However, in the case where there are multiple such `libclang` shared
198
+ // libraries, we want to use the order in which they appeared in the
199
+ // list returned by `search_libclang_directories` as a tiebreaker since
200
+ // that function returns `libclang` shared libraries in descending order
201
+ // of preference by how they were found.
202
+ //
203
+ // `max_by_key`, perhaps surprisingly, returns the *last* item with the
204
+ // maximum key rather than the first which results in the opposite of
205
+ // the tiebreaking behavior we want. This is easily fixed by reversing
206
+ // the list first.
207
+ .rev()
208
+ .max_by_key(|f| &f.2)
209
+ .cloned()
210
+ .map(|(path, filename, _)| (path, filename))
211
+ .ok_or_else(|| "unreachable".into())
212
+ }
213
+
214
+ //================================================
215
+ // Linking
216
+ //================================================
217
+
218
+ /// Finds and links to a `libclang` shared library.
219
+ #[cfg(not(feature = "runtime"))]
220
+ pub fn link() {
221
+ let cep = common::CommandErrorPrinter::default();
222
+
223
+ use std::fs;
224
+
225
+ let (directory, filename) = find(false).unwrap();
226
+ println!("cargo:rustc-link-search={}", directory.display());
227
+
228
+ if cfg!(all(target_os = "windows", target_env = "msvc")) {
229
+ // Find the `libclang` stub static library required for the MSVC
230
+ // toolchain.
231
+ let lib = if !directory.ends_with("bin") {
232
+ directory
233
+ } else {
234
+ directory.parent().unwrap().join("lib")
235
+ };
236
+
237
+ if lib.join("libclang.lib").exists() {
238
+ println!("cargo:rustc-link-search={}", lib.display());
239
+ } else if lib.join("libclang.dll.a").exists() {
240
+ // MSYS and MinGW use `libclang.dll.a` instead of `libclang.lib`.
241
+ // It is linkable with the MSVC linker, but Rust doesn't recognize
242
+ // the `.a` suffix, so we need to copy it with a different name.
243
+ //
244
+ // FIXME: Maybe we can just hardlink or symlink it?
245
+ let out = env::var("OUT_DIR").unwrap();
246
+ fs::copy(
247
+ lib.join("libclang.dll.a"),
248
+ Path::new(&out).join("libclang.lib"),
249
+ )
250
+ .unwrap();
251
+ println!("cargo:rustc-link-search=native={}", out);
252
+ } else {
253
+ panic!(
254
+ "using '{}', so 'libclang.lib' or 'libclang.dll.a' must be \
255
+ available in {}",
256
+ filename,
257
+ lib.display(),
258
+ );
259
+ }
260
+
261
+ println!("cargo:rustc-link-lib=dylib=libclang");
262
+ } else {
263
+ let name = filename.trim_start_matches("lib");
264
+
265
+ // Strip extensions and trailing version numbers (e.g., the `.so.7.0` in
266
+ // `libclang.so.7.0`).
267
+ let name = match name.find(".dylib").or_else(|| name.find(".so")) {
268
+ Some(index) => &name[0..index],
269
+ None => name,
270
+ };
271
+
272
+ println!("cargo:rustc-link-lib=dylib={}", name);
273
+ }
274
+
275
+ cep.discard();
276
+ }
@@ -0,0 +1,49 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ macro_rules! test {
4
+ () => (cfg!(test) && ::std::env::var("_CLANG_SYS_TEST").is_ok());
5
+ }
6
+
7
+ macro_rules! target_os {
8
+ ($os:expr) => {
9
+ if cfg!(test) && ::std::env::var("_CLANG_SYS_TEST").is_ok() {
10
+ let var = ::std::env::var("_CLANG_SYS_TEST_OS");
11
+ var.map_or(false, |v| v == $os)
12
+ } else {
13
+ cfg!(target_os = $os)
14
+ }
15
+ };
16
+ }
17
+
18
+ macro_rules! target_arch {
19
+ ($arch:expr) => {
20
+ if cfg!(test) && ::std::env::var("_CLANG_SYS_TEST").is_ok() {
21
+ let var = ::std::env::var("_CLANG_SYS_TEST_ARCH");
22
+ var.map_or(false, |v| v == $arch)
23
+ } else {
24
+ cfg!(target_arch = $arch)
25
+ }
26
+ };
27
+ }
28
+
29
+ macro_rules! target_pointer_width {
30
+ ($pointer_width:expr) => {
31
+ if cfg!(test) && ::std::env::var("_CLANG_SYS_TEST").is_ok() {
32
+ let var = ::std::env::var("_CLANG_SYS_TEST_POINTER_WIDTH");
33
+ var.map_or(false, |v| v == $pointer_width)
34
+ } else {
35
+ cfg!(target_pointer_width = $pointer_width)
36
+ }
37
+ };
38
+ }
39
+
40
+ macro_rules! target_env {
41
+ ($env:expr) => {
42
+ if cfg!(test) && ::std::env::var("_CLANG_SYS_TEST").is_ok() {
43
+ let var = ::std::env::var("_CLANG_SYS_TEST_ENV");
44
+ var.map_or(false, |v| v == $env)
45
+ } else {
46
+ cfg!(target_env = $env)
47
+ }
48
+ };
49
+ }