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

Fix #4931 - Install C# OpenStudio.dll properly. #4933

Merged
merged 6 commits into from
Aug 24, 2023

Conversation

jmarrec
Copy link
Collaborator

@jmarrec jmarrec commented Jul 19, 2023

Pull request overview

Let's see if CI makes an installer with the OpenStudio.dll

Pull Request Author

  • Model API Changes / Additions
  • Any new or modified fields have been implemented in the EnergyPlus ForwardTranslator (and ReverseTranslator as appropriate)
  • Model API methods are tested (in src/model/test)
  • EnergyPlus ForwardTranslator Tests (in src/energyplus/Test)
  • If a new object or method, added a test in NREL/OpenStudio-resources: Add Link
  • If needed, added VersionTranslation rules for the objects (src/osversion/VersionTranslator.cpp)
  • Verified that C# bindings built fine on Windows, partial classes used as needed, etc.
  • All new and existing tests passes
  • If methods have been deprecated, update rest of code to use the new methods

Labels:

  • If change to an IDD file, add the label IDDChange
  • If breaking existing API, add the label APIChange
  • If deemed ready, add label Pull Request - Ready for CI so that CI builds your PR

Review Checklist

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • Code Style, strip trailing whitespace, etc.
  • All related changes have been implemented: model changes, model tests, FT changes, FT tests, VersionTranslation, OS App
  • Labeling is ok
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified

@jmarrec jmarrec added component - C# Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge. labels Jul 19, 2023
@jmarrec jmarrec self-assigned this Jul 19, 2023
@@ -60,14 +61,11 @@ target_compile_options(csharp_warnings INTERFACE "$<${is_gnu_or_clang_genex}:-Wn
# custom command to make OPENSTUDIO_CSHARP_DLL
add_custom_command(
OUTPUT ${OPENSTUDIO_CSHARP_DLL}
COMMAND "${DOTNET}" "build" "-c" "$<CONFIGURATION>" "/p:Platform=${CSHARP_PLATFORM}" "${PROJECT_BINARY_DIR}/csharp_wrapper/OpenStudio.csproj"
COMMAND "${DOTNET}" "build" "-c" "$<CONFIG>" "/p:Platform=${CSHARP_PLATFORM}" "${PROJECT_BINARY_DIR}/csharp_wrapper/OpenStudio.csproj"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONFIGURATION genex is deprecated since cmake 3.0 and replaced with CONFIG

install(FILES "${OPENSTUDIO_CSHARP_DLL}" DESTINATION CSharp/openstudio/ CONFIGURATIONS DEBUG COMPONENT "CSharpAPI")


install(FILES "${OPENSTUDIO_CSHARP_DLL}" DESTINATION CSharp/openstudio/ COMPONENT "CSharpAPI")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Install it regardless of the configuration. It was done only for DEBUG prior

Comment on lines 51 to 52
# Note: can't use CMAKE_BUILD_TYPE as it's empty for multi generators (MSVC for eg). So we use a genex
set(OPENSTUDIO_CSHARP_DLL "${CSHARP_LIBRARY_OUTPUT_DIRECTORY}/$<CONFIG>/netstandard2.0/OpenStudio.dll")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the note.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced the CMAKE_BUILD_TYPE with a genex too. This was working on CI because we do pass explicitly cmake -DCMAKE_BUILD_TYPE:STRING=Release when building on MSVC. But MSVC by default is Multi-configuration and CMAKE_BUILD_TYPE is empty if used like this.

Comment on lines +1219 to +1221
if (BUILD_CSHARP_BINDINGS)
install(FILES ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} DESTINATION "CSharp/openstudio/" COMPONENT "CSharpAPI")
endif()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't install the runtimes libs there if C# isn't selected to begin with.

This threw me off when I was looking at the CI-built packages, because actually the incremental runner does not build C#!

Comment on lines +329 to +330
# The -py3 flag is now deprecated as Python 3 is the default the version used is Python 3
set(SWIG_PYTHON_3_FLAGS "-relativeimport")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated cleanup: Avoid having multiple warnings from swig saying "-py3 flag is deprecated"

@@ -66,7 +66,7 @@
// and nested classes and "nothing known about <type>"
// also ignoring #509, shadowed method. Its a red herring for all of our cases
//#pragma SWIG nowarn=401,362,365,366,368,378,503,801,312
#pragma SWIG nowarn=362,365,366,368,378,503,801,312,509,401
#pragma SWIG nowarn=362,365,366,368,378,503,801,312,509,401,516
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid thousands of "overloaded method ignore, using XXX instead". In particular for every modelObject, the Ctor is overloaded (rule of 5/6) so it was getting out of control.

@@ -9,7 +9,7 @@ set(Python_USE_STATIC_LIBS OFF)
if (PYTHON_VERSION)
find_package(Python ${PYTHON_VERSION} EXACT REQUIRED COMPONENTS Interpreter Development OPTIONAL_COMPONENTS NumPy)
else()
find_package(Python REQUIRED COMPONENTS Interpreter Development OPTIONAL_COMPONENTS NumPy)
find_package(Python 3 EXACT REQUIRED COMPONENTS Interpreter Development OPTIONAL_COMPONENTS NumPy)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Force finding python3, not python2, related to SWIG using py3 now. Python 2 is EOL since 2020 anyways, we do not want to support it.

@@ -511,7 +499,7 @@ macro(MAKE_SWIG_TARGET NAME SIMPLENAME KEY_I_FILE I_FILES PARENT_TARGET PARENT_S
# This is not working: "cannot open file 'python37.lib'"
target_link_libraries(${swig_target} PUBLIC ${${PARENT_TARGET}_depends})
if (MSVC)
message("Python_LIBRARIES=${Python_LIBRARIES}")
message(DEBUG "Python_LIBRARIES=${Python_LIBRARIES}")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shush this message too

Comment on lines +5 to +7
// ignores toJSON/fromJSON globally
%rename("$ignore", regextarget=1, fullname=1) "openstudio::.*::toJSON$";
%rename("$ignore", regextarget=1, fullname=1) "openstudio::.*::fromJSON$";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If SWIGCSHARP, ignore toJSON and fromJSON globally.

Comment on lines +21 to +25
// Ignore Json::Value return type (toJSON / fromJSON are globally ignored already)
%ignore openstudio::StandardsJSON::getPrimaryKey;

%ignore openstudio::CustomOutputAdapter::CustomOutputAdapter;
%ignore openstudio::CustomOutputAdapter::optionsJSON;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore other Json::Value related things in Filetypes.i when C#

Copy link
Collaborator Author

@jmarrec jmarrec Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will unbrick the develop build (@wenyikuang FYI), which fails due to this problem currently, after the merge of #4917 (which we didn't realize it was going to break the build because the CI incremental windows runner does not build c# bindings...), cf https://ci.openstudio.net/blue/organizations/jenkins/openstudio-develop-full/detail/openstudio-develop-full/360/pipeline/98#step-101-log-921

D:\OSN\build\csharp_wrapper\generated_sources\OpenStudioUtilitiesData\SWIGTYPE_p_Json__Value.cs(13,14): 
error CS0101: The namespace 'OpenStudio' already contains a definition for 'SWIGTYPE_p_Json__Value' [D:\OSN\build\csharp_wrapper\OpenStudio.csproj]

D:\OSN\build\csharp_wrapper\generated_sources\OpenStudioUtilitiesFileTypes\SWIGTYPE_p_Json__Value.cs(13,14): 
error CS0101: The namespace 'OpenStudio' already contains a definition for 'SWIGTYPE_p_Json__Value' [D:\OSN\build\csharp_wrapper\OpenStudio.csproj]

D:\OSN\build\csharp_wrapper\generated_sources\OpenStudioUtilitiesData\SWIGTYPE_p_Json__Value.cs(16,12): error CS0111: Type 'SWIGTYPE_p_Json__Value' already defines a member called 'SWIGTYPE_p_Json__Value' with the same parameter types [D:\OSN\build\csharp_wrapper\OpenStudio.csproj]

D:\OSN\build\csharp_wrapper\generated_sources\OpenStudioUtilitiesData\SWIGTYPE_p_Json__Value.cs(20,13): error CS0111: Type 'SWIGTYPE_p_Json__Value' already defines a member called 'SWIGTYPE_p_Json__Value' with the same parameter types [D:\OSN\build\csharp_wrapper\OpenStudio.csproj]

D:\OSN\build\csharp_wrapper\generated_sources\OpenStudioUtilitiesFileTypes\SWIGTYPE_p_Json__Value.cs(16,12): error CS0111: Type 'SWIGTYPE_p_Json__Value' already defines a member called 'SWIGTYPE_p_Json__Value' with the same parameter types [D:\OSN\build\csharp_wrapper\OpenStudio.csproj]

@jmarrec
Copy link
Collaborator Author

jmarrec commented Aug 24, 2023

Running a full build on this branch at https://ci.openstudio.net/blue/organizations/jenkins/openstudio-develop-full/detail/openstudio-develop-full/363/pipeline/11

Meh that failed due to a mt python error (concurrency?), replaying on the windows build at 364.
mt.exe : general error c101008d: Failed to write the updated manifest to the resource of file "Products\python\_openstudioutilitiesgeometry.pyd". Access is denied.

I Tested the changes locally on Windows 10 + macOS m1 too. C# build now works, and I do get the installed OpenStudio.dll

@jmarrec
Copy link
Collaborator Author

jmarrec commented Aug 24, 2023

Ok 364 replay worked on windows as well: https://ci.openstudio.net/blue/organizations/jenkins/openstudio-develop-full/detail/openstudio-develop-full/364/pipeline/

Testing the windows installer to see if the OpenStudio.dll is in there

OpenStudio-3.7.0-alpha+709fec93d1-Windows$ find . -name "*.dll"
./CSharp/openstudio/openstudio_model_csharp.dll
./CSharp/openstudio/vcruntime140_1.dll
./CSharp/openstudio/msvcp140_1.dll
./CSharp/openstudio/vcruntime140.dll
./CSharp/openstudio/concrt140.dll
./CSharp/openstudio/openstudio_csharp.dll
./CSharp/openstudio/msvcp140_2.dll
./CSharp/openstudio/openstudio_translators_csharp.dll
./CSharp/openstudio/msvcp140.dll
./CSharp/openstudio/msvcp140_atomic_wait.dll
+./CSharp/openstudio/OpenStudio.dll
./CSharp/openstudio/msvcp140_codecvt_ids.dll

@jmarrec jmarrec merged commit a04ae99 into develop Aug 24, 2023
2 checks passed
@jmarrec jmarrec deleted the 4931_Csharp_OpenStudio_dll branch August 24, 2023 12:37
@jmarrec
Copy link
Collaborator Author

jmarrec commented Aug 24, 2023

Merging right away, tested it works, and this is going to fix develop nightly builds which is important!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component - C# Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Why is OpenStudio.dll no longer included in the installers?
2 participants