Skip to content

Commit

Permalink
chg to 2.1.2 pre. experimental idea: write a nuget props file which c…
Browse files Browse the repository at this point in the history
…ontains the path to all the native libraries in the lib package. e_sqlite3 only for now. uwp and wasm missing for now, since they use nativeassets/tfm.
  • Loading branch information
ericsink committed Sep 8, 2022
1 parent 6358513 commit 2e1baf6
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 4 deletions.
134 changes: 133 additions & 1 deletion gen_lib_nuspecs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public enum TFM
NET461,
NET60,
MACCATALYST,
XAMARINMAC20,
}

public static class common
Expand All @@ -44,6 +45,7 @@ public static string AsString(this TFM e)
case TFM.NET461: return "net461";
case TFM.NET60: return "net6.0";
case TFM.MACCATALYST: return "net6.0-maccatalyst15.2";
case TFM.XAMARINMAC20: return "xamarin.mac20";
default:
throw new NotImplementedException(string.Format("TFM.AsString for {0}", e));
}
Expand Down Expand Up @@ -444,6 +446,17 @@ private static void gen_nuspec_lib_e_sqlite3(string dir_src)

write_nuspec_file_entries_from_cb(WhichLib.E_SQLITE3, "v142", f);

{
var tname = string.Format("{0}.props", id);
var path_props = Path.Combine(dir_proj, tname);
var relpath_props = nuget_path_combine(".", tname);
gen_nuget_props(path_props, WhichLib.E_SQLITE3);
common.write_nuspec_file_entry(
relpath_props,
"buildTransitive\\",
f
);
}
{
var tname = string.Format("{0}.targets", id);
Directory.CreateDirectory(Path.Combine(dir_proj, "net461"));
Expand All @@ -468,6 +481,20 @@ private static void gen_nuspec_lib_e_sqlite3(string dir_src)
f
);
}
#if not
{
var tname = string.Format("{0}.targets", id);
Directory.CreateDirectory(Path.Combine(dir_proj, "xamarin.mac20"));
var path_targets = Path.Combine(dir_proj, "xamarin.mac20", tname);
var relpath_targets = nuget_path_combine(".", "xamarin.mac20", tname);
gen_nuget_targets_legacy_xamarin_mac(path_targets, WhichLib.E_SQLITE3);
common.write_nuspec_file_entry(
relpath_targets,
string.Format("buildTransitive\\{0}", TFM.XAMARINMAC20.AsString()),
f
);
}
#endif
#if not
{
var tname = string.Format("{0}.targets", id);
Expand All @@ -486,6 +513,9 @@ private static void gen_nuspec_lib_e_sqlite3(string dir_src)
// TODO need a comment here to explain these
common.write_empty(f, TFM.NET461);
common.write_empty(f, TFM.NETSTANDARD20);
#if not
common.write_empty(f, TFM.XAMARINMAC20);
#endif

f.WriteEndElement(); // files

Expand Down Expand Up @@ -609,11 +639,64 @@ XmlWriter f
f.WriteEndElement(); // Content
}

static void write_nuget_prop_item(
string rid,
WhichLib lib,
XmlWriter f
)
{
var suffix = get_lib_suffix_from_rid(rid);
var filename = lib.AsString_libname_in_nupkg(suffix);

var rid_idsafe = rid.Replace("-", "_");
var prop_name = $"path__{lib.AsString_basename_in_nupkg()}__{rid_idsafe}";

f.WriteElementString(prop_name, string.Format("$(MSBuildThisFileDirectory)..\\runtimes\\{0}\\native\\{1}", rid, filename));
}

private static void gen_nuget_props(string dest, WhichLib lib)
{
var settings = common.XmlWriterSettings_default();
settings.OmitXmlDeclaration = false;

using (XmlWriter f = XmlWriter.Create(dest, settings))
{
f.WriteStartDocument();
f.WriteComment("Automatically generated");

f.WriteStartElement("Project", "http://schemas.microsoft.com/developer/msbuild/2003");
f.WriteAttributeString("ToolsVersion", "4.0");

f.WriteStartElement("PropertyGroup");
write_nuget_prop_item("win-x86", lib, f);
write_nuget_prop_item("win-x64", lib, f);
write_nuget_prop_item("win-arm", lib, f);
write_nuget_prop_item("osx-x64", lib, f);
write_nuget_prop_item("osx-arm64", lib, f);
write_nuget_prop_item("linux-x86", lib, f);
write_nuget_prop_item("linux-x64", lib, f);
write_nuget_prop_item("linux-arm", lib, f);
write_nuget_prop_item("linux-armel", lib, f);
write_nuget_prop_item("linux-arm64", lib, f);
write_nuget_prop_item("linux-x64", lib, f);
write_nuget_prop_item("linux-mips64", lib, f);
write_nuget_prop_item("linux-s390x", lib, f);
f.WriteEndElement(); // PropertyGroup

f.WriteEndElement(); // Project

f.WriteEndDocument();
}
}

private static void gen_nuget_targets(string dest, WhichLib lib)
{
var settings = common.XmlWriterSettings_default();
settings.OmitXmlDeclaration = false;

// TODO these targets appear to be for old situations where RuntimeIdentifier
// was not set, like desktop mono, pre-net6 days

using (XmlWriter f = XmlWriter.Create(dest, settings))
{
f.WriteStartDocument();
Expand All @@ -631,6 +714,7 @@ private static void gen_nuget_targets(string dest, WhichLib lib)

f.WriteStartElement("ItemGroup");
f.WriteAttributeString("Condition", " '$(RuntimeIdentifier)' == '' AND '$(OS)' == 'Unix' AND Exists('/Library/Frameworks') ");
// TODO in what case does this make sense?
write_nuget_target_item("osx-x64", lib, f);
f.WriteEndElement(); // ItemGroup

Expand All @@ -652,6 +736,54 @@ private static void gen_nuget_targets(string dest, WhichLib lib)
}
}

#if not
private static void gen_nuget_targets_legacy_xamarin_mac(string dest, WhichLib lib)
{
var settings = common.XmlWriterSettings_default();
settings.OmitXmlDeclaration = false;

using (XmlWriter f = XmlWriter.Create(dest, settings))
{
f.WriteStartDocument();
f.WriteComment("Automatically generated");

f.WriteStartElement("Project", "http://schemas.microsoft.com/developer/msbuild/2003");
f.WriteAttributeString("ToolsVersion", "4.0");

var filename = lib.AsString_libname_in_nupkg(LibSuffix.DYLIB);

// --------
f.WriteStartElement("ItemGroup");
f.WriteAttributeString("Condition", " '$(RuntimeIdentifier)' == 'osx-x64' ");

f.WriteStartElement("NativeFileReference");
f.WriteAttributeString("Include", string.Format("$(MSBuildThisFileDirectory)..\\..\\runtimes\\osx-x64\\native\\{0}", filename));
f.WriteElementString("Kind", "Dynamic");
f.WriteElementString("SmartLink", "False");
f.WriteEndElement(); // NativeFileReference

f.WriteEndElement(); // ItemGroup

// --------
f.WriteStartElement("ItemGroup");
f.WriteAttributeString("Condition", " '$(RuntimeIdentifier)' == 'osx-arm64' ");

f.WriteStartElement("NativeFileReference");
f.WriteAttributeString("Include", string.Format("$(MSBuildThisFileDirectory)..\\..\\runtimes\\osx-arm64\\native\\{0}", filename));
f.WriteElementString("Kind", "Dynamic");
f.WriteElementString("SmartLink", "False");
f.WriteEndElement(); // NativeFileReference

f.WriteEndElement(); // ItemGroup

f.WriteEndElement(); // Project

f.WriteEndDocument();
}

}
#endif

private static void gen_nuget_targets_wasm(string dest, WhichLib lib)
{
var settings = common.XmlWriterSettings_default();
Expand All @@ -672,7 +804,7 @@ private static void gen_nuget_targets_wasm(string dest, WhichLib lib)

f.WriteStartElement("NativeFileReference");
f.WriteAttributeString("Include", string.Format("$(MSBuildThisFileDirectory)..\\..\\runtimes\\browser-wasm\\nativeassets\\net6.0\\{0}", filename));
f.WriteEndElement(); // Content
f.WriteEndElement(); // NativeFileReference

f.WriteEndElement(); // ItemGroup

Expand Down
6 changes: 3 additions & 3 deletions version_stamp/version_stamp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static class gen

public const int MAJOR_VERSION = 2;
public const int MINOR_VERSION = 1;
public const int PATCH_VERSION = 1;
public const int PATCH_VERSION = 2;

// a version string with a -pre-timestamp in it
public static string NUSPEC_VERSION_PRE_TIMESTAMP = string.Format("{0}.{1}.{2}-pre{3}",
Expand All @@ -51,9 +51,9 @@ public static class gen
);

// keep one of the following 3
//public static string NUSPEC_VERSION = NUSPEC_VERSION_PRE_TIMESTAMP;
public static string NUSPEC_VERSION = NUSPEC_VERSION_PRE_TIMESTAMP;
//public static string NUSPEC_VERSION = NUSPEC_VERSION_PRE;
public static string NUSPEC_VERSION = NUSPEC_VERSION_RELEASE;
//public static string NUSPEC_VERSION = NUSPEC_VERSION_RELEASE;

public static string ASSEMBLY_VERSION = string.Format("{0}.{1}.{2}.{3}",
MAJOR_VERSION,
Expand Down

0 comments on commit 2e1baf6

Please sign in to comment.