Top Level Namespace
Defined Under Namespace
Modules: PQCrypto
Constant Summary collapse
- VENDOR_ONLY_CFLAGS =
"-Wno-unused-parameter -Wno-unused-function -Wno-strict-prototypes -Wno-pedantic -Wno-c23-extensions -Wno-undef"- SANITIZE =
ENV["PQCRYPTO_SANITIZE"]
- NATIVE_ASM =
env_bool("PQCRYPTO_NATIVE_ASM", native_asm_supported_by_default?)
- NATIVE_ARITH =
env_bool("PQCRYPTO_NATIVE_ARITH", NATIVE_ASM)
- NATIVE_FIPS202 =
env_bool("PQCRYPTO_NATIVE_FIPS202", NATIVE_ASM)
- X86_VENDOR_ARCH_FLAGS =
"-mavx2 -mbmi -mbmi2 -mpopcnt -maes -mssse3 -msse4.1 -msse4.2"- VENDOR_C_ARCH_FLAGS =
+""
- VENDOR_ASM_ARCH_FLAGS =
+""
Instance Method Summary collapse
- #aarch64_host? ⇒ Boolean
- #configure_compiler_environment ⇒ Object
- #configure_openssl! ⇒ Object
- #configure_openssl_paths(incdir, libdir, crypto_lib:) ⇒ Object
- #configure_openssl_prefix(prefix, source:) ⇒ Object
- #configure_ruby_c_api! ⇒ Object
- #env_bool(name, default) ⇒ Object
- #explicit_openssl_prefix ⇒ Object
- #find_vendor_dir ⇒ Object
- #generate_version_header! ⇒ Object
- #host_cpu ⇒ Object
- #host_os ⇒ Object
- #include_paths_from_flags(flags) ⇒ Object
- #inject_native_sources!(config) ⇒ Object
- #native_asm_supported_by_default? ⇒ Boolean
- #native_flags(kind, level, shared:) ⇒ Object
- #native_vendor_config(vendor_dir) ⇒ Object
- #native_vendor_ready?(vendor_dir) ⇒ Boolean
- #native_vendor_sources_for(vendor_dir) ⇒ Object
- #normalize_existing_path(path) ⇒ Object
- #openssl_library_dirs(prefix) ⇒ Object
- #openssl_library_file(dir, name) ⇒ Object
- #openssl_library_present?(dir, name) ⇒ Boolean
- #openssl_pkg_config ⇒ Object
- #openssl_prefix_usable?(prefix) ⇒ Boolean
- #openssl_version_at_least_3?(version) ⇒ Boolean
- #pkg_config_value(variable) ⇒ Object
- #recursive_include_dirs(root) ⇒ Object
- #remove_competing_openssl_headers!(selected_incdir) ⇒ Object
- #resolve_openssl_prefix ⇒ Object
- #run_vendor_script!(vendor_dir) ⇒ Object
- #strip_include_path(flags, path) ⇒ Object
- #vendor_script_path ⇒ Object
- #x86_64_host? ⇒ Boolean
Instance Method Details
#aarch64_host? ⇒ Boolean
59 60 61 |
# File 'ext/pqcrypto/extconf.rb', line 59 def aarch64_host? host_cpu =~ /\A(?:arm64|aarch64)\z/i end |
#configure_compiler_environment ⇒ Object
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'ext/pqcrypto/extconf.rb', line 311 def configure_compiler_environment prefix = resolve_openssl_prefix if prefix configure_openssl_prefix(prefix, source: "prefix") return end pkg = openssl_pkg_config if pkg && pkg[:incdir] && pkg[:libdir] configure_openssl_paths(pkg[:incdir], pkg[:libdir], crypto_lib: pkg[:crypto_lib]) puts "OpenSSL pkg-config: #{pkg[:version]}" puts "OpenSSL include dir: #{pkg[:incdir]}" puts "OpenSSL library dir: #{pkg[:libdir]}" puts "OpenSSL libcrypto: #{pkg[:crypto_lib]}" return end if pkg && pkg[:version] if openssl_version_at_least_3?(pkg[:version]) puts "Ignoring incomplete pkg-config OpenSSL #{pkg[:version]}; headers or libraries were not found" else puts "Ignoring pkg-config OpenSSL #{pkg[:version]}; OpenSSL 3.0 or later is required" end else puts "OpenSSL pkg-config: unavailable" end conventional = ["/usr/local", "/usr"].find { |candidate| openssl_prefix_usable?(candidate) } if conventional configure_openssl_prefix(conventional, source: "system prefix") return end puts "OpenSSL prefix: (none resolved; using compiler defaults)" end |
#configure_openssl! ⇒ Object
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'ext/pqcrypto/extconf.rb', line 420 def configure_openssl! configure_compiler_environment abort "openssl/evp.h is required" unless have_header("openssl/evp.h") abort "openssl/rand.h is required" unless have_header("openssl/rand.h") abort "openssl/crypto.h is required" unless have_header("openssl/crypto.h") abort "openssl/x509.h is required" unless have_header("openssl/x509.h") abort "openssl/pkcs12.h is required" unless have_header("openssl/pkcs12.h") version_check = <<~SRC #include <openssl/crypto.h> #include <openssl/opensslv.h> #if OPENSSL_VERSION_NUMBER < 0x30000000L #error "OpenSSL 3.0 or later is required" #endif int main(void) { return (int)OPENSSL_version_major(); } SRC abort <<~MSG unless try_link(version_check) OpenSSL 3.0 or later is required, but the compiler and linker did not find a consistent OpenSSL 3 headers + libcrypto pair. See mkmf.log for the exact include paths, library paths, and linker error. macOS with Homebrew: brew install openssl@3 OPENSSL_ROOT_DIR="$(brew --prefix openssl@3)" bundle exec rake clean compile Debian/Ubuntu: sudo apt-get install libssl-dev pkg-config pkg-config --modversion openssl # must report 3.x If an old Ruby toolchain injects OpenSSL 1.1 through CPPFLAGS or PKG_CONFIG_PATH, inspect mkmf.log and point the build at OpenSSL 3. MSG sha3_check = <<~SRC #include <openssl/evp.h> int main(void) { const EVP_MD *md = EVP_sha3_256(); return md == NULL ? 1 : 0; } SRC abort "OpenSSL SHA3-256 is required (X-Wing combiner)" unless try_link(sha3_check) shake_check = <<~SRC #include <openssl/evp.h> int main(void) { const EVP_MD *md = EVP_shake256(); return md == NULL ? 1 : 0; } SRC abort "OpenSSL SHAKE256 is required (X-Wing key expansion / ML-DSA streaming mu)" unless try_link(shake_check) $CFLAGS << " -DHAVE_OPENSSL_EVP_H -DHAVE_OPENSSL_RAND_H" end |
#configure_openssl_paths(incdir, libdir, crypto_lib:) ⇒ Object
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'ext/pqcrypto/extconf.rb', line 276 def configure_openssl_paths(incdir, libdir, crypto_lib:) if defined?($configure_args) && $configure_args $configure_args["--with-openssl-dir"] = File.dirname(incdir) $configure_args["--with-openssl-include"] = incdir $configure_args["--with-openssl-lib"] = libdir end remove_competing_openssl_headers!(incdir) $INCFLAGS = "-I#{incdir} #{$INCFLAGS}".strip $CPPFLAGS = "-I#{incdir} #{$CPPFLAGS}".strip $LIBPATH.unshift(libdir) unless $LIBPATH.include?(libdir) selected_libs = [crypto_lib].map { |path| Shellwords.escape(path) }.join(" ") $LOCAL_LIBS = "#{selected_libs} #{$LOCAL_LIBS}".strip unless host_os =~ /mswin|mingw|cygwin/i || libdir.start_with?("/usr/lib") $LDFLAGS = "-Wl,-rpath,#{Shellwords.escape(libdir)} #{$LDFLAGS}".strip end end |
#configure_openssl_prefix(prefix, source:) ⇒ Object
297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'ext/pqcrypto/extconf.rb', line 297 def configure_openssl_prefix(prefix, source:) incdir = File.join(prefix, "include") libdir = openssl_library_dirs(prefix).find do |dir| openssl_library_present?(dir, "crypto") end crypto_lib = openssl_library_file(libdir, "crypto") configure_openssl_paths(incdir, libdir, crypto_lib: crypto_lib) puts "OpenSSL #{source}: #{prefix}" puts "OpenSSL include dir: #{incdir}" puts "OpenSSL library dir: #{libdir}" puts "OpenSSL libcrypto: #{crypto_lib}" end |
#configure_ruby_c_api! ⇒ Object
414 415 416 417 418 |
# File 'ext/pqcrypto/extconf.rb', line 414 def configure_ruby_c_api! abort "ruby/thread.h is required" unless have_header("ruby/thread.h") abort "rb_thread_call_without_gvl is required" unless have_func("rb_thread_call_without_gvl", "ruby/thread.h") abort "rb_nogvl is required" unless have_func("rb_nogvl", "ruby/thread.h") end |
#env_bool(name, default) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'ext/pqcrypto/extconf.rb', line 73 def env_bool(name, default) value = ENV[name] return default if value.nil? || value.strip.empty? || value.strip.downcase == "auto" case value.strip.downcase when "1", "true", "yes", "on" true when "0", "false", "no", "off" false else abort "Invalid #{name}=#{value.inspect}; use 1, 0, true, false, or auto" end end |
#explicit_openssl_prefix ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'ext/pqcrypto/extconf.rb', line 147 def explicit_openssl_prefix %w[OPENSSL_ROOT_DIR OPENSSL_DIR].each do |var| value = ENV[var] next if value.nil? || value.strip.empty? prefix = File.(value.strip) abort <<~MSG unless openssl_prefix_usable?(prefix) #{var}=#{value.inspect} does not point to a complete OpenSSL installation. Expected OpenSSL headers under: #{File.join(prefix, "include", "openssl")} And libcrypto under lib, lib64, or a Linux multiarch lib directory. MSG return prefix end nil end |
#find_vendor_dir ⇒ Object
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'ext/pqcrypto/extconf.rb', line 392 def find_vendor_dir candidates = [ File.join(__dir__, "vendor"), File.("../../ext/pqcrypto/vendor", __dir__), File.join(Dir.pwd, "ext", "pqcrypto", "vendor") ] dir = __dir__ 6.times do candidates << File.join(dir, "ext", "pqcrypto", "vendor") dir = File.dirname(dir) end candidates.map! { |path| File.(path) } candidates.uniq! primary = File.(File.join(__dir__, "vendor")) run_vendor_script!(primary) unless native_vendor_ready?(primary) candidates.find { |path| native_vendor_ready?(path) } end |
#generate_version_header! ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'ext/pqcrypto/extconf.rb', line 10 def generate_version_header! version = PQCrypto::VERSION unless version.match?(/\A[0-9A-Za-z][0-9A-Za-z._+-]*\z/) abort "Invalid PQCrypto::VERSION for C header: #{version.inspect}" end header = File.join(__dir__, "pqcrypto_version.h") File.write(header, <<~C) /* Generated by extconf.rb from lib/pq_crypto/version.rb. Do not edit. */ #ifndef PQCRYPTO_VERSION_H #define PQCRYPTO_VERSION_H #define PQCRYPTO_VERSION #{version.dump} #endif C end |
#host_cpu ⇒ Object
51 52 53 |
# File 'ext/pqcrypto/extconf.rb', line 51 def host_cpu RbConfig::CONFIG.fetch("host_cpu", "") end |
#host_os ⇒ Object
55 56 57 |
# File 'ext/pqcrypto/extconf.rb', line 55 def host_os RbConfig::CONFIG.fetch("host_os", "") end |
#include_paths_from_flags(flags) ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'ext/pqcrypto/extconf.rb', line 221 def include_paths_from_flags(flags) tokens = Shellwords.split(flags.to_s) paths = [] index = 0 while index < tokens.length token = tokens[index] case token when "-I", "-isystem" paths << tokens[index + 1] if tokens[index + 1] index += 2 next when /\A-I(.+)\z/ paths << Regexp.last_match(1) when /\A-isystem(.+)\z/ paths << Regexp.last_match(1) end index += 1 end paths rescue ArgumentError [] end |
#inject_native_sources!(config) ⇒ Object
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 |
# File 'ext/pqcrypto/extconf.rb', line 534 def inject_native_sources!(config) makefile = File.read("Makefile") vendor_objects = [] build_rules = [] [ [:mlkem, "512", config[:mlkem_c], true], [:mlkem, "768", config[:mlkem_c], false], [:mlkem, "1024", config[:mlkem_c], false], [:mldsa, "44", config[:mldsa_c], true], [:mldsa, "65", config[:mldsa_c], false], [:mldsa, "87", config[:mldsa_c], false] ].each do |kind, level, source, shared| object = "pqnative_#{kind}_#{level}.o" flags = native_flags(kind, level, shared: shared) vendor_objects << object build_rules << <<~RULE #{object}: #{source} $(ECHO) compiling #{source} [#{kind}-#{level}] $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(CCDLFLAGS) #{VENDOR_ONLY_CFLAGS} #{VENDOR_C_ARCH_FLAGS} #{flags} $(COUTFLAG)$@ -c $(CSRCFLAG)$< RULE end if NATIVE_ARITH || NATIVE_FIPS202 [ [:mlkem, "512", config[:mlkem_asm], true], [:mlkem, "768", config[:mlkem_asm], false], [:mlkem, "1024", config[:mlkem_asm], false], [:mldsa, "44", config[:mldsa_asm], true], [:mldsa, "65", config[:mldsa_asm], false], [:mldsa, "87", config[:mldsa_asm], false] ].each do |kind, level, source, shared| next unless File.exist?(source) object = "pqnative_#{kind}_#{level}_asm.o" flags = native_flags(kind, level, shared: shared) vendor_objects << object build_rules << <<~RULE #{object}: #{source} $(ECHO) assembling #{source} [#{kind}-#{level}] $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(CCDLFLAGS) #{VENDOR_ONLY_CFLAGS} #{VENDOR_ASM_ARCH_FLAGS} #{flags} $(COUTFLAG)$@ -c $(CSRCFLAG)$< RULE end end objects_line = makefile.lines.find { |line| line.start_with?("OBJS = ") } raise "Could not find OBJS line in generated Makefile" unless objects_line makefile.sub!(objects_line, objects_line.chomp + " #{vendor_objects.join(' ')}\n") unless makefile.include?("# vendored pq-code-package objects") rules_block = "\n# vendored pq-code-package objects\n" + build_rules.join("\n") + "\n" anchor = "$(OBJS): $(HDRS) $(ruby_headers)\n" raise "Could not find OBJS dependency anchor in generated Makefile" unless makefile.include?(anchor) makefile.sub!(anchor, anchor + rules_block) end File.write("Makefile", makefile) end |
#native_asm_supported_by_default? ⇒ Boolean
67 68 69 70 71 |
# File 'ext/pqcrypto/extconf.rb', line 67 def native_asm_supported_by_default? return false if host_os =~ /mswin|mingw|cygwin/i aarch64_host? end |
#native_flags(kind, level, shared:) ⇒ Object
520 521 522 523 524 525 526 527 528 529 530 531 532 |
# File 'ext/pqcrypto/extconf.rb', line 520 def native_flags(kind, level, shared:) prefix = kind == :mlkem ? "MLK" : "MLD" ns = kind == :mlkem ? "pqcr_mlkem" : "pqcr_mldsa" flags = [] flags << "-D#{prefix}_CONFIG_MULTILEVEL_BUILD" flags << "-D#{prefix}_CONFIG_PARAMETER_SET=#{level}" flags << "-D#{prefix}_CONFIG_NAMESPACE_PREFIX=#{ns}" flags << "-D#{prefix}_CONFIG_NO_SUPERCOP" flags << (shared ? "-D#{prefix}_CONFIG_MULTILEVEL_WITH_SHARED" : "-D#{prefix}_CONFIG_MULTILEVEL_NO_SHARED") flags << "-D#{prefix}_CONFIG_USE_NATIVE_BACKEND_ARITH" if NATIVE_ARITH flags << "-D#{prefix}_CONFIG_USE_NATIVE_BACKEND_FIPS202" if NATIVE_FIPS202 flags.join(" ") end |
#native_vendor_config(vendor_dir) ⇒ Object
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 |
# File 'ext/pqcrypto/extconf.rb', line 481 def native_vendor_config(vendor_dir) abort <<~MSG unless vendor_dir PQ Code Package vendored sources are required. Expected: ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c Run: bundle exec rake vendor MSG mlkem_dir = File.join(vendor_dir, "mlkem-native", "mlkem") mldsa_dir = File.join(vendor_dir, "mldsa-native", "mldsa") mlkem_c = File.join(mlkem_dir, "mlkem_native.c") mldsa_c = File.join(mldsa_dir, "mldsa_native.c") missing = [mlkem_c, mldsa_c].reject { |path| File.exist?(path) } abort <<~MSG unless missing.empty? Missing PQ Code Package native source files: #{missing.join("\n ")} This build intentionally has no PQClean fallback. Auto-vendoring did not produce the required files. Vendor mlkem-native and mldsa-native, then rebuild. MSG include_dirs = [__dir__, mlkem_dir, mldsa_dir, *recursive_include_dirs(mlkem_dir), *recursive_include_dirs(mldsa_dir)].uniq include_dirs.each { |dir| $CPPFLAGS << " -I#{dir}" } { mlkem_dir: mlkem_dir, mldsa_dir: mldsa_dir, mlkem_c: mlkem_c, mldsa_c: mldsa_c, mlkem_asm: File.join(mlkem_dir, "mlkem_native_asm.S"), mldsa_asm: File.join(mldsa_dir, "mldsa_native_asm.S") } end |
#native_vendor_ready?(vendor_dir) ⇒ Boolean
354 355 356 357 |
# File 'ext/pqcrypto/extconf.rb', line 354 def native_vendor_ready?(vendor_dir) File.exist?(File.join(vendor_dir, ".vendored")) && native_vendor_sources_for(vendor_dir).all? { |path| File.exist?(path) } end |
#native_vendor_sources_for(vendor_dir) ⇒ Object
347 348 349 350 351 352 |
# File 'ext/pqcrypto/extconf.rb', line 347 def native_vendor_sources_for(vendor_dir) [ File.join(vendor_dir, "mlkem-native", "mlkem", "mlkem_native.c"), File.join(vendor_dir, "mldsa-native", "mldsa", "mldsa_native.c") ] end |
#normalize_existing_path(path) ⇒ Object
215 216 217 218 219 |
# File 'ext/pqcrypto/extconf.rb', line 215 def normalize_existing_path(path) File.realpath(path) rescue Errno::ENOENT File.(path) end |
#openssl_library_dirs(prefix) ⇒ Object
106 107 108 109 110 |
# File 'ext/pqcrypto/extconf.rb', line 106 def openssl_library_dirs(prefix) dirs = Dir.glob(File.join(prefix, "lib", "*-linux-gnu")) dirs.concat([File.join(prefix, "lib64"), File.join(prefix, "lib")]) dirs.select { |dir| File.directory?(dir) }.uniq end |
#openssl_library_file(dir, name) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'ext/pqcrypto/extconf.rb', line 112 def openssl_library_file(dir, name) candidates = [ File.join(dir, "lib#{name}.so.3"), *Dir.glob(File.join(dir, "lib#{name}.so.3.*")).sort, File.join(dir, "lib#{name}.so"), File.join(dir, "lib#{name}.3.dylib"), *Dir.glob(File.join(dir, "lib#{name}.3.*.dylib")).sort, File.join(dir, "lib#{name}.dylib"), File.join(dir, "lib#{name}.a"), File.join(dir, "lib#{name}.dll.a"), File.join(dir, "#{name}.lib") ] path = candidates.find { |candidate| File.file?(candidate) } path && File.realpath(path) rescue Errno::ENOENT nil end |
#openssl_library_present?(dir, name) ⇒ Boolean
131 132 133 |
# File 'ext/pqcrypto/extconf.rb', line 131 def openssl_library_present?(dir, name) !openssl_library_file(dir, name).nil? end |
#openssl_pkg_config ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'ext/pqcrypto/extconf.rb', line 191 def openssl_pkg_config return nil unless find_executable("pkg-config") version = `pkg-config --modversion openssl 2>/dev/null`.strip return nil unless $?.success? return nil if version.empty? return { version: version } unless openssl_version_at_least_3?(version) incdir = pkg_config_value("includedir") libdir = pkg_config_value("libdir") return { version: version } unless incdir && libdir return { version: version } unless File.exist?(File.join(incdir, "openssl", "opensslv.h")) crypto_lib = openssl_library_file(libdir, "crypto") return { version: version } unless crypto_lib { version: version, incdir: incdir, libdir: libdir, crypto_lib: crypto_lib } end |
#openssl_prefix_usable?(prefix) ⇒ Boolean
135 136 137 138 139 140 141 142 143 144 145 |
# File 'ext/pqcrypto/extconf.rb', line 135 def openssl_prefix_usable?(prefix) return false if prefix.nil? prefix = prefix.strip return false if prefix.empty? return false unless File.exist?(File.join(prefix, "include", "openssl", "opensslv.h")) openssl_library_dirs(prefix).any? do |dir| openssl_library_present?(dir, "crypto") end end |
#openssl_version_at_least_3?(version) ⇒ Boolean
209 210 211 212 213 |
# File 'ext/pqcrypto/extconf.rb', line 209 def openssl_version_at_least_3?(version) Gem::Version.new(version) >= Gem::Version.new("3.0.0") rescue ArgumentError false end |
#pkg_config_value(variable) ⇒ Object
183 184 185 186 187 188 189 |
# File 'ext/pqcrypto/extconf.rb', line 183 def pkg_config_value(variable) value = `pkg-config --variable=#{variable} openssl 2>/dev/null`.strip return nil unless $?.success? return nil if value.empty? File.(value) end |
#recursive_include_dirs(root) ⇒ Object
477 478 479 |
# File 'ext/pqcrypto/extconf.rb', line 477 def recursive_include_dirs(root) Dir.glob(File.join(root, "**", "*")).select { |p| File.directory?(p) }.map { |p| File.(p) } end |
#remove_competing_openssl_headers!(selected_incdir) ⇒ Object
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'ext/pqcrypto/extconf.rb', line 257 def remove_competing_openssl_headers!(selected_incdir) selected = normalize_existing_path(selected_incdir) flag_values = [$INCFLAGS, $CPPFLAGS, $CFLAGS] competing = flag_values .flat_map { |flags| include_paths_from_flags(flags) }.uniq.select do |path| next false unless File.file?(File.join(path, "openssl", "opensslv.h")) normalize_existing_path(path) != selected end competing.each do |path| $INCFLAGS = strip_include_path($INCFLAGS, path) $CPPFLAGS = strip_include_path($CPPFLAGS, path) $CFLAGS = strip_include_path($CFLAGS, path) puts "Ignoring competing OpenSSL headers: #{path}" end end |
#resolve_openssl_prefix ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'ext/pqcrypto/extconf.rb', line 168 def resolve_openssl_prefix explicit = explicit_openssl_prefix return explicit if explicit candidates = [] if find_executable("brew") %w[openssl@3 openssl].each do |formula| prefix = `brew --prefix #{formula} 2>/dev/null`.strip candidates << prefix unless prefix.empty? end end candidates.concat(["/opt/homebrew/opt/openssl@3", "/usr/local/opt/openssl@3"]) candidates.uniq.find { |prefix| openssl_prefix_usable?(prefix) } end |
#run_vendor_script!(vendor_dir) ⇒ Object
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'ext/pqcrypto/extconf.rb', line 363 def run_vendor_script!(vendor_dir) abort <<~MSG if ENV["PQCRYPTO_AUTO_VENDOR"] != "1" PQ Code Package vendored sources are missing. Expected: #{native_vendor_sources_for(vendor_dir).join("\n ")} The vendor tree is committed to the repository and shipped with the gem. If it is missing, the source tree is incomplete or corrupted. To fetch upstream sources at the pinned commits run: ruby script/vendor_libs.rb Or to allow extconf.rb to do this for you set PQCRYPTO_AUTO_VENDOR=1. MSG script = vendor_script_path abort "PQ Code Package vendored sources are missing and script/vendor_libs.rb was not packaged." unless File.exist?(script) puts "PQ Code Package native sources are missing; vendoring now (PQCRYPTO_AUTO_VENDOR=1)..." ok = system(RbConfig.ruby, script) abort <<~MSG unless ok Failed to vendor PQ Code Package native sources. This build intentionally has no PQClean fallback. Install git/network access or vendor mlkem-native and mldsa-native before installing the gem. MSG end |
#strip_include_path(flags, path) ⇒ Object
248 249 250 251 252 253 254 255 |
# File 'ext/pqcrypto/extconf.rb', line 248 def strip_include_path(flags, path) escaped = Regexp.escape(path) flags.to_s .gsub(/(?:\A|\s)-I\s*#{escaped}(?=\s|\z)/, " ") .gsub(/(?:\A|\s)-isystem\s*#{escaped}(?=\s|\z)/, " ") .strip end |
#vendor_script_path ⇒ Object
359 360 361 |
# File 'ext/pqcrypto/extconf.rb', line 359 def vendor_script_path File.("../../script/vendor_libs.rb", __dir__) end |
#x86_64_host? ⇒ Boolean
63 64 65 |
# File 'ext/pqcrypto/extconf.rb', line 63 def x86_64_host? host_cpu =~ /\A(?:x86_64|amd64|x64)\z/i end |