Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Internal/ModelImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class ModelImpl : IModel
{
public ModelImpl(string fmuPath)
{
var res = System.Runtime.InteropServices.RuntimeInformation.OSArchitecture;
var res2 = System.Runtime.InteropServices.RuntimeInformation.OSDescription;
try
{
TmpFolder = Path.Combine(Path.GetTempPath(),nameof(Femyou),Path.GetFileName(fmuPath));
Expand All @@ -23,7 +25,7 @@ public ModelImpl(string fmuPath)
.Select(sv => new Variable(sv) as IVariable)
.ToDictionary(sv => sv.Name, sv => sv);
var fmiVersion = root!.Attribute("fmiVersion")?.Value;
ModelVersion = fmiVersion!.StartsWith("2.") ? (IModelVersion) new ModelVersion2() : new ModelVersion3();
ModelVersion = fmiVersion!.StartsWith("2.") ? (IModelVersion)new ModelVersion2() : new ModelVersion3();
var coSimulationId = root
!.Element(ModelVersion.CoSimulationElementName)
!.Attribute("modelIdentifier")
Expand Down
9 changes: 6 additions & 3 deletions src/Internal/ModelVersion2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ public class ModelVersion2 : IModelVersion
{
public string CoSimulationElementName { get; } = "CoSimulation";
public string GuidAttributeName { get; } = "guid";
public string RelativePath(string name, Architecture architecture, PlatformID platform) =>
platform switch
public string RelativePath(string name, Architecture architecture, PlatformID platform)
{
var isDarwin = System.Runtime.InteropServices.RuntimeInformation.OSDescription.Contains("Darwin");
return platform switch
{
PlatformID.Unix => Path.Combine("binaries", "linux" + MapArchitecture(architecture), name + ".so"),
PlatformID.Unix => Path.Combine("binaries", (isDarwin ? "darwin" : "linux") + MapArchitecture(architecture), name + (isDarwin ? ".dylib" : ".so")),
PlatformID.Win32NT => Path.Combine("binaries", "win" + MapArchitecture(architecture), name + ".dll"),
_ => throw new FmuException($"Unsupported operating system {platform}"),
};
}

public Library Load(string path) => new Library2(path);

Expand Down
15 changes: 10 additions & 5 deletions src/Internal/ModelVersion3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ public class ModelVersion3 : IModelVersion
public string CoSimulationElementName { get; } = "BasicCoSimulation";
public string GuidAttributeName { get; } = "instantiationToken";
public Library Load(string path) => new Library3(path);

public string RelativePath(string name, Architecture architecture, PlatformID platform) =>
platform switch

public string RelativePath(string name, Architecture architecture, PlatformID platform)
{
var isDarwin = System.Runtime.InteropServices.RuntimeInformation.OSDescription.Contains("Darwin");
return platform switch
{
PlatformID.Unix => Path.Combine("binaries", MapArchitecture(architecture)+"-linux", name + ".so"),
PlatformID.Win32NT => Path.Combine("binaries", MapArchitecture(architecture)+"-windows", name + ".dll"),
// [VS] MacOS identifies as `Arm64`, but doesn't use `aarch64`.
// Derived from looking at what the reference FMUs build.
PlatformID.Unix => Path.Combine("binaries", isDarwin ? (architecture == Architecture.Arm64 ? "darwin64" : "x86_64-darwin") : MapArchitecture(architecture) + "-linux", name + (isDarwin ? ".dylib" : ".so")),
PlatformID.Win32NT => Path.Combine("binaries", MapArchitecture(architecture) + "-windows", name + ".dll"),
_ => throw new FmuException($"Unsupported operating system {platform}"),
};
}

private string MapArchitecture(Architecture architecture) =>
architecture switch
Expand Down
3 changes: 3 additions & 0 deletions tests/CallbacksTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public class CallbacksTests
public CallbacksTests(int version)
{
_getFmuPath = name => TestTools.GetFmuPath(version, name);
var isDarwin = System.Runtime.InteropServices.RuntimeInformation.OSDescription.Contains("Darwin");
var isArm64 = System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture == System.Runtime.InteropServices.Architecture.Arm64;
Assume.That(version == 3 && isDarwin && isArm64, Is.False);
}
private Func<string, string> _getFmuPath;

Expand Down
4 changes: 4 additions & 0 deletions tests/InstanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public class InstanceTests
public InstanceTests(int version)
{
_getFmuPath = name => TestTools.GetFmuPath(version, name);
var isDarwin = System.Runtime.InteropServices.RuntimeInformation.OSDescription.Contains("Darwin");
var isArm64 = System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture == System.Runtime.InteropServices.Architecture.Arm64;
Assume.That(version == 3 && isDarwin && isArm64, Is.False);

}
private Func<string, string> _getFmuPath;

Expand Down
3 changes: 3 additions & 0 deletions tests/ModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public class ModelTests
public ModelTests(int version)
{
_getFmuPath = name => TestTools.GetFmuPath(version, name);
var isDarwin = System.Runtime.InteropServices.RuntimeInformation.OSDescription.Contains("Darwin");
var isArm64 = System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture == System.Runtime.InteropServices.Architecture.Arm64;
Assume.That(version == 3 && isDarwin && isArm64, Is.False);
}
private readonly Func<string, string> _getFmuPath;

Expand Down