Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version handling: Handle multiple digits #102

Merged
merged 2 commits into from
Aug 10, 2023

Conversation

Geod24
Copy link
Collaborator

@Geod24 Geod24 commented Aug 7, 2023

@CyberShadow : Not sure how to handle this as I expect it's not compatible with our .di approach.

@VPanteleev-S7
Copy link

I have not been able to reproduce any linking issues without directly accessing private symbols either way (i.e. no problems with accessing OpenSSLVersion. But, here's a patch which replaces the template with CTFE:

diff --git a/source/deimos/openssl/opensslv.di b/source/deimos/openssl/opensslv.di
index bd21d55..d7f7680 100644
--- a/source/deimos/openssl/opensslv.di
+++ b/source/deimos/openssl/opensslv.di
@@ -19,89 +19,100 @@ version (DeimosOpenSSL_1_0_0)
 {
     // https://www.openssl.org/news/changelog.html#openssl-100
     // OpenSSL 1.0.0t was released 2015-12-03
-    public alias OpenSSLVersion = OpenSSLVersionTemplate!"1.0.0t";
+    public enum OpenSSLVersion = openSSLVersionFromText("1.0.0t");
 }
 else version (DeimosOpenSSL_1_0_1)
 {
     // https://www.openssl.org/news/changelog.html#openssl-101
     // OpenSSL 1.0.1u was released 2016-09-22
-    public alias OpenSSLVersion = OpenSSLVersionTemplate!"1.0.1u";
+    public enum OpenSSLVersion = openSSLVersionFromText("1.0.1u");
 }
 else version (DeimosOpenSSL_1_0_2)
 {
     // https://www.openssl.org/news/changelog.html#openssl-102
     // OpenSSL 1.0.2t was released 2019-09-10
-    public alias OpenSSLVersion = OpenSSLVersionTemplate!"1.0.2t";
+    public enum OpenSSLVersion = openSSLVersionFromText("1.0.2t");
 }
 else version (DeimosOpenSSL_1_1_0)
 {
     // https://www.openssl.org/news/changelog.html#openssl-110
     // OpenSSL 1.1.0l was released 2019-09-10
-    public alias OpenSSLVersion = OpenSSLVersionTemplate!"1.1.0l";
+    public enum OpenSSLVersion = openSSLVersionFromText("1.1.0l");
 }
 else version (DeimosOpenSSL_1_1_1)
 {
     // https://www.openssl.org/news/changelog.html#openssl-111
     // OpenSSL 1.1.1m was released 2021-12-14
-    public alias OpenSSLVersion = OpenSSLVersionTemplate!"1.1.1m";
+    public enum OpenSSLVersion = openSSLVersionFromText("1.1.1m");
 }
 else version (DeimosOpenSSL_3_0)
 {
     // https://www.openssl.org/news/changelog.html#openssl-30
     // OpenSSL 3.0.3 was released 2022-05-03
-    public alias OpenSSLVersion = OpenSSLVersionTemplate!"3.0.3";
+    public enum OpenSSLVersion = openSSLVersionFromText("3.0.3");
 }
 else version (DeimosOpenSSLAutoDetect)
 {
     import deimos.openssl.version_;
 
-    public alias OpenSSLVersion = OpenSSLVersionTemplate!OpenSSLTextVersion;
+    public enum OpenSSLVersion = openSSLVersionFromText(OpenSSLTextVersion);
 }
 else
 {
     // It was decided in https://github.com/D-Programming-Deimos/openssl/pull/66
     // that we should fall back to the latest supported version of the bindings,
     // should the user provide neither explicit version nor `DeimosOpenSSLAutoDetect`
-    public alias OpenSSLVersion = OpenSSLVersionTemplate!"1.1.0h";
+    public enum OpenSSLVersion = openSSLVersionFromText("1.1.0h");
 }
 
 // Publicly aliased above
-private struct OpenSSLVersionTemplate (string textVersion)
+private struct OpenSSLVersionStruct
 {
+    string text;
+    uint major, minor, patch;
+    int build;
+}
+
+/*private*/ OpenSSLVersionStruct openSSLVersionFromText(string textVersion)
+{
+    OpenSSLVersionStruct v;
+
     import std.ascii : isDigit;
     import std.algorithm.iteration : splitter;
     import std.algorithm.searching : canFind;
     import std.conv : to;
     import std.range : dropExactly;
 
-    enum text = textVersion;
+    v.text = textVersion;
 
-    enum uint major = textVersion.splitter('.')
+    v.major = textVersion.splitter('.')
         .front.to!uint;
-    static assert (major >= 0);
+    assert (v.major >= 0);
 
-    enum uint minor = textVersion.splitter('.')
+    v.minor = textVersion.splitter('.')
         .dropExactly(1)
         .front.to!uint;
-    static assert (minor >= 0);
+    assert (v.minor >= 0);
 
     // `std.algorithm.iteration : splitWhen` not usable at CT
     // so we're using `canFind`.
-    private enum string patchText = textVersion.splitter('.')
+    string patchText = textVersion.splitter('.')
         .dropExactly(2).front;
-    private enum patchChar = patchText.canFind!(
+    auto patchChar = patchText.canFind!(
         (dchar c) => !c.isDigit());
 
-    enum uint patch = patchText[0 .. $ - patchChar].to!uint;
-    static assert (patch >= 0);
+    v.patch = patchText[0 .. $ - patchChar].to!uint;
+    assert (v.patch >= 0);
 
-    static if (patchChar)
+    if (patchChar)
     {
-        enum int build = (patchText[$ - 1] - '`');
-        static assert (build >= 0);
+        v.build = (patchText[$ - 1] - '`');
+        assert (v.build >= 0);
     }
     else
-        enum int build = 0;
+        v.build = 0;
+
+    return v;
 }
 
 /* Numeric release version identifier:

The new openSSLVersionFromText can be used in other modules without linker errors (unlike OpenSSLVersionTemplate).

@CyberShadow
Copy link
Member

Please rebase to fix CI?

@CyberShadow CyberShadow linked an issue Aug 10, 2023 that may be closed by this pull request
Geod24 and others added 2 commits August 10, 2023 08:02
Use an approach which is hopefully more robust in terms of not pulling
in link-time dependencies.
@CyberShadow CyberShadow merged commit 1f88418 into D-Programming-Deimos:master Aug 10, 2023
12 checks passed
@Geod24 Geod24 deleted the mlang_fix_3.0.10 branch August 10, 2023 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3.0.10 is breaking opensslv.di
3 participants