From fd27d45f81ff06e60ab6d86e9a8159b6f64b16ce Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 28 May 2026 14:12:27 +0300 Subject: [PATCH] net.ssl: use openssl for bsd tinyc via prefs --- vlib/net/ssl/ssl_notd_use_openssl.v | 38 +++++++---------------------- vlib/v/pref/default.v | 11 ++++++++- vlib/v/pref/pref_test.v | 20 +++++++++++++++ 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/vlib/net/ssl/ssl_notd_use_openssl.v b/vlib/net/ssl/ssl_notd_use_openssl.v index 853c09998..0317757bb 100644 --- a/vlib/net/ssl/ssl_notd_use_openssl.v +++ b/vlib/net/ssl/ssl_notd_use_openssl.v @@ -1,35 +1,15 @@ module ssl -$if tinyc && (freebsd || openbsd) { - import net.openssl -} $else { - import net.mbedtls -} - -$if tinyc && (freebsd || openbsd) { - // TinyCC hangs in the bundled mbedtls path on FreeBSD/OpenBSD. - // Prefer the OpenSSL backend there, which does not exhibit the issue. - pub type SSLConn = openssl.SSLConn +import net.mbedtls - @[params] - pub struct SSLConnectConfig { - openssl.SSLConnectConfig - } +pub type SSLConn = mbedtls.SSLConn - // new_ssl_conn returns a new SSLConn with the given config. - pub fn new_ssl_conn(config SSLConnectConfig) !&SSLConn { - return openssl.new_ssl_conn(config.SSLConnectConfig) or { return err } - } -} $else { - pub type SSLConn = mbedtls.SSLConn - - @[params] - pub struct SSLConnectConfig { - mbedtls.SSLConnectConfig - } +@[params] +pub struct SSLConnectConfig { + mbedtls.SSLConnectConfig +} - // new_ssl_conn returns a new SSLConn with the given config. - pub fn new_ssl_conn(config SSLConnectConfig) !&SSLConn { - return mbedtls.new_ssl_conn(config.SSLConnectConfig) or { return err } - } +// new_ssl_conn returns a new SSLConn with the given config. +pub fn new_ssl_conn(config SSLConnectConfig) !&SSLConn { + return mbedtls.new_ssl_conn(config.SSLConnectConfig) or { return err } } diff --git a/vlib/v/pref/default.v b/vlib/v/pref/default.v index ec8b14e35..bec71f1ec 100644 --- a/vlib/v/pref/default.v +++ b/vlib/v/pref/default.v @@ -176,6 +176,14 @@ fn (mut p Preferences) disable_tcc_shared_backtraces() { } } +fn (mut p Preferences) prefer_openssl_for_bsd_tinyc() { + if p.os in [.freebsd, .openbsd] && p.ccompiler_type == .tinyc + && 'use_openssl' !in p.compile_defines_all { + // TinyCC hangs in the bundled mbedtls path on FreeBSD/OpenBSD. + p.parse_define('use_openssl') + } +} + // fill_with_defaults initializes unset preferences and derives build options from them. pub fn (mut p Preferences) fill_with_defaults() { p.setup_os_and_arch_when_not_explicitly_set() @@ -338,9 +346,10 @@ fn is_v2_compiler_target(npath string) bool { return target.ends_with('cmd/v2') || target.ends_with('cmd/v2/v2.v') } -// normalize_gc_defaults_for_resolved_ccompiler clears stale compiler-dependent +// normalize_gc_defaults_for_resolved_ccompiler applies compiler-dependent // defaults after the effective C compiler has been resolved. pub fn (mut p Preferences) normalize_gc_defaults_for_resolved_ccompiler() { + p.prefer_openssl_for_bsd_tinyc() p.disable_tcc_shared_backtraces() if p.prealloc { p.gc_mode = .no_gc diff --git a/vlib/v/pref/pref_test.v b/vlib/v/pref/pref_test.v index ffca51d94..4c2831ddc 100644 --- a/vlib/v/pref/pref_test.v +++ b/vlib/v/pref/pref_test.v @@ -604,6 +604,26 @@ fn test_tcc_shared_builds_disable_backtraces() { assert 'no_backtrace' !in regular_prefs.compile_defines_all } +fn test_bsd_tinyc_defaults_to_openssl() { + mut bsd_tinyc_prefs := &pref.Preferences{ + path: 'main.v' + os: .freebsd + ccompiler: 'tinyc' + ccompiler_set_by_flag: true + } + bsd_tinyc_prefs.fill_with_defaults() + assert 'use_openssl' in bsd_tinyc_prefs.compile_defines + assert 'use_openssl' in bsd_tinyc_prefs.compile_defines_all + + mut bsd_clang_prefs := &pref.Preferences{ + path: 'main.v' + os: .freebsd + ccompiler: 'clang' + } + bsd_clang_prefs.fill_with_defaults() + assert 'use_openssl' !in bsd_clang_prefs.compile_defines_all +} + fn test_late_resolved_tcc_shared_builds_disable_backtraces() { mut shared_prefs := &pref.Preferences{ path: 'libfoo.v' -- 2.39.5