Skip to content

Commit 064a888

Browse files
committed
Redo version checking.
1 parent 3794798 commit 064a888

File tree

7 files changed

+48
-50
lines changed

7 files changed

+48
-50
lines changed

AGENTS.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,13 @@ Run ruby-bindgen to regenerate the FFI bindings:
8787
bundle exec ruby-bindgen ffi-bindings.yaml
8888
```
8989

90-
### 5. Manual fixes after regeneration
90+
### 5. Version detection
9191

92-
After regenerating, apply these manual changes to `lib/api/proj.rb`:
93-
94-
**Add `PROJ_VERSION_NUMBER`:** libclang cannot evaluate macro expressions, so ruby-bindgen cannot emit the computed `PROJ_VERSION_NUMBER` constant. The generated version guards (`if PROJ_VERSION_NUMBER >= ...`) depend on it. After the `PROJ_VERSION_PATCH` line, add:
95-
96-
```ruby
97-
PROJ_VERSION_NUMBER = PROJ_VERSION_MAJOR * 10000 + PROJ_VERSION_MINOR * 100 + PROJ_VERSION_PATCH
98-
```
92+
Version guards in the generated bindings call `proj_version`, a method defined in `lib/api/proj_version.rb`. This file is user-maintained (not overwritten by ruby-bindgen) and reads the runtime library version via `proj_info`. No manual fixes are needed after regeneration.
9993

10094
### Version number format
10195

102-
PROJ uses the `PROJ_VERSION_NUMBER` macro, computed as `major * 10000 + minor * 100 + patch`. Examples:
96+
PROJ version numbers are computed as `major * 10000 + minor * 100 + patch`. Examples:
10397
- 5.0.0 → 50000 (baseline, no version guard)
10498
- 6.0.0 → 60000
10599
- 9.4.0 → 90400

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ source "https://rubygems.org"
33
# Specify your gem's dependencies in tensorflow-ruby.gemspec
44
gemspec
55

6+
gem "ruby-bindgen", path: "/mnt/c/Source/ruby-bindgen"
67
gem "simplecov"

ffi-bindings.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ library_versions:
2222
- "12"
2323
- "11"
2424

25-
version_macro: PROJ_VERSION_NUMBER
26-
2725
symbols:
26+
skip:
27+
- PJ_INFO
28+
- proj_info
29+
2830
versions:
2931
# 5.1.0
3032
50100:

lib/api/proj.rb

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
module Proj
22
module Api
3-
PROJ_VERSION_MAJOR = 9
4-
PROJ_VERSION_MINOR = 6
5-
PROJ_VERSION_PATCH = 2
6-
# libclang cannot evaluate macro expressions, so ruby-bindgen cannot emit this computed constant.
7-
# Must be added manually after each regeneration.
8-
PROJ_VERSION_NUMBER = PROJ_VERSION_MAJOR * 10000 + PROJ_VERSION_MINOR * 100 + PROJ_VERSION_PATCH
9-
PJ_DEFAULT_CTX = 0
10-
PROJ_ERR_INVALID_OP = 1024
11-
PROJ_ERR_COORD_TRANSFM = 2048
12-
PROJ_ERR_OTHER = 4096
133
attach_variable :PjRelease, :pj_release, :string
144
typedef :pointer, :PjArea
155

@@ -144,17 +134,6 @@ class PjCoord < FFI::Union
144134
:lp, PjLp
145135
end
146136

147-
class PjInfo < FFI::Struct
148-
layout :major, :int,
149-
:minor, :int,
150-
:patch, :int,
151-
:release, :string,
152-
:version, :string,
153-
:searchpath, :string,
154-
:paths, :pointer,
155-
:path_count, :ulong
156-
end
157-
158137
class PjProjInfo < FFI::Struct
159138
layout :id, :string,
160139
:description, :string,
@@ -265,7 +244,6 @@ class ProjFileApi < FFI::Struct
265244
attach_function :proj_errno_reset, :proj_errno_reset, [:pointer], :int
266245
attach_function :proj_errno_restore, :proj_errno_restore, [:pointer, :int], :int
267246
attach_function :proj_factors, :proj_factors, [:pointer, PjCoord.by_value], P5Factors.by_value
268-
attach_function :proj_info, :proj_info, [], PjInfo.by_value
269247
attach_function :proj_pj_info, :proj_pj_info, [:pointer], PjProjInfo.by_value
270248
attach_function :proj_grid_info, :proj_grid_info, [:string], PjGridInfo.by_value
271249
attach_function :proj_init_info, :proj_init_info, [:string], PjInitInfo.by_value
@@ -491,12 +469,12 @@ class PjParamDescription < FFI::Struct
491469
attach_function :proj_create_cs, :proj_create_cs, [:pointer, PjCoordinateSystemType, :int, :pointer], :pointer
492470
attach_function :proj_create_conversion, :proj_create_conversion, [:pointer, :string, :string, :string, :string, :string, :string, :int, :pointer], :pointer
493471
attach_function :proj_create_transformation, :proj_create_transformation, [:pointer, :string, :string, :string, :pointer, :pointer, :pointer, :string, :string, :string, :int, :pointer, :double], :pointer
494-
if PROJ_VERSION_NUMBER >= 50100
472+
if proj_version >= 50100
495473
attach_function :proj_errno_string, :proj_errno_string, [:int], :string
496474
attach_function :proj_log_level, :proj_log_level, [:pointer, PjLogLevel], PjLogLevel
497475
attach_function :proj_log_func, :proj_log_func, [:pointer, :pointer, :pj_log_function], :void
498476
end
499-
if PROJ_VERSION_NUMBER >= 60000
477+
if proj_version >= 60000
500478
attach_function :proj_context_set_file_finder, :proj_context_set_file_finder, [:pointer, :proj_file_finder, :pointer], :void
501479
attach_function :proj_context_set_search_paths, :proj_context_set_search_paths, [:pointer, :int, :pointer], :void
502480
attach_function :proj_context_use_proj4_init_rules, :proj_context_use_proj4_init_rules, [:pointer, :int], :void
@@ -656,10 +634,10 @@ class PjParamDescription < FFI::Struct
656634
attach_function :proj_create_conversion_spherical_cross_track_height, :proj_create_conversion_spherical_cross_track_height, [:pointer, :double, :double, :double, :double, :string, :double, :string, :double], :pointer
657635
attach_function :proj_create_conversion_equal_earth, :proj_create_conversion_equal_earth, [:pointer, :double, :double, :double, :string, :double, :string, :double], :pointer
658636
end
659-
if PROJ_VERSION_NUMBER >= 60100
637+
if proj_version >= 60100
660638
attach_function :proj_normalize_for_visualization, :proj_normalize_for_visualization, [:pointer, :pointer], :pointer
661639
end
662-
if PROJ_VERSION_NUMBER >= 60200
640+
if proj_version >= 60200
663641
attach_function :proj_create_crs_to_crs_from_pj, :proj_create_crs_to_crs_from_pj, [:pointer, :pointer, :pointer, :pointer, :pointer], :pointer
664642
attach_function :proj_cleanup, :proj_cleanup, [], :void
665643
attach_function :proj_context_set_autoclose_database, :proj_context_set_autoclose_database, [:pointer, :int], :void
@@ -671,7 +649,7 @@ class PjParamDescription < FFI::Struct
671649
attach_function :proj_concatoperation_get_step_count, :proj_concatoperation_get_step_count, [:pointer, :pointer], :int
672650
attach_function :proj_concatoperation_get_step, :proj_concatoperation_get_step, [:pointer, :pointer, :int], :pointer
673651
end
674-
if PROJ_VERSION_NUMBER >= 60300
652+
if proj_version >= 60300
675653
attach_function :proj_is_equivalent_to_with_ctx, :proj_is_equivalent_to_with_ctx, [:pointer, :pointer, :pointer, PjComparisonCriterion], :int
676654
attach_function :proj_coordoperation_create_inverse, :proj_coordoperation_create_inverse, [:pointer, :pointer], :pointer
677655
attach_function :proj_create_ellipsoidal_3d_cs, :proj_create_ellipsoidal_3D_cs, [:pointer, PjEllipsoidalCs3dType, :string, :double, :string, :double], :pointer
@@ -685,7 +663,7 @@ class PjParamDescription < FFI::Struct
685663
attach_function :proj_create_conversion_vertical_perspective, :proj_create_conversion_vertical_perspective, [:pointer, :double, :double, :double, :double, :double, :double, :string, :double, :string, :double], :pointer
686664
attach_function :proj_create_conversion_pole_rotation_grib_convention, :proj_create_conversion_pole_rotation_grib_convention, [:pointer, :double, :double, :double, :string, :double], :pointer
687665
end
688-
if PROJ_VERSION_NUMBER >= 70000
666+
if proj_version >= 70000
689667
attach_function :proj_context_set_fileapi, :proj_context_set_fileapi, [:pointer, ProjFileApi.by_ref, :pointer], :int
690668
attach_function :proj_context_set_sqlite3_vfs_name, :proj_context_set_sqlite3_vfs_name, [:pointer, :string], :void
691669
attach_function :proj_context_set_network_callbacks, :proj_context_set_network_callbacks, [:pointer, :proj_network_open_cbk_type, :proj_network_close_cbk_type, :proj_network_get_header_value_cbk_type, :proj_network_read_range_type, :pointer], :int
@@ -701,7 +679,7 @@ class PjParamDescription < FFI::Struct
701679
callback :proj_download_file_progress_cbk_callback, [:pointer, :double, :pointer], :int
702680
attach_function :proj_download_file, :proj_download_file, [:pointer, :string, :int, :proj_download_file_progress_cbk_callback, :pointer], :int
703681
end
704-
if PROJ_VERSION_NUMBER >= 70100
682+
if proj_version >= 70100
705683
attach_function :proj_context_get_url_endpoint, :proj_context_get_url_endpoint, [:pointer], :string
706684
attach_function :proj_context_get_user_writable_directory, :proj_context_get_user_writable_directory, [:pointer, :int], :string
707685
attach_function :proj_degree_input, :proj_degree_input, [:pointer, PjDirection], :int
@@ -711,7 +689,7 @@ class PjParamDescription < FFI::Struct
711689
attach_function :proj_operation_factory_context_set_allow_ballpark_transformations, :proj_operation_factory_context_set_allow_ballpark_transformations, [:pointer, :pointer, :int], :void
712690
attach_function :proj_get_suggested_operation, :proj_get_suggested_operation, [:pointer, :pointer, PjDirection, PjCoord.by_value], :int
713691
end
714-
if PROJ_VERSION_NUMBER >= 70200
692+
if proj_version >= 70200
715693
attach_function :proj_context_clone, :proj_context_clone, [:pointer], :pointer
716694
attach_function :proj_context_set_ca_bundle_path, :proj_context_set_ca_bundle_path, [:pointer, :string], :void
717695
attach_function :proj_crs_get_datum_ensemble, :proj_crs_get_datum_ensemble, [:pointer, :pointer], :pointer
@@ -721,11 +699,11 @@ class PjParamDescription < FFI::Struct
721699
attach_function :proj_datum_ensemble_get_member, :proj_datum_ensemble_get_member, [:pointer, :pointer, :int], :pointer
722700
attach_function :proj_dynamic_datum_get_frame_reference_epoch, :proj_dynamic_datum_get_frame_reference_epoch, [:pointer, :pointer], :double
723701
end
724-
if PROJ_VERSION_NUMBER >= 80000
702+
if proj_version >= 80000
725703
attach_function :proj_context_errno_string, :proj_context_errno_string, [:pointer, :int], :string
726704
attach_function :proj_crs_is_derived, :proj_crs_is_derived, [:pointer, :pointer], :int
727705
end
728-
if PROJ_VERSION_NUMBER >= 80100
706+
if proj_version >= 80100
729707
attach_function :proj_context_get_database_structure, :proj_context_get_database_structure, [:pointer, :pointer], :pointer
730708
attach_function :proj_get_geoid_models_from_database, :proj_get_geoid_models_from_database, [:pointer, :string, :string, :pointer], :pointer
731709
attach_function :proj_get_celestial_body_list_from_database, :proj_get_celestial_body_list_from_database, [:pointer, :string, :pointer], :pointer
@@ -735,32 +713,32 @@ class PjParamDescription < FFI::Struct
735713
attach_function :proj_get_insert_statements, :proj_get_insert_statements, [:pointer, :pointer, :pointer, :string, :string, :int, :pointer, :pointer], :pointer
736714
attach_function :proj_get_celestial_body_name, :proj_get_celestial_body_name, [:pointer, :pointer], :string
737715
end
738-
if PROJ_VERSION_NUMBER >= 80200
716+
if proj_version >= 80200
739717
attach_function :proj_trans_bounds, :proj_trans_bounds, [:pointer, :pointer, PjDirection, :double, :double, :double, :double, :pointer, :pointer, :pointer, :pointer, :int], :int
740718
attach_function :proj_create_conversion_pole_rotation_netcdf_cf_convention, :proj_create_conversion_pole_rotation_netcdf_cf_convention, [:pointer, :double, :double, :double, :string, :double], :pointer
741719
end
742-
if PROJ_VERSION_NUMBER >= 90100
720+
if proj_version >= 90100
743721
attach_function :proj_area_set_name, :proj_area_set_name, [:pointer, :string], :void
744722
attach_function :proj_trans_get_last_used_operation, :proj_trans_get_last_used_operation, [:pointer], :pointer
745723
attach_function :proj_operation_factory_context_set_area_of_interest_name, :proj_operation_factory_context_set_area_of_interest_name, [:pointer, :pointer, :string], :void
746724
end
747-
if PROJ_VERSION_NUMBER >= 90200
725+
if proj_version >= 90200
748726
attach_function :proj_get_domain_count, :proj_get_domain_count, [:pointer], :int
749727
attach_function :proj_get_scope_ex, :proj_get_scope_ex, [:pointer, :int], :string
750728
attach_function :proj_coordinate_metadata_get_epoch, :proj_coordinate_metadata_get_epoch, [:pointer, :pointer], :double
751729
attach_function :proj_create_conversion_tunisia_mining_grid, :proj_create_conversion_tunisia_mining_grid, [:pointer, :double, :double, :double, :double, :string, :double, :string, :double], :pointer
752730
end
753-
if PROJ_VERSION_NUMBER >= 90400
731+
if proj_version >= 90400
754732
attach_function :proj_crs_has_point_motion_operation, :proj_crs_has_point_motion_operation, [:pointer, :pointer], :int
755733
attach_function :proj_coordinate_metadata_create, :proj_coordinate_metadata_create, [:pointer, :pointer, :double], :pointer
756734
attach_function :proj_create_conversion_lambert_conic_conformal_1sp_variant_b, :proj_create_conversion_lambert_conic_conformal_1sp_variant_b, [:pointer, :double, :double, :double, :double, :double, :double, :string, :double, :string, :double], :pointer
757735
end
758-
if PROJ_VERSION_NUMBER >= 90500
736+
if proj_version >= 90500
759737
attach_function :proj_context_set_user_writable_directory, :proj_context_set_user_writable_directory, [:pointer, :string, :int], :void
760738
attach_function :proj_coordoperation_requires_per_coordinate_input_time, :proj_coordoperation_requires_per_coordinate_input_time, [:pointer, :pointer], :int
761739
attach_function :proj_create_conversion_local_orthographic, :proj_create_conversion_local_orthographic, [:pointer, :double, :double, :double, :double, :double, :double, :string, :double, :string, :double], :pointer
762740
end
763-
if PROJ_VERSION_NUMBER >= 90600
741+
if proj_version >= 90600
764742
attach_function :proj_trans_bounds_3d, :proj_trans_bounds_3D, [:pointer, :pointer, PjDirection, :double, :double, :double, :double, :double, :double, :pointer, :pointer, :pointer, :pointer, :pointer, :pointer, :int], :int
765743
end
766744
end

lib/api/proj_ffi.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ def self.search_names
3636
end
3737
end
3838

39+
require_relative 'proj_version'
3940
require_relative './proj'
4041
require_relative './proj_experimental'

lib/api/proj_version.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Proj
2+
module Api
3+
class PjInfo < FFI::Struct
4+
layout :major, :int,
5+
:minor, :int,
6+
:patch, :int,
7+
:release, :string,
8+
:version, :string,
9+
:searchpath, :string,
10+
:paths, :pointer,
11+
:path_count, :ulong
12+
end
13+
14+
attach_function :proj_info, :proj_info, [], PjInfo.by_value
15+
16+
def self.proj_version
17+
info = proj_info
18+
info[:major] * 10000 + info[:minor] * 100 + info[:patch]
19+
end
20+
end
21+
end

lib/proj.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
module Proj
66
# Compatibility constant used by wrapper classes
7-
PROJ_VERSION = Gem::Version.new("#{Api::PROJ_VERSION_MAJOR}.#{Api::PROJ_VERSION_MINOR}.#{Api::PROJ_VERSION_PATCH}")
7+
info = Api.proj_info
8+
PROJ_VERSION = Gem::Version.new("#{info[:major]}.#{info[:minor]}.#{info[:patch]}")
89
Api::PROJ_VERSION = PROJ_VERSION
910
end
1011

0 commit comments

Comments
 (0)