Skip to content

Commit

Permalink
Merge pull request #5211 from NREL/CSharp
Browse files Browse the repository at this point in the history
CSharp - Update for conan V2 and build for 3.8.0 (+ add arm64)
  • Loading branch information
jmarrec authored May 22, 2024
2 parents 22beb86 + 8d7675f commit cdee54c
Show file tree
Hide file tree
Showing 9 changed files with 425 additions and 291 deletions.
595 changes: 336 additions & 259 deletions .github/workflows/buildCSharp.yml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions .github/workflows/python_bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ jobs:
shell: cmd
run: |
echo "::group::Conan Install"
conan install . --output-folder=./build --build=missing -c tools.cmake.cmaketoolchain:generator=Ninja -s compiler.cppstd=20 -s build_type=Release -o 'openstudio/:*with_testing=False' -o 'openstudio/:*with_benchmark=False'
conan install . --output-folder=./build --build=missing -c tools.cmake.cmaketoolchain:generator=Ninja -s compiler.cppstd=20 -s build_type=Release -o with_testing=False -o with_benchmark=False
echo "::engroup::"
echo "::group::CMake Configure"
Expand All @@ -265,9 +265,9 @@ jobs:
begin_group "Conan install"
if [ "$RUNNER_OS" == "macOS" ]; then
# Avoid "builtin __has_nothrow_assign is deprecated; use __is_nothrow_assignable instead" in boost/1.79 with recent clang
conan install . --output-folder=./build --build=missing -c tools.cmake.cmaketoolchain:generator=Ninja -s compiler.cppstd=20 -s build_type=Release -o 'openstudio/:*with_testing=False' -o 'openstudio/:*with_benchmark=False' -c tools.build:cxxflags="['-D_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION']"
conan install . --output-folder=./build --build=missing -c tools.cmake.cmaketoolchain:generator=Ninja -s compiler.cppstd=20 -s build_type=Release -o with_testing=False -o with_benchmark=False -c tools.build:cxxflags="['-D_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION']"
else
conan install . --output-folder=./build --build=missing -c tools.cmake.cmaketoolchain:generator=Ninja -s compiler.cppstd=20 -s build_type=Release -o 'openstudio/:*with_testing=False' -o 'openstudio/:*with_benchmark=False'
conan install . --output-folder=./build --build=missing -c tools.cmake.cmaketoolchain:generator=Ninja -s compiler.cppstd=20 -s build_type=Release -o with_testing=False -o with_benchmark=False
fi
echo -e "::endgroup::"
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,8 @@ elseif(WIN32)
else()
set(ENERGYPLUS_PATH "EnergyPlus-${ENERGYPLUS_VERSION}-${ENERGYPLUS_BUILD_SHA}-Windows-i386")
set(ENERGYPLUS_ARCH 32)
set(ENERGYPLUS_EXPECTED_HASH NOT_AVAILABLE_ON_RELEASE)
set(ENERGYPLUS_EXPECTED_HASH 766cf42388ca5b682800fe6ded8ac3ee)
set(ENERGYPLUS_REPO "jmarrec")
endif()
if(EXISTS "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}.zip")
file(MD5 "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}.zip" ENERGYPLUS_HASH)
Expand Down
5 changes: 3 additions & 2 deletions conan.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"websocketpp/0.8.2#842a0419153a8aa52f3ea3a1da557d38%1695972005.713",
"tinygltf/2.5.0#65c28d0a4c3cbd4ef92b08b59df769da%1701621757.442",
"termcap/1.3.1#1986f84bf21dd07ea774b027a3201fcb%1678542508.75",
"swig/4.1.1#8f418438101ef7712d52a9fe739d32f9%1707838298.077707",
"swig/4.1.1#2bb5c79321cbb05bcab525c690d9bf74%1716336914.081294",
"stb/cci.20230920#9792498b81cf34a90138d239e36b0bf8%1700546289.605",
"sqlite3/3.38.5#4b875d4249cdfb4c1235e6b3ea6c18e7%1676251415.466",
"ruby/3.2.2#7a66613b28107b3318a6ff60701c1b6b%1707386606.655",
Expand Down Expand Up @@ -56,5 +56,6 @@
"boost/1.83.0": [
"boost/1.79.0#d8a5b9e748e4152d6f489d7d87a1f129"
]
}
},
"config_requires": []
}
48 changes: 29 additions & 19 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,23 @@ class OpenStudioBuildRecipe(ConanFile):
generators = "CMakeDeps" # CMakeToolchain explicitly instantiated

options = {
"with_ruby": [True, False],
"with_python": [True, False],
"with_csharp": [True, False],
"with_testing": [True, False],
"with_benchmark": [True, False],
}
default_options = {
"with_ruby": True,
"with_python": True,
"with_csharp": False,
"with_testing": True,
"with_benchmark": True,
}

def requirements(self):
self.requires("ruby/3.2.2")
if self.options.with_ruby:
self.requires("ruby/3.2.2")

if is_apple_os(self):
self.requires(
Expand Down Expand Up @@ -67,10 +74,12 @@ def requirements(self):
def generate(self):
tc = CMakeToolchain(self)

tc.cache_variables["BUILD_CLI"] = True
tc.cache_variables["BUILD_RUBY_BINDINGS"] = True
tc.cache_variables["BUILD_PYTHON_BINDINGS"] = True
tc.cache_variables["BUILD_PYTHON_PIP_PACKAGE"] = False
tc.cache_variables["BUILD_CLI"] = bool(self.options.with_ruby)
tc.cache_variables["BUILD_RUBY_BINDINGS"] = bool(self.options.with_ruby)
tc.cache_variables["BUILD_PYTHON_BINDINGS"] = bool(self.options.with_python)
tc.cache_variables["BUILD_CSHARP_BINDINGS"] = bool(self.options.with_csharp)
# tc.cache_variables["BUILD_NUGET_PACKAGE"] = False
# tc.cache_variables["BUILD_PYTHON_PIP_PACKAGE"] = False

tc.cache_variables["BUILD_TESTING"] = bool(self.options.with_testing)
tc.cache_variables["BUILD_BENCHMARK"] = bool(self.options.with_benchmark)
Expand All @@ -90,18 +99,19 @@ def generate(self):
tc.cache_variables["CPACK_BINARY_TXZ"] = False
tc.cache_variables["CPACK_BINARY_TZ"] = False

v = sys.version_info
if (v.major, v.minor) == (3, 8):
python_version = f"{v.major}.{v.minor}.{v.micro}"
self.output.info(
f"Setting PYTHON_VERSION and Python_ROOT_DIR from your current python: {python_version}, '{sys.base_prefix}'"
)
tc.cache_variables["PYTHON_VERSION"] = python_version
tc.cache_variables["Python_ROOT_DIR"] = str(Path(sys.base_prefix))
else:
self.output.warning(
"Your current python is not in the 3.8.x range, which is what we target.\n"
"You'll need to pass it properly when configuring CMake\n"
"via -DPYTHON_VERSION:STRING='3.8.xx' and -DPython_ROOT_DIR:PATH='/path/to/python3.8/'"
)
if self.options.with_python:
v = sys.version_info
if (v.major, v.minor) == (3, 8):
python_version = f"{v.major}.{v.minor}.{v.micro}"
self.output.info(
f"Setting PYTHON_VERSION and Python_ROOT_DIR from your current python: {python_version}, '{sys.base_prefix}'"
)
tc.cache_variables["PYTHON_VERSION"] = python_version
tc.cache_variables["Python_ROOT_DIR"] = str(Path(sys.base_prefix))
else:
self.output.warning(
"Your current python is not in the 3.8.x range, which is what we target.\n"
"You'll need to pass it properly when configuring CMake\n"
"via -DPYTHON_VERSION:STRING='3.8.xx' and -DPython_ROOT_DIR:PATH='/path/to/python3.8/'"
)
tc.generate()
15 changes: 15 additions & 0 deletions csharp/OpenStudio-osx-arm64.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="PlatformCheck" BeforeTargets="InjectReference"
Condition="'$(Platform)' != 'arm64'">
<Error Text="$(MSBuildThisFileName) does not work correctly on '$(Platform)' platform. You need to specify platform (arm64)." />
</Target>

<Target Name="InjectReference" BeforeTargets="ResolveAssemblyReferences">
<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)/../runtimes/osx-arm64/native/**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Target>
</Project>
34 changes: 27 additions & 7 deletions csharp/developer/OpenStudio/OpenStudio.csproj.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugType>full</DebugType>
<DebugType>full</DebugType>
</PropertyGroup>

<!-- Linux:
libopenstudio_csharp.so
libopenstudio_model_csharp.so
libopenstudio_translators_csharp.so
libopenstudiolib.so
libopenstudiolib.so
-->

<!-- Mac:
libopenstudio_csharp.dylib
libopenstudio_model_csharp.dylib
libopenstudio_translators_csharp.dylib
libopenstudiolib.dylib
libopenstudiolib.dylib
-->

<!-- Windows:
Expand All @@ -58,25 +58,45 @@ openstudiolib.dll
-->

<Target Name="IncludeReferencedLibInPackage" DependsOnTargets="BuildOnlySettings;ResolveReferences">
<Message Text="DEBUGGING: OS=$(OS) TargetFramework=$(TargetFramework) Architecture=$(Architecture) Platform=$(Platform) RID=$(Rid)" />
<Message Text="DEBUGGING: is_osx1=$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX))) is_osx2=$([MSBuild]::IsOsPlatform('OSX'))" />
<Message Text="DEBUGGING: System.Runtime.InteropServices.RuntimeInformation: OSArchitecture=$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture), RuntimeIdentifier=$([System.Runtime.InteropServices.RuntimeInformation]::RuntimeIdentifier), OSDescription=$([System.Runtime.InteropServices.RuntimeInformation]::OSDescription)" />
<PropertyGroup>
<Rid>$([System.Runtime.InteropServices.RuntimeInformation]::RuntimeIdentifier)</Rid>
<IsLinux>$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))</IsLinux>
<IsDarwin>$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))</IsDarwin>
<IsWindows>$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))</IsWindows>
<IsArm64>False</IsArm64>
<IsArm64 Condition=" '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64' ">true</IsArm64>
</PropertyGroup>
<Message Text="DEBUGGING: Rid=$(Rid), IsLinux=$(IsLinux), IsDarwin=$(IsDarwin), IsWindows=$(IsWindows), IsArm64=$(IsArm64), IsNotArm64=$(IsNotArm64)" />
<Message Condition=" $(IsDarwin) And !$(IsArm64) " Text="Darwin not arm64" />
<Message Condition=" $(IsDarwin) And $(IsArm64) " Text="Darwin arm64" />
<!-- for Windows -->
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
<ItemGroup Condition=" $(IsWindows) ">
<TfmSpecificPackageFile Include="../Products/Release/openstudio*csharp.dll" PackagePath="lib/$(TargetFramework)" />
<TfmSpecificPackageFile Include="../Products/Release/openstudiolib.dll" PackagePath="lib/$(TargetFramework)" />
</ItemGroup>

<!-- for Linux -->
<ItemGroup Condition=" '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' ">
<ItemGroup Condition=" $(IsLinux) ">
<TfmSpecificPackageFile Include="../Products/*openstudio*csharp.so" PackagePath="runtimes/linux-x64/native" />
<TfmSpecificPackageFile Include="../Products/*openstudiolib.so" PackagePath="runtimes/linux-x64/native" />
<TfmSpecificPackageFile Include="../Products/OpenStudio-linux-x64.targets" PackagePath="build/OpenStudio.targets" />
</ItemGroup>

<!-- for Mac -->
<ItemGroup Condition=" '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' ">
<ItemGroup Condition=" $(IsDarwin) And !$(IsArm64) ">
<TfmSpecificPackageFile Include="../Products/*openstudio*csharp.dylib" PackagePath="runtimes/osx-x64/native" />
<TfmSpecificPackageFile Include="../Products/*openstudiolib.dylib" PackagePath="runtimes/osx-x64/native" />
<TfmSpecificPackageFile Include="../Products/OpenStudio-osx-x64.targets" PackagePath="build/OpenStudio.targets" />
</ItemGroup>
<ItemGroup Condition=" $(IsDarwin) And $(IsArm64) ">
<TfmSpecificPackageFile Include="../Products/*openstudio*csharp.dylib" PackagePath="runtimes/$(Rid)/native" />
<TfmSpecificPackageFile Include="../Products/*openstudiolib.dylib" PackagePath="runtimes/$(Rid)/native" />
<TfmSpecificPackageFile Include="../Products/OpenStudio-$(Rid).targets" PackagePath="build/OpenStudio.targets" />
</ItemGroup>

</Target>

</Project>
9 changes: 9 additions & 0 deletions src/measure/Measure.i
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
// Help in overload resolution preferring std::string over char const *
%ignore openstudio::measure::OSArgument::setValue(char const*);
%ignore openstudio::measure::OSArgument::setDefaultValue(char const*);

// Ignore Json::Value return type (toJSON / fromJSON / valueAsJSON are globally ignored already)
%ignore openstudio::measure::OSArgument::defaultValueAsJSON;
%ignore openstudio::measure::OSArgument::domainAsJSON;
%ignore openstudio::measure::OSRunner::getArgumentValues;
%ignore openstudio::measure::OSRunner::getPastStepValuesForMeasure;
%ignore openstudio::measure::OSRunner::getPastStepValuesForName;


#elif defined(SWIGPYTHON)
// Avoid triggering a SWIG warning: 'print' is a python keyword
%rename(toString) openstudio::measure::OSArgument::print;
Expand Down
1 change: 1 addition & 0 deletions src/utilities/core/jsoncpp.i
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// ignores toJSON/fromJSON globally
%rename("$ignore", regextarget=1, fullname=1) "openstudio::.*::toJSON$";
%rename("$ignore", regextarget=1, fullname=1) "openstudio::.*::fromJSON$";
%rename("$ignore", regextarget=1, fullname=1) "openstudio::.*::valueAsJSON$";
#else
%{
#include <json/value.h>
Expand Down

0 comments on commit cdee54c

Please sign in to comment.