| 
									
										
										
										
											2025-04-29 15:11:10 +02:00
										 |  |  | # ftxui_common.bzl | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | load("@rules_cc//cc:defs.bzl", "cc_library") | 
					
						
							| 
									
										
										
										
											2025-05-07 22:41:17 +02:00
										 |  |  | load("@rules_cc//cc:defs.bzl", "cc_binary") | 
					
						
							| 
									
										
										
										
											2025-04-29 15:11:10 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Microsoft terminal is a bit buggy ¯\_(ツ)_/¯ and MSVC uses bad defaults. | 
					
						
							|  |  |  | def windows_copts(): | 
					
						
							|  |  |  |     MSVC_COPTS = [ | 
					
						
							|  |  |  |       # Microsoft Visual Studio must decode sources files as UTF-8. | 
					
						
							|  |  |  |       "/utf-8", | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Microsoft Visual Studio must interpret the codepoint using unicode. | 
					
						
							|  |  |  |       "/DUNICODE", | 
					
						
							|  |  |  |       "/D_UNICODE", | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Fallback for Microsoft Terminal. | 
					
						
							|  |  |  |       # This | 
					
						
							|  |  |  |       # - Replace missing font symbols by others. | 
					
						
							|  |  |  |       # - Reduce screen position pooling frequency to deals against a Microsoft | 
					
						
							|  |  |  |       #   race condition. This was fixed in 2020, but clients never not updated. | 
					
						
							|  |  |  |       #   - https://github.com/microsoft/terminal/pull/7583 | 
					
						
							|  |  |  |       #   - https://github.com/ArthurSonzogni/FTXUI/issues/136 | 
					
						
							|  |  |  |       "/DFTXUI_MICROSOFT_TERMINAL_FALLBACK", | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     WINDOWS_COPTS = [ | 
					
						
							|  |  |  |       # Fallback for Microsoft Terminal. | 
					
						
							|  |  |  |       # This | 
					
						
							|  |  |  |       # - Replace missing font symbols by others. | 
					
						
							|  |  |  |       # - Reduce screen position pooling frequency to deals against a Microsoft | 
					
						
							| 
									
										
										
										
											2025-05-07 22:41:17 +02:00
										 |  |  |       #   race condition. This was fixed in 2020, but clients are still using | 
					
						
							|  |  |  |       #   old versions. | 
					
						
							| 
									
										
										
										
											2025-04-29 15:11:10 +02:00
										 |  |  |       #   - https://github.com/microsoft/terminal/pull/7583 | 
					
						
							|  |  |  |       #   - https://github.com/ArthurSonzogni/FTXUI/issues/136 | 
					
						
							|  |  |  |       "-DFTXUI_MICROSOFT_TERMINAL_FALLBACK", | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     return select({ | 
					
						
							|  |  |  |         # MSVC: | 
					
						
							|  |  |  |         "@rules_cc//cc/compiler:msvc-cl": MSVC_COPTS, | 
					
						
							|  |  |  |         "@rules_cc//cc/compiler:clang-cl": MSVC_COPTS, | 
					
						
							|  |  |  |         "@platforms//os:windows": WINDOWS_COPTS, | 
					
						
							|  |  |  |         "//conditions:default": [], | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def ftxui_cc_library( | 
					
						
							|  |  |  |         name, | 
					
						
							| 
									
										
										
										
											2025-05-07 22:41:17 +02:00
										 |  |  |         srcs = [], | 
					
						
							|  |  |  |         hdrs = [], | 
					
						
							| 
									
										
										
										
											2025-04-29 15:11:10 +02:00
										 |  |  |         linkopts = [], | 
					
						
							|  |  |  |         deps = []): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cc_library( | 
					
						
							|  |  |  |         name = name, | 
					
						
							|  |  |  |         srcs = srcs, | 
					
						
							|  |  |  |         hdrs = hdrs, | 
					
						
							|  |  |  |         linkopts = linkopts, | 
					
						
							|  |  |  |         deps = deps, | 
					
						
							|  |  |  |         strip_include_prefix = "", | 
					
						
							|  |  |  |         include_prefix = "", | 
					
						
							|  |  |  |         includes = [ | 
					
						
							|  |  |  |             "include", | 
					
						
							|  |  |  |             "src", | 
					
						
							|  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2025-05-07 22:41:17 +02:00
										 |  |  |         copts = windows_copts(), | 
					
						
							| 
									
										
										
										
											2025-04-29 15:11:10 +02:00
										 |  |  |         visibility = ["//visibility:public"], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Compile all the examples in the examples/ directory. | 
					
						
							| 
									
										
										
										
											2025-05-07 22:41:17 +02:00
										 |  |  | # This is useful to check the Bazel is always synchronized against CMake | 
					
						
							|  |  |  | # definitions. | 
					
						
							| 
									
										
										
										
											2025-04-29 15:11:10 +02:00
										 |  |  | def generate_examples(): | 
					
						
							|  |  |  |     cpp_files = native.glob(["examples/**/*.cpp"]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for src in cpp_files: | 
					
						
							|  |  |  |         # Skip failing examples due to the color_info_sorted_2d.ipp dependency. | 
					
						
							|  |  |  |         if src == "examples/component/homescreen.cpp" or \ | 
					
						
							|  |  |  |            src == "examples/dom/color_info_palette256.cpp" or \ | 
					
						
							|  |  |  |            src == "examples/dom/color_gallery.cpp": | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Turn "examples/component/button.cpp" → "example_component_button" | 
					
						
							|  |  |  |         name = src.replace("/", "_").replace(".cpp", "") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-07 22:41:17 +02:00
										 |  |  |         cc_binary( | 
					
						
							| 
									
										
										
										
											2025-04-29 15:11:10 +02:00
										 |  |  |             name = name, | 
					
						
							|  |  |  |             srcs = [src], | 
					
						
							| 
									
										
										
										
											2025-05-07 22:41:17 +02:00
										 |  |  |             deps = [ | 
					
						
							|  |  |  |               ":component", | 
					
						
							|  |  |  |               ":dom", | 
					
						
							|  |  |  |               ":screen", | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             copts = windows_copts(), | 
					
						
							| 
									
										
										
										
											2025-04-29 15:11:10 +02:00
										 |  |  |         ) |