From ed2fba9c1ffde51c181c8f53e2bc906e8feae0e8 Mon Sep 17 00:00:00 2001 From: gilzoide Date: Mon, 10 Feb 2025 18:38:34 -0300 Subject: [PATCH 1/2] Make column attributes inherit Unity's RequiredMemberAttribute This fixes managed code stripping removing getter/setter methods --- Plugins/Makefile | 2 +- Plugins/tools~/fix-library-path.sed | 6 +++--- README.md | 2 +- Runtime/sqlite-net/SQLite.cs | 16 ++++++++-------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Plugins/Makefile b/Plugins/Makefile index 0fe7e91..560cf59 100644 --- a/Plugins/Makefile +++ b/Plugins/Makefile @@ -92,7 +92,7 @@ lib/webgl/libgilzoide-sqlite-net.bc: $(SQLITE_SRC) | lib/webgl # Source $(SQLITE_NET_DEST)/%.cs: sqlite-net~/src/%.cs $(SQLITE_NET_SED_SCRIPT) - cat $< | sed -f $(SQLITE_NET_SED_SCRIPT) > $@ + cat $< | sed -E -f $(SQLITE_NET_SED_SCRIPT) > $@ $(SQLITE_NET_DEST)/License.txt: sqlite-net~/License.txt cp $< $@ diff --git a/Plugins/tools~/fix-library-path.sed b/Plugins/tools~/fix-library-path.sed index d0700da..5595392 100644 --- a/Plugins/tools~/fix-library-path.sed +++ b/Plugins/tools~/fix-library-path.sed @@ -30,9 +30,9 @@ s/static string Quote/public static string Quote/ # Make SQLite3 class partial, to extend in another file s/class SQLite3/partial class SQLite3/ -# Add [RequiredMember] attribute to ColumnInfo.Name property -# This fixes managed code stripping removing its setter method -s/Column ("name")/Column ("name"), UnityEngine.Scripting.RequiredMember/ +# Make column attributes inherit Unity's RequiredMemberAttribute +# This fixes managed code stripping removing getter/setter methods +s/public class (PrimaryKey|AutoIncrement|Indexed|MaxLength|Collation|NotNull|StoreAsText)Attribute : Attribute/public class \1Attribute : UnityEngine.Scripting.RequiredMemberAttribute/ # Use main thread TaskScheduler in WebGL s/TaskScheduler\.Default/SQLiteAsyncExtensions.TaskScheduler/ diff --git a/README.md b/README.md index 64ffc2b..dee01f5 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,6 @@ Third-party code: - `SQLiteConnection.Quote` is made public. This is useful for libraries making raw queries. - `SQLite3.SetDirectory` is only defined in Windows platforms. -- Adds a `[RequiredMember]` attribute to `ColumnInfo.Name` property, fixing errors on columns when managed code stripping is enabled. +- Makes all column related attributes inherit `RequiredMemberAttribute`, fixing errors on columns when managed code stripping is enabled. - Changes the `TaskScheduler` used by the async API on WebGL to one that executes tasks on Unity's main thread. - Fix support for struct return types in queries diff --git a/Runtime/sqlite-net/SQLite.cs b/Runtime/sqlite-net/SQLite.cs index f9fc593..78c4ce9 100644 --- a/Runtime/sqlite-net/SQLite.cs +++ b/Runtime/sqlite-net/SQLite.cs @@ -919,7 +919,7 @@ public class ColumnInfo { // public int cid { get; set; } - [Column ("name"), UnityEngine.Scripting.RequiredMember] + [Column ("name")] public string Name { get; set; } // [Column ("type")] @@ -2465,17 +2465,17 @@ public ColumnAttribute (string name) } [AttributeUsage (AttributeTargets.Property)] - public class PrimaryKeyAttribute : Attribute + public class PrimaryKeyAttribute : UnityEngine.Scripting.RequiredMemberAttribute { } [AttributeUsage (AttributeTargets.Property)] - public class AutoIncrementAttribute : Attribute + public class AutoIncrementAttribute : UnityEngine.Scripting.RequiredMemberAttribute { } [AttributeUsage (AttributeTargets.Property, AllowMultiple = true)] - public class IndexedAttribute : Attribute + public class IndexedAttribute : UnityEngine.Scripting.RequiredMemberAttribute { public string Name { get; set; } public int Order { get; set; } @@ -2507,7 +2507,7 @@ public override bool Unique { } [AttributeUsage (AttributeTargets.Property)] - public class MaxLengthAttribute : Attribute + public class MaxLengthAttribute : UnityEngine.Scripting.RequiredMemberAttribute { public int Value { get; private set; } @@ -2529,7 +2529,7 @@ public sealed class PreserveAttribute : System.Attribute /// "BINARY" is the default. /// [AttributeUsage (AttributeTargets.Property)] - public class CollationAttribute : Attribute + public class CollationAttribute : UnityEngine.Scripting.RequiredMemberAttribute { public string Value { get; private set; } @@ -2540,12 +2540,12 @@ public CollationAttribute (string collation) } [AttributeUsage (AttributeTargets.Property)] - public class NotNullAttribute : Attribute + public class NotNullAttribute : UnityEngine.Scripting.RequiredMemberAttribute { } [AttributeUsage (AttributeTargets.Enum)] - public class StoreAsTextAttribute : Attribute + public class StoreAsTextAttribute : UnityEngine.Scripting.RequiredMemberAttribute { } From 1543ded3fe2c10bd40647c38541e5c4c38f1af61 Mon Sep 17 00:00:00 2001 From: gilzoide Date: Sat, 15 Feb 2025 08:51:14 -0300 Subject: [PATCH 2/2] Change usage of RequiredMemberAttribute to PreserveAttribute Unity does not preserve members marked with attributes that inherit RequiredMemberAttribute, but do preserve members with attributes that inherit PreserveAttribute. --- Plugins/tools~/fix-library-path.sed | 4 ++-- README.md | 2 +- Runtime/sqlite-net/SQLite.cs | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Plugins/tools~/fix-library-path.sed b/Plugins/tools~/fix-library-path.sed index 5595392..3545579 100644 --- a/Plugins/tools~/fix-library-path.sed +++ b/Plugins/tools~/fix-library-path.sed @@ -30,9 +30,9 @@ s/static string Quote/public static string Quote/ # Make SQLite3 class partial, to extend in another file s/class SQLite3/partial class SQLite3/ -# Make column attributes inherit Unity's RequiredMemberAttribute +# Make column attributes inherit Unity's PreserveAttribute # This fixes managed code stripping removing getter/setter methods -s/public class (PrimaryKey|AutoIncrement|Indexed|MaxLength|Collation|NotNull|StoreAsText)Attribute : Attribute/public class \1Attribute : UnityEngine.Scripting.RequiredMemberAttribute/ +s/public class (Column|PrimaryKey|AutoIncrement|Indexed|MaxLength|Collation|NotNull|StoreAsText)Attribute : Attribute/public class \1Attribute : UnityEngine.Scripting.PreserveAttribute/ # Use main thread TaskScheduler in WebGL s/TaskScheduler\.Default/SQLiteAsyncExtensions.TaskScheduler/ diff --git a/README.md b/README.md index dee01f5..bd22fbf 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,6 @@ Third-party code: - `SQLiteConnection.Quote` is made public. This is useful for libraries making raw queries. - `SQLite3.SetDirectory` is only defined in Windows platforms. -- Makes all column related attributes inherit `RequiredMemberAttribute`, fixing errors on columns when managed code stripping is enabled. +- Makes all column related attributes inherit `PreserveAttribute`, fixing errors on columns when managed code stripping is enabled. - Changes the `TaskScheduler` used by the async API on WebGL to one that executes tasks on Unity's main thread. - Fix support for struct return types in queries diff --git a/Runtime/sqlite-net/SQLite.cs b/Runtime/sqlite-net/SQLite.cs index 78c4ce9..5136a69 100644 --- a/Runtime/sqlite-net/SQLite.cs +++ b/Runtime/sqlite-net/SQLite.cs @@ -2454,7 +2454,7 @@ public TableAttribute (string name) } [AttributeUsage (AttributeTargets.Property)] - public class ColumnAttribute : Attribute + public class ColumnAttribute : UnityEngine.Scripting.PreserveAttribute { public string Name { get; set; } @@ -2465,17 +2465,17 @@ public ColumnAttribute (string name) } [AttributeUsage (AttributeTargets.Property)] - public class PrimaryKeyAttribute : UnityEngine.Scripting.RequiredMemberAttribute + public class PrimaryKeyAttribute : UnityEngine.Scripting.PreserveAttribute { } [AttributeUsage (AttributeTargets.Property)] - public class AutoIncrementAttribute : UnityEngine.Scripting.RequiredMemberAttribute + public class AutoIncrementAttribute : UnityEngine.Scripting.PreserveAttribute { } [AttributeUsage (AttributeTargets.Property, AllowMultiple = true)] - public class IndexedAttribute : UnityEngine.Scripting.RequiredMemberAttribute + public class IndexedAttribute : UnityEngine.Scripting.PreserveAttribute { public string Name { get; set; } public int Order { get; set; } @@ -2507,7 +2507,7 @@ public override bool Unique { } [AttributeUsage (AttributeTargets.Property)] - public class MaxLengthAttribute : UnityEngine.Scripting.RequiredMemberAttribute + public class MaxLengthAttribute : UnityEngine.Scripting.PreserveAttribute { public int Value { get; private set; } @@ -2529,7 +2529,7 @@ public sealed class PreserveAttribute : System.Attribute /// "BINARY" is the default. /// [AttributeUsage (AttributeTargets.Property)] - public class CollationAttribute : UnityEngine.Scripting.RequiredMemberAttribute + public class CollationAttribute : UnityEngine.Scripting.PreserveAttribute { public string Value { get; private set; } @@ -2540,12 +2540,12 @@ public CollationAttribute (string collation) } [AttributeUsage (AttributeTargets.Property)] - public class NotNullAttribute : UnityEngine.Scripting.RequiredMemberAttribute + public class NotNullAttribute : UnityEngine.Scripting.PreserveAttribute { } [AttributeUsage (AttributeTargets.Enum)] - public class StoreAsTextAttribute : UnityEngine.Scripting.RequiredMemberAttribute + public class StoreAsTextAttribute : UnityEngine.Scripting.PreserveAttribute { }