kreuzberg 4.0.0.rc2 → 4.0.0
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.
- checksums.yaml +4 -4
- data/.gitignore +14 -14
- data/.rspec +3 -3
- data/.rubocop.yaml +1 -1
- data/.rubocop.yml +543 -538
- data/Gemfile +8 -8
- data/Gemfile.lock +194 -6
- data/README.md +396 -426
- data/Rakefile +34 -25
- data/Steepfile +51 -47
- data/examples/async_patterns.rb +283 -341
- data/ext/kreuzberg_rb/extconf.rb +65 -45
- data/ext/kreuzberg_rb/native/.cargo/config.toml +23 -0
- data/ext/kreuzberg_rb/native/Cargo.lock +7619 -6535
- data/ext/kreuzberg_rb/native/Cargo.toml +75 -44
- data/ext/kreuzberg_rb/native/README.md +425 -425
- data/ext/kreuzberg_rb/native/build.rs +15 -15
- data/ext/kreuzberg_rb/native/include/ieeefp.h +11 -11
- data/ext/kreuzberg_rb/native/include/msvc_compat/strings.h +14 -14
- data/ext/kreuzberg_rb/native/include/strings.h +20 -20
- data/ext/kreuzberg_rb/native/include/unistd.h +47 -47
- data/ext/kreuzberg_rb/native/src/lib.rs +3802 -2998
- data/extconf.rb +60 -28
- data/kreuzberg.gemspec +199 -148
- data/lib/kreuzberg/api_proxy.rb +126 -142
- data/lib/kreuzberg/cache_api.rb +67 -46
- data/lib/kreuzberg/cli.rb +47 -55
- data/lib/kreuzberg/cli_proxy.rb +117 -127
- data/lib/kreuzberg/config.rb +936 -691
- data/lib/kreuzberg/error_context.rb +136 -32
- data/lib/kreuzberg/errors.rb +116 -118
- data/lib/kreuzberg/extraction_api.rb +313 -85
- data/lib/kreuzberg/mcp_proxy.rb +177 -186
- data/lib/kreuzberg/ocr_backend_protocol.rb +40 -113
- data/lib/kreuzberg/post_processor_protocol.rb +15 -86
- data/lib/kreuzberg/result.rb +334 -216
- data/lib/kreuzberg/setup_lib_path.rb +99 -80
- data/lib/kreuzberg/types.rb +170 -0
- data/lib/kreuzberg/validator_protocol.rb +16 -89
- data/lib/kreuzberg/version.rb +5 -5
- data/lib/kreuzberg.rb +96 -103
- data/lib/libpdfium.so +0 -0
- data/sig/kreuzberg/internal.rbs +184 -184
- data/sig/kreuzberg.rbs +561 -520
- data/spec/binding/async_operations_spec.rb +473 -0
- data/spec/binding/batch_operations_spec.rb +595 -0
- data/spec/binding/batch_spec.rb +359 -0
- data/spec/binding/cache_spec.rb +227 -227
- data/spec/binding/cli_proxy_spec.rb +85 -85
- data/spec/binding/cli_spec.rb +55 -55
- data/spec/binding/config_result_spec.rb +377 -0
- data/spec/binding/config_spec.rb +419 -345
- data/spec/binding/config_validation_spec.rb +377 -283
- data/spec/binding/embeddings_spec.rb +816 -0
- data/spec/binding/error_handling_spec.rb +399 -213
- data/spec/binding/error_recovery_spec.rb +488 -0
- data/spec/binding/errors_spec.rb +66 -66
- data/spec/binding/font_config_spec.rb +220 -0
- data/spec/binding/images_spec.rb +738 -0
- data/spec/binding/keywords_extraction_spec.rb +600 -0
- data/spec/binding/metadata_types_spec.rb +1228 -0
- data/spec/binding/pages_extraction_spec.rb +471 -0
- data/spec/binding/plugins/ocr_backend_spec.rb +307 -307
- data/spec/binding/plugins/postprocessor_spec.rb +269 -269
- data/spec/binding/plugins/validator_spec.rb +273 -274
- data/spec/binding/tables_spec.rb +641 -0
- data/spec/fixtures/config.toml +38 -39
- data/spec/fixtures/config.yaml +41 -41
- data/spec/fixtures/invalid_config.toml +3 -4
- data/spec/smoke/package_spec.rb +177 -178
- data/spec/spec_helper.rb +40 -42
- data/spec/unit/config/chunking_config_spec.rb +213 -0
- data/spec/unit/config/embedding_config_spec.rb +343 -0
- data/spec/unit/config/extraction_config_spec.rb +438 -0
- data/spec/unit/config/font_config_spec.rb +285 -0
- data/spec/unit/config/hierarchy_config_spec.rb +314 -0
- data/spec/unit/config/image_extraction_config_spec.rb +209 -0
- data/spec/unit/config/image_preprocessing_config_spec.rb +249 -0
- data/spec/unit/config/keyword_config_spec.rb +229 -0
- data/spec/unit/config/language_detection_config_spec.rb +258 -0
- data/spec/unit/config/ocr_config_spec.rb +171 -0
- data/spec/unit/config/page_config_spec.rb +221 -0
- data/spec/unit/config/pdf_config_spec.rb +267 -0
- data/spec/unit/config/postprocessor_config_spec.rb +290 -0
- data/spec/unit/config/tesseract_config_spec.rb +181 -0
- data/spec/unit/config/token_reduction_config_spec.rb +251 -0
- data/test/metadata_types_test.rb +959 -0
- data/vendor/Cargo.toml +61 -0
- data/vendor/kreuzberg/Cargo.toml +259 -204
- data/vendor/kreuzberg/README.md +263 -175
- data/vendor/kreuzberg/build.rs +782 -474
- data/vendor/kreuzberg/examples/bench_fixes.rs +71 -0
- data/vendor/kreuzberg/examples/test_pdfium_fork.rs +62 -0
- data/vendor/kreuzberg/src/api/error.rs +81 -81
- data/vendor/kreuzberg/src/api/handlers.rs +320 -199
- data/vendor/kreuzberg/src/api/mod.rs +94 -79
- data/vendor/kreuzberg/src/api/server.rs +518 -353
- data/vendor/kreuzberg/src/api/types.rs +206 -170
- data/vendor/kreuzberg/src/cache/mod.rs +1167 -1167
- data/vendor/kreuzberg/src/chunking/mod.rs +2303 -677
- data/vendor/kreuzberg/src/chunking/processor.rs +219 -0
- data/vendor/kreuzberg/src/core/batch_mode.rs +95 -95
- data/vendor/kreuzberg/src/core/batch_optimizations.rs +385 -0
- data/vendor/kreuzberg/src/core/config.rs +1914 -1032
- data/vendor/kreuzberg/src/core/config_validation.rs +949 -0
- data/vendor/kreuzberg/src/core/extractor.rs +1200 -1024
- data/vendor/kreuzberg/src/core/formats.rs +235 -0
- data/vendor/kreuzberg/src/core/io.rs +329 -329
- data/vendor/kreuzberg/src/core/mime.rs +605 -605
- data/vendor/kreuzberg/src/core/mod.rs +61 -45
- data/vendor/kreuzberg/src/core/pipeline.rs +1223 -984
- data/vendor/kreuzberg/src/core/server_config.rs +1220 -0
- data/vendor/kreuzberg/src/embeddings.rs +471 -432
- data/vendor/kreuzberg/src/error.rs +431 -431
- data/vendor/kreuzberg/src/extraction/archive.rs +959 -954
- data/vendor/kreuzberg/src/extraction/capacity.rs +263 -0
- data/vendor/kreuzberg/src/extraction/docx.rs +404 -40
- data/vendor/kreuzberg/src/extraction/email.rs +855 -854
- data/vendor/kreuzberg/src/extraction/excel.rs +697 -688
- data/vendor/kreuzberg/src/extraction/html.rs +1830 -553
- data/vendor/kreuzberg/src/extraction/image.rs +492 -368
- data/vendor/kreuzberg/src/extraction/libreoffice.rs +574 -563
- data/vendor/kreuzberg/src/extraction/markdown.rs +216 -213
- data/vendor/kreuzberg/src/extraction/mod.rs +93 -81
- data/vendor/kreuzberg/src/extraction/office_metadata/app_properties.rs +398 -398
- data/vendor/kreuzberg/src/extraction/office_metadata/core_properties.rs +247 -247
- data/vendor/kreuzberg/src/extraction/office_metadata/custom_properties.rs +240 -240
- data/vendor/kreuzberg/src/extraction/office_metadata/mod.rs +130 -130
- data/vendor/kreuzberg/src/extraction/office_metadata/odt_properties.rs +284 -287
- data/vendor/kreuzberg/src/extraction/pptx.rs +3102 -3000
- data/vendor/kreuzberg/src/extraction/structured.rs +491 -490
- data/vendor/kreuzberg/src/extraction/table.rs +329 -328
- data/vendor/kreuzberg/src/extraction/text.rs +277 -269
- data/vendor/kreuzberg/src/extraction/xml.rs +333 -333
- data/vendor/kreuzberg/src/extractors/archive.rs +447 -446
- data/vendor/kreuzberg/src/extractors/bibtex.rs +470 -469
- data/vendor/kreuzberg/src/extractors/docbook.rs +504 -502
- data/vendor/kreuzberg/src/extractors/docx.rs +400 -367
- data/vendor/kreuzberg/src/extractors/email.rs +157 -143
- data/vendor/kreuzberg/src/extractors/epub.rs +696 -707
- data/vendor/kreuzberg/src/extractors/excel.rs +385 -343
- data/vendor/kreuzberg/src/extractors/fictionbook.rs +492 -491
- data/vendor/kreuzberg/src/extractors/html.rs +419 -393
- data/vendor/kreuzberg/src/extractors/image.rs +219 -198
- data/vendor/kreuzberg/src/extractors/jats.rs +1054 -1051
- data/vendor/kreuzberg/src/extractors/jupyter.rs +368 -367
- data/vendor/kreuzberg/src/extractors/latex.rs +653 -652
- data/vendor/kreuzberg/src/extractors/markdown.rs +701 -700
- data/vendor/kreuzberg/src/extractors/mod.rs +429 -365
- data/vendor/kreuzberg/src/extractors/odt.rs +628 -628
- data/vendor/kreuzberg/src/extractors/opml.rs +635 -634
- data/vendor/kreuzberg/src/extractors/orgmode.rs +529 -528
- data/vendor/kreuzberg/src/extractors/pdf.rs +761 -493
- data/vendor/kreuzberg/src/extractors/pptx.rs +279 -248
- data/vendor/kreuzberg/src/extractors/rst.rs +577 -576
- data/vendor/kreuzberg/src/extractors/rtf.rs +809 -810
- data/vendor/kreuzberg/src/extractors/security.rs +484 -484
- data/vendor/kreuzberg/src/extractors/security_tests.rs +367 -367
- data/vendor/kreuzberg/src/extractors/structured.rs +142 -140
- data/vendor/kreuzberg/src/extractors/text.rs +265 -260
- data/vendor/kreuzberg/src/extractors/typst.rs +651 -650
- data/vendor/kreuzberg/src/extractors/xml.rs +147 -135
- data/vendor/kreuzberg/src/image/dpi.rs +164 -164
- data/vendor/kreuzberg/src/image/mod.rs +6 -6
- data/vendor/kreuzberg/src/image/preprocessing.rs +417 -417
- data/vendor/kreuzberg/src/image/resize.rs +89 -89
- data/vendor/kreuzberg/src/keywords/config.rs +154 -154
- data/vendor/kreuzberg/src/keywords/mod.rs +237 -237
- data/vendor/kreuzberg/src/keywords/processor.rs +275 -267
- data/vendor/kreuzberg/src/keywords/rake.rs +293 -293
- data/vendor/kreuzberg/src/keywords/types.rs +68 -68
- data/vendor/kreuzberg/src/keywords/yake.rs +163 -163
- data/vendor/kreuzberg/src/language_detection/mod.rs +985 -942
- data/vendor/kreuzberg/src/language_detection/processor.rs +218 -0
- data/vendor/kreuzberg/src/lib.rs +114 -105
- data/vendor/kreuzberg/src/mcp/mod.rs +35 -32
- data/vendor/kreuzberg/src/mcp/server.rs +2090 -1968
- data/vendor/kreuzberg/src/ocr/cache.rs +469 -469
- data/vendor/kreuzberg/src/ocr/error.rs +37 -37
- data/vendor/kreuzberg/src/ocr/hocr.rs +216 -216
- data/vendor/kreuzberg/src/ocr/language_registry.rs +520 -0
- data/vendor/kreuzberg/src/ocr/mod.rs +60 -58
- data/vendor/kreuzberg/src/ocr/processor.rs +858 -863
- data/vendor/kreuzberg/src/ocr/table/mod.rs +4 -4
- data/vendor/kreuzberg/src/ocr/table/tsv_parser.rs +144 -144
- data/vendor/kreuzberg/src/ocr/tesseract_backend.rs +456 -450
- data/vendor/kreuzberg/src/ocr/types.rs +393 -393
- data/vendor/kreuzberg/src/ocr/utils.rs +47 -47
- data/vendor/kreuzberg/src/ocr/validation.rs +206 -206
- data/vendor/kreuzberg/src/panic_context.rs +154 -154
- data/vendor/kreuzberg/src/pdf/bindings.rs +306 -0
- data/vendor/kreuzberg/src/pdf/bundled.rs +408 -0
- data/vendor/kreuzberg/src/pdf/error.rs +214 -122
- data/vendor/kreuzberg/src/pdf/fonts.rs +358 -0
- data/vendor/kreuzberg/src/pdf/hierarchy.rs +903 -0
- data/vendor/kreuzberg/src/pdf/images.rs +139 -139
- data/vendor/kreuzberg/src/pdf/metadata.rs +509 -346
- data/vendor/kreuzberg/src/pdf/mod.rs +81 -50
- data/vendor/kreuzberg/src/pdf/rendering.rs +369 -369
- data/vendor/kreuzberg/src/pdf/table.rs +417 -393
- data/vendor/kreuzberg/src/pdf/text.rs +553 -158
- data/vendor/kreuzberg/src/plugins/extractor.rs +1042 -1013
- data/vendor/kreuzberg/src/plugins/mod.rs +212 -209
- data/vendor/kreuzberg/src/plugins/ocr.rs +637 -620
- data/vendor/kreuzberg/src/plugins/processor.rs +650 -642
- data/vendor/kreuzberg/src/plugins/registry.rs +1339 -1337
- data/vendor/kreuzberg/src/plugins/traits.rs +258 -258
- data/vendor/kreuzberg/src/plugins/validator.rs +967 -956
- data/vendor/kreuzberg/src/stopwords/mod.rs +1470 -1470
- data/vendor/kreuzberg/src/text/mod.rs +27 -19
- data/vendor/kreuzberg/src/text/quality.rs +710 -697
- data/vendor/kreuzberg/src/text/quality_processor.rs +231 -0
- data/vendor/kreuzberg/src/text/string_utils.rs +229 -217
- data/vendor/kreuzberg/src/text/token_reduction/cjk_utils.rs +164 -164
- data/vendor/kreuzberg/src/text/token_reduction/config.rs +100 -100
- data/vendor/kreuzberg/src/text/token_reduction/core.rs +832 -796
- data/vendor/kreuzberg/src/text/token_reduction/filters.rs +923 -902
- data/vendor/kreuzberg/src/text/token_reduction/mod.rs +160 -160
- data/vendor/kreuzberg/src/text/token_reduction/semantic.rs +619 -619
- data/vendor/kreuzberg/src/text/token_reduction/simd_text.rs +148 -147
- data/vendor/kreuzberg/src/text/utf8_validation.rs +193 -0
- data/vendor/kreuzberg/src/types.rs +1713 -903
- data/vendor/kreuzberg/src/utils/mod.rs +31 -17
- data/vendor/kreuzberg/src/utils/pool.rs +503 -0
- data/vendor/kreuzberg/src/utils/pool_sizing.rs +364 -0
- data/vendor/kreuzberg/src/utils/quality.rs +968 -959
- data/vendor/kreuzberg/src/utils/string_pool.rs +761 -0
- data/vendor/kreuzberg/src/utils/string_utils.rs +381 -381
- data/vendor/kreuzberg/stopwords/af_stopwords.json +53 -53
- data/vendor/kreuzberg/stopwords/ar_stopwords.json +482 -482
- data/vendor/kreuzberg/stopwords/bg_stopwords.json +261 -261
- data/vendor/kreuzberg/stopwords/bn_stopwords.json +400 -400
- data/vendor/kreuzberg/stopwords/br_stopwords.json +1205 -1205
- data/vendor/kreuzberg/stopwords/ca_stopwords.json +280 -280
- data/vendor/kreuzberg/stopwords/cs_stopwords.json +425 -425
- data/vendor/kreuzberg/stopwords/da_stopwords.json +172 -172
- data/vendor/kreuzberg/stopwords/de_stopwords.json +622 -622
- data/vendor/kreuzberg/stopwords/el_stopwords.json +849 -849
- data/vendor/kreuzberg/stopwords/en_stopwords.json +1300 -1300
- data/vendor/kreuzberg/stopwords/eo_stopwords.json +175 -175
- data/vendor/kreuzberg/stopwords/es_stopwords.json +734 -734
- data/vendor/kreuzberg/stopwords/et_stopwords.json +37 -37
- data/vendor/kreuzberg/stopwords/eu_stopwords.json +100 -100
- data/vendor/kreuzberg/stopwords/fa_stopwords.json +801 -801
- data/vendor/kreuzberg/stopwords/fi_stopwords.json +849 -849
- data/vendor/kreuzberg/stopwords/fr_stopwords.json +693 -693
- data/vendor/kreuzberg/stopwords/ga_stopwords.json +111 -111
- data/vendor/kreuzberg/stopwords/gl_stopwords.json +162 -162
- data/vendor/kreuzberg/stopwords/gu_stopwords.json +226 -226
- data/vendor/kreuzberg/stopwords/ha_stopwords.json +41 -41
- data/vendor/kreuzberg/stopwords/he_stopwords.json +196 -196
- data/vendor/kreuzberg/stopwords/hi_stopwords.json +227 -227
- data/vendor/kreuzberg/stopwords/hr_stopwords.json +181 -181
- data/vendor/kreuzberg/stopwords/hu_stopwords.json +791 -791
- data/vendor/kreuzberg/stopwords/hy_stopwords.json +47 -47
- data/vendor/kreuzberg/stopwords/id_stopwords.json +760 -760
- data/vendor/kreuzberg/stopwords/it_stopwords.json +634 -634
- data/vendor/kreuzberg/stopwords/ja_stopwords.json +136 -136
- data/vendor/kreuzberg/stopwords/kn_stopwords.json +84 -84
- data/vendor/kreuzberg/stopwords/ko_stopwords.json +681 -681
- data/vendor/kreuzberg/stopwords/ku_stopwords.json +64 -64
- data/vendor/kreuzberg/stopwords/la_stopwords.json +51 -51
- data/vendor/kreuzberg/stopwords/lt_stopwords.json +476 -476
- data/vendor/kreuzberg/stopwords/lv_stopwords.json +163 -163
- data/vendor/kreuzberg/stopwords/ml_stopwords.json +1 -1
- data/vendor/kreuzberg/stopwords/mr_stopwords.json +101 -101
- data/vendor/kreuzberg/stopwords/ms_stopwords.json +477 -477
- data/vendor/kreuzberg/stopwords/ne_stopwords.json +490 -490
- data/vendor/kreuzberg/stopwords/nl_stopwords.json +415 -415
- data/vendor/kreuzberg/stopwords/no_stopwords.json +223 -223
- data/vendor/kreuzberg/stopwords/pl_stopwords.json +331 -331
- data/vendor/kreuzberg/stopwords/pt_stopwords.json +562 -562
- data/vendor/kreuzberg/stopwords/ro_stopwords.json +436 -436
- data/vendor/kreuzberg/stopwords/ru_stopwords.json +561 -561
- data/vendor/kreuzberg/stopwords/si_stopwords.json +193 -193
- data/vendor/kreuzberg/stopwords/sk_stopwords.json +420 -420
- data/vendor/kreuzberg/stopwords/sl_stopwords.json +448 -448
- data/vendor/kreuzberg/stopwords/so_stopwords.json +32 -32
- data/vendor/kreuzberg/stopwords/st_stopwords.json +33 -33
- data/vendor/kreuzberg/stopwords/sv_stopwords.json +420 -420
- data/vendor/kreuzberg/stopwords/sw_stopwords.json +76 -76
- data/vendor/kreuzberg/stopwords/ta_stopwords.json +129 -129
- data/vendor/kreuzberg/stopwords/te_stopwords.json +54 -54
- data/vendor/kreuzberg/stopwords/th_stopwords.json +118 -118
- data/vendor/kreuzberg/stopwords/tl_stopwords.json +149 -149
- data/vendor/kreuzberg/stopwords/tr_stopwords.json +506 -506
- data/vendor/kreuzberg/stopwords/uk_stopwords.json +75 -75
- data/vendor/kreuzberg/stopwords/ur_stopwords.json +519 -519
- data/vendor/kreuzberg/stopwords/vi_stopwords.json +647 -647
- data/vendor/kreuzberg/stopwords/yo_stopwords.json +62 -62
- data/vendor/kreuzberg/stopwords/zh_stopwords.json +796 -796
- data/vendor/kreuzberg/stopwords/zu_stopwords.json +31 -31
- data/vendor/kreuzberg/tests/api_embed.rs +360 -0
- data/vendor/kreuzberg/tests/api_extract_multipart.rs +52 -52
- data/vendor/kreuzberg/tests/api_large_pdf_extraction.rs +471 -0
- data/vendor/kreuzberg/tests/api_large_pdf_extraction_diagnostics.rs +289 -0
- data/vendor/kreuzberg/tests/api_tests.rs +1472 -966
- data/vendor/kreuzberg/tests/archive_integration.rs +545 -543
- data/vendor/kreuzberg/tests/batch_orchestration.rs +587 -556
- data/vendor/kreuzberg/tests/batch_pooling_benchmark.rs +154 -0
- data/vendor/kreuzberg/tests/batch_processing.rs +328 -316
- data/vendor/kreuzberg/tests/bibtex_parity_test.rs +421 -421
- data/vendor/kreuzberg/tests/concurrency_stress.rs +541 -525
- data/vendor/kreuzberg/tests/config_features.rs +612 -598
- data/vendor/kreuzberg/tests/config_integration_test.rs +753 -0
- data/vendor/kreuzberg/tests/config_loading_tests.rs +416 -415
- data/vendor/kreuzberg/tests/core_integration.rs +519 -510
- data/vendor/kreuzberg/tests/csv_integration.rs +414 -414
- data/vendor/kreuzberg/tests/data/hierarchy_ground_truth.json +294 -0
- data/vendor/kreuzberg/tests/docbook_extractor_tests.rs +500 -498
- data/vendor/kreuzberg/tests/docx_metadata_extraction_test.rs +122 -122
- data/vendor/kreuzberg/tests/docx_vs_pandoc_comparison.rs +370 -370
- data/vendor/kreuzberg/tests/email_integration.rs +327 -325
- data/vendor/kreuzberg/tests/epub_native_extractor_tests.rs +275 -275
- data/vendor/kreuzberg/tests/error_handling.rs +402 -393
- data/vendor/kreuzberg/tests/fictionbook_extractor_tests.rs +228 -228
- data/vendor/kreuzberg/tests/format_integration.rs +165 -159
- data/vendor/kreuzberg/tests/helpers/mod.rs +202 -142
- data/vendor/kreuzberg/tests/html_table_test.rs +551 -551
- data/vendor/kreuzberg/tests/image_integration.rs +255 -253
- data/vendor/kreuzberg/tests/instrumentation_test.rs +139 -139
- data/vendor/kreuzberg/tests/jats_extractor_tests.rs +639 -639
- data/vendor/kreuzberg/tests/jupyter_extractor_tests.rs +704 -704
- data/vendor/kreuzberg/tests/keywords_integration.rs +479 -479
- data/vendor/kreuzberg/tests/keywords_quality.rs +509 -509
- data/vendor/kreuzberg/tests/latex_extractor_tests.rs +496 -496
- data/vendor/kreuzberg/tests/markdown_extractor_tests.rs +490 -490
- data/vendor/kreuzberg/tests/mime_detection.rs +429 -428
- data/vendor/kreuzberg/tests/ocr_configuration.rs +514 -510
- data/vendor/kreuzberg/tests/ocr_errors.rs +698 -676
- data/vendor/kreuzberg/tests/ocr_language_registry.rs +191 -0
- data/vendor/kreuzberg/tests/ocr_quality.rs +629 -627
- data/vendor/kreuzberg/tests/ocr_stress.rs +469 -469
- data/vendor/kreuzberg/tests/odt_extractor_tests.rs +674 -695
- data/vendor/kreuzberg/tests/opml_extractor_tests.rs +616 -616
- data/vendor/kreuzberg/tests/orgmode_extractor_tests.rs +822 -822
- data/vendor/kreuzberg/tests/page_markers.rs +297 -0
- data/vendor/kreuzberg/tests/pdf_hierarchy_detection.rs +301 -0
- data/vendor/kreuzberg/tests/pdf_hierarchy_quality.rs +589 -0
- data/vendor/kreuzberg/tests/pdf_integration.rs +45 -43
- data/vendor/kreuzberg/tests/pdf_ocr_triggering.rs +301 -0
- data/vendor/kreuzberg/tests/pdf_text_merging.rs +475 -0
- data/vendor/kreuzberg/tests/pdfium_linking.rs +340 -0
- data/vendor/kreuzberg/tests/pipeline_integration.rs +1446 -1411
- data/vendor/kreuzberg/tests/plugin_ocr_backend_test.rs +776 -771
- data/vendor/kreuzberg/tests/plugin_postprocessor_test.rs +577 -560
- data/vendor/kreuzberg/tests/plugin_system.rs +927 -921
- data/vendor/kreuzberg/tests/plugin_validator_test.rs +783 -783
- data/vendor/kreuzberg/tests/registry_integration_tests.rs +587 -586
- data/vendor/kreuzberg/tests/rst_extractor_tests.rs +694 -692
- data/vendor/kreuzberg/tests/rtf_extractor_tests.rs +775 -776
- data/vendor/kreuzberg/tests/security_validation.rs +416 -415
- data/vendor/kreuzberg/tests/stopwords_integration_test.rs +888 -888
- data/vendor/kreuzberg/tests/test_fastembed.rs +631 -609
- data/vendor/kreuzberg/tests/typst_behavioral_tests.rs +1260 -1259
- data/vendor/kreuzberg/tests/typst_extractor_tests.rs +648 -647
- data/vendor/kreuzberg/tests/xlsx_metadata_extraction_test.rs +87 -87
- data/vendor/kreuzberg-ffi/Cargo.toml +67 -0
- data/vendor/kreuzberg-ffi/README.md +851 -0
- data/vendor/kreuzberg-ffi/benches/result_view_benchmark.rs +227 -0
- data/vendor/kreuzberg-ffi/build.rs +168 -0
- data/vendor/kreuzberg-ffi/cbindgen.toml +37 -0
- data/vendor/kreuzberg-ffi/kreuzberg-ffi.pc.in +12 -0
- data/vendor/kreuzberg-ffi/kreuzberg.h +3012 -0
- data/vendor/kreuzberg-ffi/src/batch_streaming.rs +588 -0
- data/vendor/kreuzberg-ffi/src/config.rs +1341 -0
- data/vendor/kreuzberg-ffi/src/error.rs +901 -0
- data/vendor/kreuzberg-ffi/src/extraction.rs +555 -0
- data/vendor/kreuzberg-ffi/src/helpers.rs +879 -0
- data/vendor/kreuzberg-ffi/src/lib.rs +977 -0
- data/vendor/kreuzberg-ffi/src/memory.rs +493 -0
- data/vendor/kreuzberg-ffi/src/mime.rs +329 -0
- data/vendor/kreuzberg-ffi/src/panic_shield.rs +265 -0
- data/vendor/kreuzberg-ffi/src/plugins/document_extractor.rs +442 -0
- data/vendor/kreuzberg-ffi/src/plugins/mod.rs +14 -0
- data/vendor/kreuzberg-ffi/src/plugins/ocr_backend.rs +628 -0
- data/vendor/kreuzberg-ffi/src/plugins/post_processor.rs +438 -0
- data/vendor/kreuzberg-ffi/src/plugins/validator.rs +329 -0
- data/vendor/kreuzberg-ffi/src/result.rs +510 -0
- data/vendor/kreuzberg-ffi/src/result_pool.rs +639 -0
- data/vendor/kreuzberg-ffi/src/result_view.rs +773 -0
- data/vendor/kreuzberg-ffi/src/string_intern.rs +568 -0
- data/vendor/kreuzberg-ffi/src/types.rs +363 -0
- data/vendor/kreuzberg-ffi/src/util.rs +210 -0
- data/vendor/kreuzberg-ffi/src/validation.rs +848 -0
- data/vendor/kreuzberg-ffi/tests.disabled/README.md +48 -0
- data/vendor/kreuzberg-ffi/tests.disabled/config_loading_tests.rs +299 -0
- data/vendor/kreuzberg-ffi/tests.disabled/config_tests.rs +346 -0
- data/vendor/kreuzberg-ffi/tests.disabled/extractor_tests.rs +232 -0
- data/vendor/kreuzberg-ffi/tests.disabled/plugin_registration_tests.rs +470 -0
- data/vendor/kreuzberg-tesseract/.commitlintrc.json +13 -0
- data/vendor/kreuzberg-tesseract/.crate-ignore +2 -0
- data/vendor/kreuzberg-tesseract/Cargo.lock +2933 -0
- data/vendor/kreuzberg-tesseract/Cargo.toml +57 -0
- data/vendor/{rb-sys/LICENSE-MIT → kreuzberg-tesseract/LICENSE} +22 -21
- data/vendor/kreuzberg-tesseract/README.md +399 -0
- data/vendor/kreuzberg-tesseract/build.rs +1127 -0
- data/vendor/kreuzberg-tesseract/patches/README.md +71 -0
- data/vendor/kreuzberg-tesseract/patches/tesseract.diff +199 -0
- data/vendor/kreuzberg-tesseract/src/api.rs +1371 -0
- data/vendor/kreuzberg-tesseract/src/choice_iterator.rs +77 -0
- data/vendor/kreuzberg-tesseract/src/enums.rs +297 -0
- data/vendor/kreuzberg-tesseract/src/error.rs +81 -0
- data/vendor/kreuzberg-tesseract/src/lib.rs +145 -0
- data/vendor/kreuzberg-tesseract/src/monitor.rs +57 -0
- data/vendor/kreuzberg-tesseract/src/mutable_iterator.rs +197 -0
- data/vendor/kreuzberg-tesseract/src/page_iterator.rs +253 -0
- data/vendor/kreuzberg-tesseract/src/result_iterator.rs +286 -0
- data/vendor/kreuzberg-tesseract/src/result_renderer.rs +183 -0
- data/vendor/kreuzberg-tesseract/tests/integration_test.rs +211 -0
- metadata +196 -45
- data/vendor/kreuzberg/benches/otel_overhead.rs +0 -48
- data/vendor/kreuzberg/src/extractors/fictionbook.rs.backup2 +0 -738
- data/vendor/rb-sys/.cargo-ok +0 -1
- data/vendor/rb-sys/.cargo_vcs_info.json +0 -6
- data/vendor/rb-sys/Cargo.lock +0 -393
- data/vendor/rb-sys/Cargo.toml +0 -70
- data/vendor/rb-sys/Cargo.toml.orig +0 -57
- data/vendor/rb-sys/LICENSE-APACHE +0 -190
- data/vendor/rb-sys/bin/release.sh +0 -21
- data/vendor/rb-sys/build/features.rs +0 -108
- data/vendor/rb-sys/build/main.rs +0 -246
- data/vendor/rb-sys/build/stable_api_config.rs +0 -153
- data/vendor/rb-sys/build/version.rs +0 -48
- data/vendor/rb-sys/readme.md +0 -36
- data/vendor/rb-sys/src/bindings.rs +0 -21
- data/vendor/rb-sys/src/hidden.rs +0 -11
- data/vendor/rb-sys/src/lib.rs +0 -34
- data/vendor/rb-sys/src/macros.rs +0 -371
- data/vendor/rb-sys/src/memory.rs +0 -53
- data/vendor/rb-sys/src/ruby_abi_version.rs +0 -38
- data/vendor/rb-sys/src/special_consts.rs +0 -31
- data/vendor/rb-sys/src/stable_api/compiled.c +0 -179
- data/vendor/rb-sys/src/stable_api/compiled.rs +0 -257
- data/vendor/rb-sys/src/stable_api/ruby_2_6.rs +0 -316
- data/vendor/rb-sys/src/stable_api/ruby_2_7.rs +0 -316
- data/vendor/rb-sys/src/stable_api/ruby_3_0.rs +0 -324
- data/vendor/rb-sys/src/stable_api/ruby_3_1.rs +0 -317
- data/vendor/rb-sys/src/stable_api/ruby_3_2.rs +0 -315
- data/vendor/rb-sys/src/stable_api/ruby_3_3.rs +0 -326
- data/vendor/rb-sys/src/stable_api/ruby_3_4.rs +0 -327
- data/vendor/rb-sys/src/stable_api.rs +0 -261
- data/vendor/rb-sys/src/symbol.rs +0 -31
- data/vendor/rb-sys/src/tracking_allocator.rs +0 -332
- data/vendor/rb-sys/src/utils.rs +0 -89
- data/vendor/rb-sys/src/value_type.rs +0 -7
|
@@ -0,0 +1,1127 @@
|
|
|
1
|
+
#![allow(clippy::uninlined_format_args)]
|
|
2
|
+
|
|
3
|
+
#[cfg(feature = "build-tesseract")]
|
|
4
|
+
mod build_tesseract {
|
|
5
|
+
use cmake::Config;
|
|
6
|
+
use std::env;
|
|
7
|
+
use std::fs;
|
|
8
|
+
use std::path::{Path, PathBuf};
|
|
9
|
+
|
|
10
|
+
const LEPTONICA_VERSION: &str = "1.86.0";
|
|
11
|
+
const TESSERACT_VERSION: &str = "5.5.1";
|
|
12
|
+
#[allow(dead_code)]
|
|
13
|
+
const EMSDK_COMMIT: &str = "974d5c096bd56e42045d052a47b28198ce75e2a8";
|
|
14
|
+
#[allow(dead_code)]
|
|
15
|
+
const EMSDK_VERSION: &str = "3.1.31";
|
|
16
|
+
#[allow(dead_code)]
|
|
17
|
+
const EMSDK_REPOSITORY: &str = "https://github.com/emscripten-core/emsdk.git";
|
|
18
|
+
|
|
19
|
+
fn leptonica_url() -> String {
|
|
20
|
+
format!(
|
|
21
|
+
"https://codeload.github.com/DanBloomberg/leptonica/zip/refs/tags/{}",
|
|
22
|
+
LEPTONICA_VERSION
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
fn tesseract_url() -> String {
|
|
27
|
+
format!(
|
|
28
|
+
"https://codeload.github.com/tesseract-ocr/tesseract/zip/refs/tags/{}",
|
|
29
|
+
TESSERACT_VERSION
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
fn workspace_cache_dir_from_out_dir() -> Option<PathBuf> {
|
|
34
|
+
let out_dir = env::var_os("OUT_DIR")?;
|
|
35
|
+
let mut path = PathBuf::from(out_dir);
|
|
36
|
+
for _ in 0..4 {
|
|
37
|
+
if !path.pop() {
|
|
38
|
+
return None;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
Some(path.join("tesseract-rs-cache"))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fn get_preferred_out_dir() -> PathBuf {
|
|
45
|
+
if let Ok(custom) = env::var("TESSERACT_RS_CACHE_DIR") {
|
|
46
|
+
return PathBuf::from(custom);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if cfg!(target_os = "windows") {
|
|
50
|
+
return PathBuf::from("C:\\tess");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if let Some(workspace_cache) = workspace_cache_dir_from_out_dir() {
|
|
54
|
+
return workspace_cache;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if cfg!(target_os = "macos") {
|
|
58
|
+
let home_dir = env::var("HOME").unwrap_or_else(|_| {
|
|
59
|
+
env::var("USER")
|
|
60
|
+
.map(|user| format!("/Users/{}", user))
|
|
61
|
+
.expect("Neither HOME nor USER environment variable set")
|
|
62
|
+
});
|
|
63
|
+
PathBuf::from(home_dir)
|
|
64
|
+
.join("Library")
|
|
65
|
+
.join("Application Support")
|
|
66
|
+
.join("tesseract-rs")
|
|
67
|
+
} else if cfg!(target_os = "linux") {
|
|
68
|
+
let home_dir = env::var("HOME").unwrap_or_else(|_| {
|
|
69
|
+
env::var("USER")
|
|
70
|
+
.map(|user| format!("/home/{}", user))
|
|
71
|
+
.expect("Neither HOME nor USER environment variable set")
|
|
72
|
+
});
|
|
73
|
+
PathBuf::from(home_dir).join(".tesseract-rs")
|
|
74
|
+
} else {
|
|
75
|
+
panic!("Unsupported operating system");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
fn target_triple() -> String {
|
|
80
|
+
env::var("TARGET").unwrap_or_else(|_| env::var("HOST").unwrap_or_default())
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
fn target_matches(target: &str, needle: &str) -> bool {
|
|
84
|
+
target.contains(needle)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
fn is_windows_target(target: &str) -> bool {
|
|
88
|
+
target_matches(target, "windows")
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
fn is_macos_target(target: &str) -> bool {
|
|
92
|
+
target_matches(target, "apple-darwin")
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
fn is_linux_target(target: &str) -> bool {
|
|
96
|
+
target_matches(target, "linux")
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fn is_msvc_target(target: &str) -> bool {
|
|
100
|
+
is_windows_target(target) && target_matches(target, "msvc")
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
fn is_mingw_target(target: &str) -> bool {
|
|
104
|
+
is_windows_target(target) && target_matches(target, "gnu")
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
fn is_wasm_target(target: &str) -> bool {
|
|
108
|
+
target_matches(target, "wasm32") || target_matches(target, "wasm64")
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
fn prepare_out_dir() -> PathBuf {
|
|
112
|
+
let preferred = get_preferred_out_dir();
|
|
113
|
+
match fs::create_dir_all(&preferred) {
|
|
114
|
+
Ok(_) => preferred,
|
|
115
|
+
Err(err) => {
|
|
116
|
+
println!(
|
|
117
|
+
"cargo:warning=Failed to create cache dir {:?}: {}. Falling back to temp dir.",
|
|
118
|
+
preferred, err
|
|
119
|
+
);
|
|
120
|
+
let fallback = env::temp_dir().join("tesseract-rs-cache");
|
|
121
|
+
fs::create_dir_all(&fallback).expect("Failed to create fallback cache directory in temp dir");
|
|
122
|
+
fallback
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#[allow(dead_code)]
|
|
128
|
+
fn find_emsdk() -> Result<PathBuf, String> {
|
|
129
|
+
if let Ok(emsdk_path) = env::var("EMSDK") {
|
|
130
|
+
let path = PathBuf::from(emsdk_path);
|
|
131
|
+
if path.exists() {
|
|
132
|
+
return Ok(path);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let common_paths = vec![
|
|
137
|
+
PathBuf::from("/opt/homebrew/opt/emscripten"),
|
|
138
|
+
PathBuf::from("/usr/local/opt/emscripten"),
|
|
139
|
+
PathBuf::from(env::var("HOME").unwrap_or_default()).join(".emsdk"),
|
|
140
|
+
PathBuf::from("/usr/lib/emscripten"),
|
|
141
|
+
PathBuf::from("/opt/emsdk"),
|
|
142
|
+
];
|
|
143
|
+
|
|
144
|
+
for path in common_paths {
|
|
145
|
+
if path.exists() {
|
|
146
|
+
return Ok(path);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
Err("EMSDK not found. Please install via: brew install emscripten (macOS) or apt-get install emscripten (Linux)".to_string())
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
pub fn build() {
|
|
154
|
+
let target = target_triple();
|
|
155
|
+
|
|
156
|
+
if is_wasm_target(&target) {
|
|
157
|
+
println!(
|
|
158
|
+
"cargo:warning=Detected WASM target: {}, routing to build_wasm()",
|
|
159
|
+
target
|
|
160
|
+
);
|
|
161
|
+
return build_wasm();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let custom_out_dir = prepare_out_dir();
|
|
165
|
+
let windows_target = is_windows_target(&target);
|
|
166
|
+
let msvc_target = is_msvc_target(&target);
|
|
167
|
+
let mingw_target = is_mingw_target(&target);
|
|
168
|
+
|
|
169
|
+
println!("cargo:warning=custom_out_dir: {:?}", custom_out_dir);
|
|
170
|
+
|
|
171
|
+
let cache_dir = custom_out_dir.join("cache");
|
|
172
|
+
|
|
173
|
+
if env::var("CARGO_CLEAN").is_ok() {
|
|
174
|
+
clean_cache(&cache_dir);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
std::fs::create_dir_all(&cache_dir).expect("Failed to create cache directory");
|
|
178
|
+
|
|
179
|
+
let out_dir = custom_out_dir.clone();
|
|
180
|
+
let project_dir = custom_out_dir.clone();
|
|
181
|
+
let third_party_dir = project_dir.join("third_party");
|
|
182
|
+
|
|
183
|
+
let leptonica_dir = if third_party_dir.join("leptonica").exists() {
|
|
184
|
+
println!("cargo:warning=Using existing leptonica source");
|
|
185
|
+
third_party_dir.join("leptonica")
|
|
186
|
+
} else {
|
|
187
|
+
fs::create_dir_all(&third_party_dir).expect("Failed to create third_party directory");
|
|
188
|
+
download_and_extract(&third_party_dir, &leptonica_url(), "leptonica")
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
let tesseract_dir = if third_party_dir.join("tesseract").exists() {
|
|
192
|
+
println!("cargo:warning=Using existing tesseract source");
|
|
193
|
+
third_party_dir.join("tesseract")
|
|
194
|
+
} else {
|
|
195
|
+
fs::create_dir_all(&third_party_dir).expect("Failed to create third_party directory");
|
|
196
|
+
download_and_extract(&third_party_dir, &tesseract_url(), "tesseract")
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
let (cmake_cxx_flags, additional_defines) = get_os_specific_config();
|
|
200
|
+
|
|
201
|
+
let leptonica_install_dir = out_dir.join("leptonica");
|
|
202
|
+
let leptonica_cache_dir = cache_dir.join("leptonica");
|
|
203
|
+
|
|
204
|
+
let leptonica_link_name = build_or_use_cached(
|
|
205
|
+
"leptonica",
|
|
206
|
+
&leptonica_cache_dir,
|
|
207
|
+
&leptonica_install_dir,
|
|
208
|
+
|| {
|
|
209
|
+
let mut leptonica_config = Config::new(&leptonica_dir);
|
|
210
|
+
|
|
211
|
+
let leptonica_src_dir = leptonica_dir.join("src");
|
|
212
|
+
let environ_h_path = leptonica_src_dir.join("environ.h");
|
|
213
|
+
|
|
214
|
+
if environ_h_path.exists() {
|
|
215
|
+
let environ_h = std::fs::read_to_string(&environ_h_path)
|
|
216
|
+
.expect("Failed to read environ.h")
|
|
217
|
+
.replace("#define HAVE_LIBZ 1", "#define HAVE_LIBZ 0")
|
|
218
|
+
.replace("#ifdef NO_CONSOLE_IO", "#define NO_CONSOLE_IO\n#ifdef NO_CONSOLE_IO");
|
|
219
|
+
std::fs::write(environ_h_path, environ_h).expect("Failed to write environ.h");
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
let makefile_static_path = leptonica_dir.join("prog").join("makefile.static");
|
|
223
|
+
|
|
224
|
+
let leptonica_src_cmakelists = leptonica_dir.join("src").join("CMakeLists.txt");
|
|
225
|
+
|
|
226
|
+
if leptonica_src_cmakelists.exists() {
|
|
227
|
+
let cmakelists = std::fs::read_to_string(&leptonica_src_cmakelists)
|
|
228
|
+
.expect("Failed to read leptonica src CMakeLists.txt");
|
|
229
|
+
let patched = cmakelists.replace(
|
|
230
|
+
"if(MINGW)\n set_target_properties(\n leptonica PROPERTIES SUFFIX\n \"-${PROJECT_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}\")\nendif(MINGW)\n",
|
|
231
|
+
"if(MINGW AND BUILD_SHARED_LIBS)\n set_target_properties(\n leptonica PROPERTIES SUFFIX\n \"-${PROJECT_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}\")\nendif()\n",
|
|
232
|
+
);
|
|
233
|
+
if patched != cmakelists {
|
|
234
|
+
std::fs::write(&leptonica_src_cmakelists, patched)
|
|
235
|
+
.expect("Failed to patch leptonica src CMakeLists.txt");
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if makefile_static_path.exists() {
|
|
240
|
+
let makefile_static = std::fs::read_to_string(&makefile_static_path)
|
|
241
|
+
.expect("Failed to read makefile.static")
|
|
242
|
+
.replace(
|
|
243
|
+
"ALL_LIBS = $(LEPTLIB) -ltiff -ljpeg -lpng -lz -lm",
|
|
244
|
+
"ALL_LIBS = $(LEPTLIB) -lm",
|
|
245
|
+
);
|
|
246
|
+
std::fs::write(makefile_static_path, makefile_static).expect("Failed to write makefile.static");
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if windows_target {
|
|
250
|
+
if mingw_target {
|
|
251
|
+
leptonica_config.generator("Unix Makefiles");
|
|
252
|
+
leptonica_config.define("CMAKE_MAKE_PROGRAM", "mingw32-make");
|
|
253
|
+
leptonica_config.define("MSYS2_ARG_CONV_EXCL", "/MD;/MDd;/D;-D;-I;-L");
|
|
254
|
+
} else if msvc_target && env::var("VSINSTALLDIR").is_ok() {
|
|
255
|
+
leptonica_config.generator("NMake Makefiles");
|
|
256
|
+
}
|
|
257
|
+
leptonica_config.define("CMAKE_CL_SHOWINCLUDES_PREFIX", "");
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if env::var("CI").is_err() && env::var("RUSTC_WRAPPER").unwrap_or_default() == "sccache" {
|
|
261
|
+
leptonica_config.env("CC", "sccache cc").env("CXX", "sccache c++");
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
let leptonica_install_dir_cmake = normalize_cmake_path(&leptonica_install_dir);
|
|
265
|
+
|
|
266
|
+
leptonica_config
|
|
267
|
+
.define("CMAKE_POLICY_VERSION_MINIMUM", "3.5")
|
|
268
|
+
.define("CMAKE_BUILD_TYPE", "Release")
|
|
269
|
+
.define("BUILD_PROG", "OFF")
|
|
270
|
+
.define("BUILD_SHARED_LIBS", "OFF")
|
|
271
|
+
.define("ENABLE_ZLIB", "OFF")
|
|
272
|
+
.define("ENABLE_PNG", "OFF")
|
|
273
|
+
.define("ENABLE_JPEG", "OFF")
|
|
274
|
+
.define("ENABLE_TIFF", "OFF")
|
|
275
|
+
.define("ENABLE_WEBP", "OFF")
|
|
276
|
+
.define("ENABLE_OPENJPEG", "OFF")
|
|
277
|
+
.define("ENABLE_GIF", "OFF")
|
|
278
|
+
.define("NO_CONSOLE_IO", "ON")
|
|
279
|
+
.define("CMAKE_CXX_FLAGS", &cmake_cxx_flags)
|
|
280
|
+
.define("MINIMUM_SEVERITY", "L_SEVERITY_NONE")
|
|
281
|
+
.define("SW_BUILD", "OFF")
|
|
282
|
+
.define("HAVE_LIBZ", "0")
|
|
283
|
+
.define("ENABLE_LTO", "OFF")
|
|
284
|
+
.define("CMAKE_INSTALL_PREFIX", &leptonica_install_dir_cmake);
|
|
285
|
+
|
|
286
|
+
if windows_target {
|
|
287
|
+
if msvc_target {
|
|
288
|
+
leptonica_config
|
|
289
|
+
.define("CMAKE_C_FLAGS_RELEASE", "/MD /O2")
|
|
290
|
+
.define("CMAKE_C_FLAGS_DEBUG", "/MDd /Od");
|
|
291
|
+
} else if mingw_target {
|
|
292
|
+
leptonica_config
|
|
293
|
+
.define("CMAKE_C_FLAGS_RELEASE", "-O2 -DNDEBUG")
|
|
294
|
+
.define("CMAKE_C_FLAGS_DEBUG", "-O0 -g");
|
|
295
|
+
} else {
|
|
296
|
+
leptonica_config
|
|
297
|
+
.define("CMAKE_C_FLAGS_RELEASE", "-O2")
|
|
298
|
+
.define("CMAKE_C_FLAGS_DEBUG", "-O0 -g");
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
for (key, value) in &additional_defines {
|
|
303
|
+
leptonica_config.define(key, value);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
leptonica_config.build();
|
|
307
|
+
},
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
let leptonica_include_dir = leptonica_install_dir.join("include");
|
|
311
|
+
let leptonica_lib_dir = leptonica_install_dir.join("lib");
|
|
312
|
+
let tesseract_install_dir = out_dir.join("tesseract");
|
|
313
|
+
let tesseract_cache_dir = cache_dir.join("tesseract");
|
|
314
|
+
let tessdata_prefix = project_dir.clone();
|
|
315
|
+
|
|
316
|
+
let leptonica_install_dir_cmake = normalize_cmake_path(&leptonica_install_dir);
|
|
317
|
+
let leptonica_include_dir_cmake = normalize_cmake_path(&leptonica_include_dir);
|
|
318
|
+
let leptonica_lib_dir_cmake = normalize_cmake_path(&leptonica_lib_dir);
|
|
319
|
+
let tesseract_install_dir_cmake = normalize_cmake_path(&tesseract_install_dir);
|
|
320
|
+
let tessdata_prefix_cmake = normalize_cmake_path(&tessdata_prefix);
|
|
321
|
+
|
|
322
|
+
let tesseract_link_name =
|
|
323
|
+
build_or_use_cached("tesseract", &tesseract_cache_dir, &tesseract_install_dir, || {
|
|
324
|
+
let cmakelists_path = tesseract_dir.join("CMakeLists.txt");
|
|
325
|
+
let cmakelists = std::fs::read_to_string(&cmakelists_path)
|
|
326
|
+
.expect("Failed to read CMakeLists.txt")
|
|
327
|
+
.replace("set(HAVE_TIFFIO_H ON)", "");
|
|
328
|
+
std::fs::write(&cmakelists_path, cmakelists).expect("Failed to write CMakeLists.txt");
|
|
329
|
+
|
|
330
|
+
let mut tesseract_config = Config::new(&tesseract_dir);
|
|
331
|
+
if windows_target {
|
|
332
|
+
if mingw_target {
|
|
333
|
+
tesseract_config.generator("Unix Makefiles");
|
|
334
|
+
tesseract_config.define("CMAKE_MAKE_PROGRAM", "mingw32-make");
|
|
335
|
+
tesseract_config.define("MSYS2_ARG_CONV_EXCL", "/MD;/MDd;/D;-D;-I;-L");
|
|
336
|
+
} else if msvc_target && env::var("VSINSTALLDIR").is_ok() {
|
|
337
|
+
tesseract_config.generator("NMake Makefiles");
|
|
338
|
+
}
|
|
339
|
+
tesseract_config.define("CMAKE_CL_SHOWINCLUDES_PREFIX", "");
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if env::var("CI").is_err() && env::var("RUSTC_WRAPPER").unwrap_or_default() == "sccache" {
|
|
343
|
+
tesseract_config.env("CC", "sccache cc").env("CXX", "sccache c++");
|
|
344
|
+
}
|
|
345
|
+
tesseract_config
|
|
346
|
+
.define("CMAKE_POLICY_VERSION_MINIMUM", "3.5")
|
|
347
|
+
.define("CMAKE_BUILD_TYPE", "Release")
|
|
348
|
+
.define("BUILD_TRAINING_TOOLS", "OFF")
|
|
349
|
+
.define("BUILD_SHARED_LIBS", "OFF")
|
|
350
|
+
.define("DISABLE_ARCHIVE", "ON")
|
|
351
|
+
.define("DISABLE_CURL", "ON")
|
|
352
|
+
.define("DISABLE_OPENCL", "ON")
|
|
353
|
+
.define("Leptonica_DIR", &leptonica_install_dir_cmake)
|
|
354
|
+
.define("LEPTONICA_INCLUDE_DIR", &leptonica_include_dir_cmake)
|
|
355
|
+
.define("LEPTONICA_LIBRARY", &leptonica_lib_dir_cmake)
|
|
356
|
+
.define("CMAKE_PREFIX_PATH", &leptonica_install_dir_cmake)
|
|
357
|
+
.define("CMAKE_INSTALL_PREFIX", &tesseract_install_dir_cmake)
|
|
358
|
+
.define("TESSDATA_PREFIX", &tessdata_prefix_cmake)
|
|
359
|
+
.define("DISABLE_TIFF", "ON")
|
|
360
|
+
.define("DISABLE_PNG", "ON")
|
|
361
|
+
.define("DISABLE_JPEG", "ON")
|
|
362
|
+
.define("DISABLE_WEBP", "ON")
|
|
363
|
+
.define("DISABLE_OPENJPEG", "ON")
|
|
364
|
+
.define("DISABLE_ZLIB", "ON")
|
|
365
|
+
.define("DISABLE_LIBXML2", "ON")
|
|
366
|
+
.define("DISABLE_LIBICU", "ON")
|
|
367
|
+
.define("DISABLE_LZMA", "ON")
|
|
368
|
+
.define("DISABLE_GIF", "ON")
|
|
369
|
+
.define("DISABLE_DEBUG_MESSAGES", "ON")
|
|
370
|
+
.define("debug_file", "/dev/null")
|
|
371
|
+
.define("HAVE_LIBARCHIVE", "OFF")
|
|
372
|
+
.define("HAVE_LIBCURL", "OFF")
|
|
373
|
+
.define("HAVE_TIFFIO_H", "OFF")
|
|
374
|
+
.define("GRAPHICS_DISABLED", "ON")
|
|
375
|
+
.define("DISABLED_LEGACY_ENGINE", "OFF")
|
|
376
|
+
.define("USE_OPENCL", "OFF")
|
|
377
|
+
.define("OPENMP_BUILD", "OFF")
|
|
378
|
+
.define("BUILD_TESTS", "OFF")
|
|
379
|
+
.define("ENABLE_LTO", "OFF")
|
|
380
|
+
.define("BUILD_PROG", "OFF")
|
|
381
|
+
.define("SW_BUILD", "OFF")
|
|
382
|
+
.define("LEPT_TIFF_RESULT", "FALSE")
|
|
383
|
+
.define("INSTALL_CONFIGS", "ON")
|
|
384
|
+
.define("USE_SYSTEM_ICU", "ON")
|
|
385
|
+
.define("CMAKE_CXX_FLAGS", &cmake_cxx_flags);
|
|
386
|
+
|
|
387
|
+
for (key, value) in &additional_defines {
|
|
388
|
+
tesseract_config.define(key, value);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
tesseract_config.build();
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
println!("cargo:rerun-if-changed=build.rs");
|
|
395
|
+
println!("cargo:rerun-if-changed={}", third_party_dir.display());
|
|
396
|
+
println!("cargo:rerun-if-changed={}", leptonica_dir.display());
|
|
397
|
+
println!("cargo:rerun-if-changed={}", tesseract_dir.display());
|
|
398
|
+
|
|
399
|
+
println!("cargo:rustc-link-search=native={}", leptonica_lib_dir.display());
|
|
400
|
+
println!(
|
|
401
|
+
"cargo:rustc-link-search=native={}",
|
|
402
|
+
tesseract_install_dir.join("lib").display()
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
// Link libraries in the correct order for static linking:
|
|
406
|
+
// 1. tesseract first (depends on leptonica and C++ stdlib)
|
|
407
|
+
// 2. leptonica (depends on C++ stdlib)
|
|
408
|
+
// 3. C++ standard library and system libraries (via set_os_specific_link_flags)
|
|
409
|
+
//
|
|
410
|
+
// IMPORTANT: For static linking, the linker resolves symbols in order.
|
|
411
|
+
// Libraries must be listed BEFORE the libraries they depend on.
|
|
412
|
+
// The C++ stdlib must come LAST because both tesseract and leptonica
|
|
413
|
+
// depend on it for symbols like operator new, operator delete, etc.
|
|
414
|
+
#[cfg(feature = "dynamic-linking")]
|
|
415
|
+
let link_type = "dylib";
|
|
416
|
+
#[cfg(not(feature = "dynamic-linking"))]
|
|
417
|
+
let link_type = "static";
|
|
418
|
+
|
|
419
|
+
println!("cargo:rustc-link-lib={}={}", link_type, tesseract_link_name);
|
|
420
|
+
println!(
|
|
421
|
+
"cargo:warning=Linking with tesseract ({} linking): {}",
|
|
422
|
+
link_type, tesseract_link_name
|
|
423
|
+
);
|
|
424
|
+
println!("cargo:rustc-link-lib={}={}", link_type, leptonica_link_name);
|
|
425
|
+
println!(
|
|
426
|
+
"cargo:warning=Linking with leptonica ({} linking): {}",
|
|
427
|
+
link_type, leptonica_link_name
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
// Link C++ standard library and system libraries AFTER tesseract and leptonica.
|
|
431
|
+
// This is critical for static linking on Linux (especially aarch64) where
|
|
432
|
+
// tesseract's C++ code needs symbols like operator new/delete from libstdc++.
|
|
433
|
+
set_os_specific_link_flags();
|
|
434
|
+
|
|
435
|
+
println!("cargo:warning=Leptonica include dir: {:?}", leptonica_include_dir);
|
|
436
|
+
println!("cargo:warning=Leptonica lib dir: {:?}", leptonica_lib_dir);
|
|
437
|
+
println!("cargo:warning=Tesseract install dir: {:?}", tesseract_install_dir);
|
|
438
|
+
println!("cargo:warning=Tessdata dir: {:?}", tessdata_prefix);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
fn get_os_specific_config() -> (String, Vec<(String, String)>) {
|
|
442
|
+
let mut cmake_cxx_flags = String::new();
|
|
443
|
+
let mut additional_defines = Vec::new();
|
|
444
|
+
let target = target_triple();
|
|
445
|
+
let target_macos = is_macos_target(&target);
|
|
446
|
+
let target_linux = is_linux_target(&target);
|
|
447
|
+
let target_windows = is_windows_target(&target);
|
|
448
|
+
let target_msvc = is_msvc_target(&target);
|
|
449
|
+
let target_mingw = is_mingw_target(&target);
|
|
450
|
+
let target_musl = target.contains("musl");
|
|
451
|
+
|
|
452
|
+
if target_macos {
|
|
453
|
+
cmake_cxx_flags.push_str("-stdlib=libc++ ");
|
|
454
|
+
cmake_cxx_flags.push_str("-std=c++17 ");
|
|
455
|
+
} else if target_linux {
|
|
456
|
+
cmake_cxx_flags.push_str("-std=c++17 ");
|
|
457
|
+
if target_musl || env::var("CC").map(|cc| cc.contains("clang")).unwrap_or(false) {
|
|
458
|
+
cmake_cxx_flags.push_str("-stdlib=libc++ ");
|
|
459
|
+
let cxx_compiler = env::var("CXX").unwrap_or_else(|_| {
|
|
460
|
+
if let Ok(target) = env::var("TARGET") {
|
|
461
|
+
if target != env::var("HOST").unwrap_or_default() {
|
|
462
|
+
format!("{}-clang++", target)
|
|
463
|
+
} else {
|
|
464
|
+
"clang++".to_string()
|
|
465
|
+
}
|
|
466
|
+
} else {
|
|
467
|
+
"clang++".to_string()
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
additional_defines.push(("CMAKE_CXX_COMPILER".to_string(), cxx_compiler));
|
|
471
|
+
} else {
|
|
472
|
+
let cxx_compiler = env::var("CXX").unwrap_or_else(|_| {
|
|
473
|
+
if let Ok(target) = env::var("TARGET") {
|
|
474
|
+
if target != env::var("HOST").unwrap_or_default() {
|
|
475
|
+
format!("{}-g++", target)
|
|
476
|
+
} else {
|
|
477
|
+
"g++".to_string()
|
|
478
|
+
}
|
|
479
|
+
} else {
|
|
480
|
+
"g++".to_string()
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
additional_defines.push(("CMAKE_CXX_COMPILER".to_string(), cxx_compiler));
|
|
484
|
+
}
|
|
485
|
+
} else if target_windows {
|
|
486
|
+
if target_msvc {
|
|
487
|
+
cmake_cxx_flags.push_str("/EHsc /MP /std:c++17 /DTESSERACT_STATIC ");
|
|
488
|
+
additional_defines.push(("CMAKE_C_FLAGS_RELEASE".to_string(), "/MD /O2".to_string()));
|
|
489
|
+
additional_defines.push(("CMAKE_C_FLAGS_DEBUG".to_string(), "/MDd /Od".to_string()));
|
|
490
|
+
additional_defines.push((
|
|
491
|
+
"CMAKE_CXX_FLAGS_RELEASE".to_string(),
|
|
492
|
+
"/MD /O2 /DTESSERACT_STATIC".to_string(),
|
|
493
|
+
));
|
|
494
|
+
additional_defines.push((
|
|
495
|
+
"CMAKE_CXX_FLAGS_DEBUG".to_string(),
|
|
496
|
+
"/MDd /Od /DTESSERACT_STATIC".to_string(),
|
|
497
|
+
));
|
|
498
|
+
additional_defines.push(("CMAKE_MSVC_RUNTIME_LIBRARY".to_string(), "MultiThreadedDLL".to_string()));
|
|
499
|
+
} else if target_mingw {
|
|
500
|
+
cmake_cxx_flags.push_str("-std=c++17 -DTESSERACT_STATIC ");
|
|
501
|
+
additional_defines.push(("CMAKE_C_FLAGS_RELEASE".to_string(), "-O2 -DNDEBUG".to_string()));
|
|
502
|
+
additional_defines.push(("CMAKE_C_FLAGS_DEBUG".to_string(), "-O0 -g".to_string()));
|
|
503
|
+
additional_defines.push(("CMAKE_C_COMPILER".to_string(), "gcc".to_string()));
|
|
504
|
+
additional_defines.push(("CMAKE_CXX_COMPILER".to_string(), "g++".to_string()));
|
|
505
|
+
additional_defines.push(("CMAKE_SYSTEM_NAME".to_string(), "Windows".to_string()));
|
|
506
|
+
additional_defines.push((
|
|
507
|
+
"CMAKE_CXX_FLAGS_RELEASE".to_string(),
|
|
508
|
+
"-O2 -DNDEBUG -DTESSERACT_STATIC".to_string(),
|
|
509
|
+
));
|
|
510
|
+
additional_defines.push((
|
|
511
|
+
"CMAKE_CXX_FLAGS_DEBUG".to_string(),
|
|
512
|
+
"-O0 -g -DTESSERACT_STATIC".to_string(),
|
|
513
|
+
));
|
|
514
|
+
} else {
|
|
515
|
+
cmake_cxx_flags.push_str("-std=c++17 -DTESSERACT_STATIC ");
|
|
516
|
+
additional_defines.push(("CMAKE_C_FLAGS_RELEASE".to_string(), "-O2 -DNDEBUG".to_string()));
|
|
517
|
+
additional_defines.push(("CMAKE_C_FLAGS_DEBUG".to_string(), "-O0 -g".to_string()));
|
|
518
|
+
additional_defines.push((
|
|
519
|
+
"CMAKE_CXX_FLAGS_RELEASE".to_string(),
|
|
520
|
+
"-O2 -DNDEBUG -DTESSERACT_STATIC".to_string(),
|
|
521
|
+
));
|
|
522
|
+
additional_defines.push((
|
|
523
|
+
"CMAKE_CXX_FLAGS_DEBUG".to_string(),
|
|
524
|
+
"-O0 -g -DTESSERACT_STATIC".to_string(),
|
|
525
|
+
));
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
cmake_cxx_flags.push_str("-DUSE_STD_NAMESPACE ");
|
|
530
|
+
additional_defines.push(("CMAKE_POSITION_INDEPENDENT_CODE".to_string(), "ON".to_string()));
|
|
531
|
+
|
|
532
|
+
if target_windows && target_msvc {
|
|
533
|
+
cmake_cxx_flags.push_str("/permissive- ");
|
|
534
|
+
additional_defines.push(("CMAKE_EXE_LINKER_FLAGS".to_string(), "/INCREMENTAL:NO".to_string()));
|
|
535
|
+
additional_defines.push(("CMAKE_SHARED_LINKER_FLAGS".to_string(), "/INCREMENTAL:NO".to_string()));
|
|
536
|
+
additional_defines.push(("CMAKE_MODULE_LINKER_FLAGS".to_string(), "/INCREMENTAL:NO".to_string()));
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
(cmake_cxx_flags, additional_defines)
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
fn set_os_specific_link_flags() {
|
|
543
|
+
let target = target_triple();
|
|
544
|
+
let target_macos = is_macos_target(&target);
|
|
545
|
+
let target_linux = is_linux_target(&target);
|
|
546
|
+
let target_windows = is_windows_target(&target);
|
|
547
|
+
let target_mingw = is_mingw_target(&target);
|
|
548
|
+
let target_musl = target.contains("musl");
|
|
549
|
+
|
|
550
|
+
if target_macos {
|
|
551
|
+
println!("cargo:rustc-link-lib=c++");
|
|
552
|
+
} else if target_linux {
|
|
553
|
+
if target_musl || env::var("CC").map(|cc| cc.contains("clang")).unwrap_or(false) {
|
|
554
|
+
println!("cargo:rustc-link-lib=c++");
|
|
555
|
+
} else {
|
|
556
|
+
println!("cargo:rustc-link-lib=stdc++");
|
|
557
|
+
println!("cargo:rustc-link-lib=stdc++fs");
|
|
558
|
+
}
|
|
559
|
+
println!("cargo:rustc-link-lib=pthread");
|
|
560
|
+
println!("cargo:rustc-link-lib=m");
|
|
561
|
+
println!("cargo:rustc-link-lib=dl");
|
|
562
|
+
} else if target_windows {
|
|
563
|
+
if target_mingw {
|
|
564
|
+
println!("cargo:rustc-link-lib=stdc++");
|
|
565
|
+
}
|
|
566
|
+
println!("cargo:rustc-link-lib=user32");
|
|
567
|
+
println!("cargo:rustc-link-lib=gdi32");
|
|
568
|
+
println!("cargo:rustc-link-lib=ws2_32");
|
|
569
|
+
println!("cargo:rustc-link-lib=advapi32");
|
|
570
|
+
println!("cargo:rustc-link-lib=shell32");
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
println!("cargo:rustc-link-search=native={}", env::var("OUT_DIR").unwrap());
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
fn download_and_extract(target_dir: &Path, url: &str, name: &str) -> PathBuf {
|
|
577
|
+
use zip::ZipArchive;
|
|
578
|
+
|
|
579
|
+
fs::create_dir_all(target_dir).expect("Failed to create target directory");
|
|
580
|
+
|
|
581
|
+
let client = reqwest::blocking::Client::builder()
|
|
582
|
+
.timeout(std::time::Duration::from_secs(300))
|
|
583
|
+
.http1_only()
|
|
584
|
+
.build()
|
|
585
|
+
.expect("Failed to create HTTP client");
|
|
586
|
+
|
|
587
|
+
println!("cargo:warning=Downloading {} from {}", name, url);
|
|
588
|
+
let max_attempts = 5;
|
|
589
|
+
let mut content = None;
|
|
590
|
+
|
|
591
|
+
for attempt in 1..=max_attempts {
|
|
592
|
+
let err_msg = match client.get(url).send() {
|
|
593
|
+
Ok(resp) => {
|
|
594
|
+
if resp.status().is_success() {
|
|
595
|
+
match resp.bytes() {
|
|
596
|
+
Ok(bytes) => {
|
|
597
|
+
content = Some(bytes.to_vec());
|
|
598
|
+
break;
|
|
599
|
+
}
|
|
600
|
+
Err(err) => format!("Failed to read response: {}", err),
|
|
601
|
+
}
|
|
602
|
+
} else {
|
|
603
|
+
format!("HTTP {}", resp.status().as_u16())
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
Err(err) => err.to_string(),
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
if attempt == max_attempts {
|
|
610
|
+
panic!(
|
|
611
|
+
"Failed to download {} after {} attempts: {}",
|
|
612
|
+
name, max_attempts, err_msg
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
let backoff = 2u64.pow((attempt - 1).min(4));
|
|
617
|
+
println!(
|
|
618
|
+
"cargo:warning=Download attempt {}/{} for {} failed ({}). Retrying in {}s...",
|
|
619
|
+
attempt, max_attempts, name, err_msg, backoff
|
|
620
|
+
);
|
|
621
|
+
std::thread::sleep(std::time::Duration::from_secs(backoff));
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
let content = content.expect("unreachable: download loop must either succeed or panic");
|
|
625
|
+
|
|
626
|
+
println!("cargo:warning=Downloaded {} bytes for {}", content.len(), name);
|
|
627
|
+
|
|
628
|
+
let temp_file = target_dir.join(format!("{}.zip", name));
|
|
629
|
+
fs::write(&temp_file, content).expect("Failed to write archive to file");
|
|
630
|
+
|
|
631
|
+
let extract_dir = target_dir.join(name);
|
|
632
|
+
if extract_dir.exists() {
|
|
633
|
+
fs::remove_dir_all(&extract_dir).expect("Failed to remove existing directory");
|
|
634
|
+
}
|
|
635
|
+
fs::create_dir_all(&extract_dir).expect("Failed to create extraction directory");
|
|
636
|
+
|
|
637
|
+
let mut archive = ZipArchive::new(fs::File::open(&temp_file).unwrap()).unwrap();
|
|
638
|
+
|
|
639
|
+
for i in 0..archive.len() {
|
|
640
|
+
let mut file = archive.by_index(i).unwrap();
|
|
641
|
+
let file_path = file.mangled_name();
|
|
642
|
+
let file_path = file_path.to_str().unwrap();
|
|
643
|
+
|
|
644
|
+
let path = Path::new(file_path);
|
|
645
|
+
let path = path.strip_prefix(path.components().next().unwrap()).unwrap();
|
|
646
|
+
|
|
647
|
+
if path.as_os_str().is_empty() {
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
let target_path = extract_dir.join(path);
|
|
652
|
+
|
|
653
|
+
if file.is_dir() {
|
|
654
|
+
fs::create_dir_all(target_path).unwrap();
|
|
655
|
+
} else {
|
|
656
|
+
if let Some(parent) = target_path.parent() {
|
|
657
|
+
fs::create_dir_all(parent).unwrap();
|
|
658
|
+
}
|
|
659
|
+
let mut outfile = fs::File::create(target_path).unwrap();
|
|
660
|
+
std::io::copy(&mut file, &mut outfile).unwrap();
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
fs::remove_file(temp_file).expect("Failed to remove temporary zip file");
|
|
665
|
+
|
|
666
|
+
extract_dir
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
fn normalize_cmake_path(path: &Path) -> String {
|
|
670
|
+
path.to_string_lossy().replace('\\', "/")
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
fn clean_cache(cache_dir: &Path) {
|
|
674
|
+
println!("Cleaning cache directory: {:?}", cache_dir);
|
|
675
|
+
if cache_dir.exists() {
|
|
676
|
+
fs::remove_dir_all(cache_dir).expect("Failed to remove cache directory");
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
#[allow(dead_code)]
|
|
681
|
+
fn apply_patches(src_dir: &Path, patch_dir: &Path) -> std::io::Result<()> {
|
|
682
|
+
use std::process::Command;
|
|
683
|
+
|
|
684
|
+
let patch_file = patch_dir.join("tesseract.diff");
|
|
685
|
+
if !patch_file.exists() {
|
|
686
|
+
println!("cargo:warning=Patch file not found: {}", patch_file.display());
|
|
687
|
+
return Ok(());
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
println!("cargo:warning=Applying patches from: {}", patch_file.display());
|
|
691
|
+
|
|
692
|
+
let output = Command::new("patch")
|
|
693
|
+
.arg("-p1")
|
|
694
|
+
.current_dir(src_dir)
|
|
695
|
+
.stdin(fs::File::open(&patch_file)?)
|
|
696
|
+
.output()?;
|
|
697
|
+
|
|
698
|
+
if !output.status.success() {
|
|
699
|
+
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
700
|
+
println!("cargo:warning=Patch output: {}", stderr);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
Ok(())
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
#[allow(dead_code)]
|
|
707
|
+
fn setup_emsdk_environment(emsdk_root: &Path) {
|
|
708
|
+
let emsdk_root_str = emsdk_root.to_string_lossy().to_string();
|
|
709
|
+
|
|
710
|
+
unsafe {
|
|
711
|
+
env::set_var("EMSDK", &emsdk_root_str);
|
|
712
|
+
}
|
|
713
|
+
println!("cargo:warning=Set EMSDK={}", emsdk_root_str);
|
|
714
|
+
|
|
715
|
+
let emscripten_path = format!("{}/upstream/emscripten", emsdk_root_str);
|
|
716
|
+
unsafe {
|
|
717
|
+
env::set_var("EMSCRIPTEN", &emscripten_path);
|
|
718
|
+
}
|
|
719
|
+
println!("cargo:warning=Set EMSCRIPTEN={}", emscripten_path);
|
|
720
|
+
|
|
721
|
+
let em_config = format!("{}/.emscripten", emsdk_root_str);
|
|
722
|
+
unsafe {
|
|
723
|
+
env::set_var("EM_CONFIG", &em_config);
|
|
724
|
+
}
|
|
725
|
+
println!("cargo:warning=Set EM_CONFIG={}", em_config);
|
|
726
|
+
|
|
727
|
+
let emsdk_bin_paths = [
|
|
728
|
+
format!("{}/upstream/emscripten", emsdk_root_str),
|
|
729
|
+
format!("{}/upstream/bin", emsdk_root_str),
|
|
730
|
+
];
|
|
731
|
+
|
|
732
|
+
let current_path = env::var("PATH").unwrap_or_default();
|
|
733
|
+
let new_path = format!(
|
|
734
|
+
"{}{}{}",
|
|
735
|
+
emsdk_bin_paths.join(":"),
|
|
736
|
+
if current_path.is_empty() { "" } else { ":" },
|
|
737
|
+
current_path
|
|
738
|
+
);
|
|
739
|
+
unsafe {
|
|
740
|
+
env::set_var("PATH", &new_path);
|
|
741
|
+
}
|
|
742
|
+
println!("cargo:warning=Updated PATH with EMSDK tools");
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
#[allow(dead_code)]
|
|
746
|
+
fn build_leptonica_wasm(leptonica_src: &Path, leptonica_install: &Path, emsdk_dir: &Path) {
|
|
747
|
+
let toolchain_file = emsdk_dir.join("upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake");
|
|
748
|
+
|
|
749
|
+
let mut config = Config::new(leptonica_src);
|
|
750
|
+
|
|
751
|
+
config.define("CMAKE_TOOLCHAIN_FILE", &toolchain_file);
|
|
752
|
+
|
|
753
|
+
config
|
|
754
|
+
.define("CMAKE_BUILD_TYPE", "Release")
|
|
755
|
+
.define("CMAKE_POLICY_VERSION_MINIMUM", "3.5")
|
|
756
|
+
.define("LIBWEBP_SUPPORT", "OFF")
|
|
757
|
+
.define("OPENJPEG_SUPPORT", "OFF")
|
|
758
|
+
.define("ENABLE_ZLIB", "OFF")
|
|
759
|
+
.define("ENABLE_PNG", "OFF")
|
|
760
|
+
.define("ENABLE_JPEG", "OFF")
|
|
761
|
+
.define("ENABLE_TIFF", "OFF")
|
|
762
|
+
.define("ENABLE_WEBP", "OFF")
|
|
763
|
+
.define("ENABLE_OPENJPEG", "OFF")
|
|
764
|
+
.define("ENABLE_GIF", "OFF")
|
|
765
|
+
.define("BUILD_PROG", "OFF")
|
|
766
|
+
.define("BUILD_SHARED_LIBS", "OFF")
|
|
767
|
+
.define("NO_CONSOLE_IO", "ON")
|
|
768
|
+
.define("HAVE_LIBZ", "0")
|
|
769
|
+
.define("ENABLE_LTO", "OFF")
|
|
770
|
+
.define("CMAKE_INSTALL_PREFIX", leptonica_install);
|
|
771
|
+
|
|
772
|
+
config.build();
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
#[allow(dead_code)]
|
|
776
|
+
fn build_wasm() {
|
|
777
|
+
println!("cargo:warning=Building for WASM target with Emscripten SDK");
|
|
778
|
+
|
|
779
|
+
let custom_out_dir = prepare_out_dir();
|
|
780
|
+
let cache_dir = custom_out_dir.join("cache");
|
|
781
|
+
fs::create_dir_all(&cache_dir).expect("Failed to create cache directory");
|
|
782
|
+
|
|
783
|
+
let project_dir = custom_out_dir.clone();
|
|
784
|
+
let third_party_dir = project_dir.join("third_party");
|
|
785
|
+
|
|
786
|
+
println!("cargo:warning=Looking for pre-installed Emscripten SDK...");
|
|
787
|
+
let emsdk_dir = match find_emsdk() {
|
|
788
|
+
Ok(path) => {
|
|
789
|
+
println!("cargo:warning=Found EMSDK at: {}", path.display());
|
|
790
|
+
path
|
|
791
|
+
}
|
|
792
|
+
Err(err) => {
|
|
793
|
+
panic!("{}
|
|
794
|
+
|
|
795
|
+
Installation instructions:
|
|
796
|
+
macOS: brew install emscripten
|
|
797
|
+
Ubuntu: sudo apt-get install emscripten
|
|
798
|
+
Arch: sudo pacman -S emscripten
|
|
799
|
+
Manual: git clone https://github.com/emscripten-core/emsdk.git ~/.emsdk && cd ~/.emsdk && ./emsdk install latest && ./emsdk activate latest
|
|
800
|
+
|
|
801
|
+
After installation, set EMSDK environment variable or ensure it's in a standard location.", err);
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
setup_emsdk_environment(&emsdk_dir);
|
|
806
|
+
|
|
807
|
+
let leptonica_dir = if third_party_dir.join("leptonica").exists() {
|
|
808
|
+
println!("cargo:warning=Using existing leptonica source");
|
|
809
|
+
third_party_dir.join("leptonica")
|
|
810
|
+
} else {
|
|
811
|
+
fs::create_dir_all(&third_party_dir).expect("Failed to create third_party directory");
|
|
812
|
+
download_and_extract(&third_party_dir, &leptonica_url(), "leptonica")
|
|
813
|
+
};
|
|
814
|
+
|
|
815
|
+
let tesseract_dir = if third_party_dir.join("tesseract").exists() {
|
|
816
|
+
println!("cargo:warning=Using existing tesseract source");
|
|
817
|
+
third_party_dir.join("tesseract")
|
|
818
|
+
} else {
|
|
819
|
+
fs::create_dir_all(&third_party_dir).expect("Failed to create third_party directory");
|
|
820
|
+
download_and_extract(&third_party_dir, &tesseract_url(), "tesseract")
|
|
821
|
+
};
|
|
822
|
+
|
|
823
|
+
let leptonica_install_dir = custom_out_dir.join("leptonica");
|
|
824
|
+
let leptonica_cache_dir = cache_dir.join("leptonica");
|
|
825
|
+
|
|
826
|
+
let _leptonica_link_name =
|
|
827
|
+
build_or_use_cached("leptonica", &leptonica_cache_dir, &leptonica_install_dir, || {
|
|
828
|
+
println!("cargo:warning=Building Leptonica for WASM...");
|
|
829
|
+
build_leptonica_wasm(&leptonica_dir, &leptonica_install_dir, &emsdk_dir);
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
let tesseract_install_dir = custom_out_dir.join("tesseract");
|
|
833
|
+
let tesseract_cache_dir = cache_dir.join("tesseract");
|
|
834
|
+
|
|
835
|
+
let _tesseract_link_name =
|
|
836
|
+
build_or_use_cached("tesseract", &tesseract_cache_dir, &tesseract_install_dir, || {
|
|
837
|
+
println!("cargo:warning=Building Tesseract for WASM (SIMD enabled)...");
|
|
838
|
+
build_tesseract_wasm(
|
|
839
|
+
&tesseract_dir,
|
|
840
|
+
&tesseract_install_dir,
|
|
841
|
+
&leptonica_install_dir,
|
|
842
|
+
&emsdk_dir,
|
|
843
|
+
true,
|
|
844
|
+
);
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
let leptonica_lib_dir = leptonica_install_dir.join("lib");
|
|
848
|
+
let tesseract_lib_dir = tesseract_install_dir.join("lib");
|
|
849
|
+
|
|
850
|
+
println!("cargo:rustc-link-search=native={}", leptonica_lib_dir.display());
|
|
851
|
+
println!("cargo:rustc-link-search=native={}", tesseract_lib_dir.display());
|
|
852
|
+
|
|
853
|
+
println!("cargo:rustc-link-lib=static=tesseract");
|
|
854
|
+
println!("cargo:rustc-link-lib=static=leptonica");
|
|
855
|
+
|
|
856
|
+
println!("cargo:warning=WASM build completed successfully!");
|
|
857
|
+
println!("cargo:warning=Leptonica install dir: {:?}", leptonica_install_dir);
|
|
858
|
+
println!("cargo:warning=Tesseract install dir: {:?}", tesseract_install_dir);
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
#[allow(dead_code)]
|
|
862
|
+
fn build_tesseract_wasm(
|
|
863
|
+
src_dir: &Path,
|
|
864
|
+
tesseract_install: &Path,
|
|
865
|
+
leptonica_install: &Path,
|
|
866
|
+
emsdk_dir: &Path,
|
|
867
|
+
enable_simd: bool,
|
|
868
|
+
) {
|
|
869
|
+
let toolchain_file = emsdk_dir.join("upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake");
|
|
870
|
+
|
|
871
|
+
let mut config = Config::new(src_dir);
|
|
872
|
+
|
|
873
|
+
config.define("CMAKE_TOOLCHAIN_FILE", &toolchain_file);
|
|
874
|
+
|
|
875
|
+
config.define("Leptonica_DIR", leptonica_install);
|
|
876
|
+
config.define("CMAKE_PREFIX_PATH", leptonica_install);
|
|
877
|
+
|
|
878
|
+
let mut cxx_flags = String::from("-DTESSERACT_IMAGEDATA_AS_PIX ");
|
|
879
|
+
if enable_simd {
|
|
880
|
+
cxx_flags.push_str("-msimd128 ");
|
|
881
|
+
}
|
|
882
|
+
cxx_flags.push_str("-fno-exceptions -fPIC -Os");
|
|
883
|
+
|
|
884
|
+
let c_flags = "-fno-exceptions -fPIC -Os";
|
|
885
|
+
|
|
886
|
+
config
|
|
887
|
+
.define("CMAKE_BUILD_TYPE", "Release")
|
|
888
|
+
.define("CMAKE_POLICY_VERSION_MINIMUM", "3.5")
|
|
889
|
+
.define("BUILD_TESSERACT_BINARY", "OFF")
|
|
890
|
+
.define("BUILD_TRAINING_TOOLS", "OFF")
|
|
891
|
+
.define("INSTALL_CONFIGS", "ON")
|
|
892
|
+
.define("BUILD_TESTS", "OFF")
|
|
893
|
+
.define("BUILD_PROG", "OFF")
|
|
894
|
+
.define("SYNTAX_LOG", "OFF")
|
|
895
|
+
.define("DISABLE_ARCHIVE", "ON")
|
|
896
|
+
.define("DISABLE_CURL", "ON")
|
|
897
|
+
.define("DISABLE_OPENCL", "ON")
|
|
898
|
+
.define("DISABLE_TIFF", "ON")
|
|
899
|
+
.define("DISABLE_PNG", "ON")
|
|
900
|
+
.define("DISABLE_JPEG", "ON")
|
|
901
|
+
.define("DISABLE_WEBP", "ON")
|
|
902
|
+
.define("DISABLE_OPENJPEG", "ON")
|
|
903
|
+
.define("DISABLE_ZLIB", "ON")
|
|
904
|
+
.define("DISABLE_LIBXML2", "ON")
|
|
905
|
+
.define("DISABLE_LIBICU", "ON")
|
|
906
|
+
.define("DISABLE_LZMA", "ON")
|
|
907
|
+
.define("DISABLE_GIF", "ON")
|
|
908
|
+
.define("DISABLE_DEBUG_MESSAGES", "ON")
|
|
909
|
+
.define("GRAPHICS_DISABLED", "ON")
|
|
910
|
+
.define("DISABLED_LEGACY_ENGINE", "ON")
|
|
911
|
+
.define("USE_OPENCL", "OFF")
|
|
912
|
+
.define("OPENMP_BUILD", "OFF")
|
|
913
|
+
.define("ENABLE_LTO", "ON")
|
|
914
|
+
.define("HAVE_SSE4_1", if enable_simd { "ON" } else { "OFF" })
|
|
915
|
+
.define("HAVE_AVX", "OFF")
|
|
916
|
+
.define("HAVE_AVX2", "OFF")
|
|
917
|
+
.define("HAVE_AVX512F", "OFF")
|
|
918
|
+
.define("HAVE_FMA", "OFF")
|
|
919
|
+
.define("CMAKE_INSTALL_PREFIX", tesseract_install)
|
|
920
|
+
.define("CMAKE_CXX_FLAGS", &cxx_flags)
|
|
921
|
+
.define("CMAKE_C_FLAGS", c_flags);
|
|
922
|
+
|
|
923
|
+
config.build();
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
fn build_or_use_cached<F>(name: &str, cache_dir: &Path, install_dir: &Path, build_fn: F) -> String
|
|
927
|
+
where
|
|
928
|
+
F: FnOnce(),
|
|
929
|
+
{
|
|
930
|
+
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default();
|
|
931
|
+
let target_triple = env::var("TARGET")
|
|
932
|
+
.unwrap_or_else(|_| env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_else(|_| "unknown".to_string()));
|
|
933
|
+
let is_windows = target_triple.contains("windows");
|
|
934
|
+
let is_windows_gnu = is_windows && target_env == "gnu";
|
|
935
|
+
|
|
936
|
+
let lib_name = if is_windows && !is_windows_gnu {
|
|
937
|
+
format!("{}.lib", name)
|
|
938
|
+
} else {
|
|
939
|
+
format!("lib{}.a", name)
|
|
940
|
+
};
|
|
941
|
+
|
|
942
|
+
let cached_path = cache_dir.join(&lib_name);
|
|
943
|
+
let marker_path = cache_dir.join(format!("{}.target", name));
|
|
944
|
+
let out_path = install_dir.join("lib").join(&lib_name);
|
|
945
|
+
|
|
946
|
+
let possible_lib_names: Vec<String> = if is_windows {
|
|
947
|
+
let mut base = match name {
|
|
948
|
+
"leptonica" => vec![
|
|
949
|
+
"leptonica.lib".to_string(),
|
|
950
|
+
"libleptonica.lib".to_string(),
|
|
951
|
+
"leptonica-static.lib".to_string(),
|
|
952
|
+
"leptonica-1.84.1.lib".to_string(),
|
|
953
|
+
"leptonica-1.86.0.lib".to_string(),
|
|
954
|
+
"leptonicad.lib".to_string(),
|
|
955
|
+
"libleptonica_d.lib".to_string(),
|
|
956
|
+
"leptonica-1.84.1d.lib".to_string(),
|
|
957
|
+
"leptonica-1.86.0d.lib".to_string(),
|
|
958
|
+
],
|
|
959
|
+
"tesseract" => vec![
|
|
960
|
+
"tesseract.lib".to_string(),
|
|
961
|
+
"libtesseract.lib".to_string(),
|
|
962
|
+
"tesseract-static.lib".to_string(),
|
|
963
|
+
"tesseract53.lib".to_string(),
|
|
964
|
+
"tesseract54.lib".to_string(),
|
|
965
|
+
"tesseract55.lib".to_string(),
|
|
966
|
+
"tesseractd.lib".to_string(),
|
|
967
|
+
"libtesseract_d.lib".to_string(),
|
|
968
|
+
"tesseract53d.lib".to_string(),
|
|
969
|
+
"tesseract54d.lib".to_string(),
|
|
970
|
+
"tesseract55d.lib".to_string(),
|
|
971
|
+
],
|
|
972
|
+
_ => vec![format!("{}.lib", name)],
|
|
973
|
+
};
|
|
974
|
+
|
|
975
|
+
if is_windows_gnu {
|
|
976
|
+
match name {
|
|
977
|
+
"leptonica" => {
|
|
978
|
+
base.push(format!("libleptonica-{}.a", LEPTONICA_VERSION));
|
|
979
|
+
base.push("libleptonica.a".to_string());
|
|
980
|
+
}
|
|
981
|
+
"tesseract" => {
|
|
982
|
+
base.push(format!("libtesseract{}.a", TESSERACT_VERSION.replace('.', "")));
|
|
983
|
+
base.push("libtesseract.a".to_string());
|
|
984
|
+
base.push("libtesseract55.a".to_string());
|
|
985
|
+
}
|
|
986
|
+
_ => {
|
|
987
|
+
base.push(format!("lib{}.a", name));
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
base
|
|
993
|
+
} else {
|
|
994
|
+
vec![format!("lib{}.a", name)]
|
|
995
|
+
};
|
|
996
|
+
|
|
997
|
+
fs::create_dir_all(cache_dir).expect("Failed to create cache directory");
|
|
998
|
+
fs::create_dir_all(out_path.parent().unwrap()).expect("Failed to create output directory");
|
|
999
|
+
|
|
1000
|
+
let candidate_lib_dirs = [
|
|
1001
|
+
install_dir.join("lib"),
|
|
1002
|
+
install_dir.join("lib64"),
|
|
1003
|
+
install_dir.join("lib").join("tesseract"),
|
|
1004
|
+
];
|
|
1005
|
+
|
|
1006
|
+
let cache_valid = cached_path.exists()
|
|
1007
|
+
&& {
|
|
1008
|
+
match fs::read_to_string(&marker_path) {
|
|
1009
|
+
Ok(cached_target) => {
|
|
1010
|
+
let valid = cached_target.trim() == target_triple;
|
|
1011
|
+
if !valid {
|
|
1012
|
+
println!(
|
|
1013
|
+
"cargo:warning=Cached {} library is for wrong architecture (cached: {}, current: {}), rebuilding",
|
|
1014
|
+
name,
|
|
1015
|
+
cached_target.trim(),
|
|
1016
|
+
target_triple
|
|
1017
|
+
);
|
|
1018
|
+
let _ = fs::remove_file(&cached_path);
|
|
1019
|
+
let _ = fs::remove_file(&marker_path);
|
|
1020
|
+
}
|
|
1021
|
+
valid
|
|
1022
|
+
}
|
|
1023
|
+
Err(_) => {
|
|
1024
|
+
println!(
|
|
1025
|
+
"cargo:warning=Cached {} library missing target marker, rebuilding",
|
|
1026
|
+
name
|
|
1027
|
+
);
|
|
1028
|
+
let _ = fs::remove_file(&cached_path);
|
|
1029
|
+
false
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
|
|
1034
|
+
let link_name_to_use = if cache_valid {
|
|
1035
|
+
println!("cargo:warning=Using cached {} library for {}", name, target_triple);
|
|
1036
|
+
if let Err(e) = fs::copy(&cached_path, &out_path) {
|
|
1037
|
+
println!("cargo:warning=Failed to copy cached library: {}", e);
|
|
1038
|
+
build_fn();
|
|
1039
|
+
}
|
|
1040
|
+
name.to_string()
|
|
1041
|
+
} else {
|
|
1042
|
+
println!("Building {} library", name);
|
|
1043
|
+
build_fn();
|
|
1044
|
+
|
|
1045
|
+
let mut found_lib_name = None;
|
|
1046
|
+
'search: for lib_name in &possible_lib_names {
|
|
1047
|
+
for dir in &candidate_lib_dirs {
|
|
1048
|
+
let lib_path = dir.join(lib_name);
|
|
1049
|
+
if lib_path.exists() {
|
|
1050
|
+
println!("cargo:warning=Found {} library at: {}", name, lib_path.display());
|
|
1051
|
+
let link_name = if lib_name.ends_with(".lib") {
|
|
1052
|
+
lib_name.strip_suffix(".lib").unwrap_or(lib_name).to_string()
|
|
1053
|
+
} else if lib_name.ends_with(".a") {
|
|
1054
|
+
lib_name
|
|
1055
|
+
.strip_prefix("lib")
|
|
1056
|
+
.and_then(|s| s.strip_suffix(".a"))
|
|
1057
|
+
.unwrap_or(lib_name)
|
|
1058
|
+
.to_string()
|
|
1059
|
+
} else {
|
|
1060
|
+
lib_name.to_string()
|
|
1061
|
+
};
|
|
1062
|
+
found_lib_name = Some((lib_path, link_name));
|
|
1063
|
+
break 'search;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
if let Some((lib_path, link_name)) = found_lib_name {
|
|
1069
|
+
if out_path.exists() {
|
|
1070
|
+
println!(
|
|
1071
|
+
"cargo:warning=Library already available at expected location: {}",
|
|
1072
|
+
out_path.display()
|
|
1073
|
+
);
|
|
1074
|
+
} else if let Err(e) = fs::copy(&lib_path, &out_path) {
|
|
1075
|
+
println!("cargo:warning=Failed to copy library to standard location: {}", e);
|
|
1076
|
+
}
|
|
1077
|
+
if let Err(e) = fs::copy(&lib_path, &cached_path) {
|
|
1078
|
+
println!("cargo:warning=Failed to cache library: {}", e);
|
|
1079
|
+
} else if let Err(e) = fs::write(&marker_path, &target_triple) {
|
|
1080
|
+
println!("cargo:warning=Failed to write cache marker: {}", e);
|
|
1081
|
+
} else {
|
|
1082
|
+
println!("cargo:warning=Cached {} library for {}", name, target_triple);
|
|
1083
|
+
}
|
|
1084
|
+
link_name
|
|
1085
|
+
} else {
|
|
1086
|
+
println!(
|
|
1087
|
+
"cargo:warning=Library {} not found! Searched for: {:?}",
|
|
1088
|
+
name, possible_lib_names
|
|
1089
|
+
);
|
|
1090
|
+
for dir in &candidate_lib_dirs {
|
|
1091
|
+
println!("cargo:warning=Checked directory: {}", dir.display());
|
|
1092
|
+
if let Ok(entries) = fs::read_dir(dir) {
|
|
1093
|
+
println!("cargo:warning=Files in {}:", dir.display());
|
|
1094
|
+
for entry in entries.flatten() {
|
|
1095
|
+
println!("cargo:warning= - {}", entry.file_name().to_string_lossy());
|
|
1096
|
+
}
|
|
1097
|
+
} else {
|
|
1098
|
+
println!("cargo:warning=Directory not accessible: {}", dir.display());
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
name.to_string()
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1104
|
+
|
|
1105
|
+
for dir in candidate_lib_dirs.iter().filter(|d| d.exists()) {
|
|
1106
|
+
println!("cargo:rustc-link-search=native={}", dir.display());
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
// Return the link name instead of outputting the link directive here
|
|
1110
|
+
// This allows the caller to control the linking order
|
|
1111
|
+
link_name_to_use
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
fn main() {
|
|
1116
|
+
#[cfg(feature = "build-tesseract")]
|
|
1117
|
+
{
|
|
1118
|
+
build_tesseract::build();
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
#[cfg(all(feature = "dynamic-linking", not(feature = "build-tesseract")))]
|
|
1122
|
+
{
|
|
1123
|
+
println!("cargo:warning=Using dynamic linking with system-installed Tesseract libraries");
|
|
1124
|
+
println!("cargo:rustc-link-lib=dylib=tesseract");
|
|
1125
|
+
println!("cargo:rustc-link-lib=dylib=leptonica");
|
|
1126
|
+
}
|
|
1127
|
+
}
|