diff --git a/.gitignore b/.gitignore index a39e00c6d..b29c47920 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,12 @@ /Code/JavaWrappers/gmwrapper/doc/* /Code/JavaWrappers/gmwrapper/build/* /Code/JavaWrappers/gmwrapper/build-test/* -/Code/JavaWrappers/csharp_wrapper/swig_csharp +/Code/JavaWrappers/csharp_wrapper/swig_csharp/*.cs +/Code/JavaWrappers/csharp_wrapper/swig_csharp/*.cxx +/Code/JavaWrappers/csharp_wrapper/swig_csharp/bin +/Code/JavaWrappers/csharp_wrapper/swig_csharp/obj +/Code/JavaWrappers/csharp_wrapper/RdkitTests/bin +/Code/JavaWrappers/csharp_wrapper/RdkitTests/obj /Data/Fonts/ComicNeue-* /Data/Fonts/OFL.txt /vcpkg/* diff --git a/CMakeLists.txt b/CMakeLists.txt index c842c5cee..fd8ff70f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ option(RDK_BUILD_SLN_SUPPORT "include support for the SLN format" ON ) option(RDK_TEST_MULTITHREADED "run some tests of multithreading" ON ) option(RDK_BUILD_SWIG_JAVA_WRAPPER "build the SWIG JAVA wrappers (does nothing if RDK_BUILD_SWIG_WRAPPERS is not set)" ON ) option(RDK_BUILD_SWIG_CSHARP_WRAPPER "build the experimental SWIG C# wrappers (does nothing if RDK_BUILD_SWIG_WRAPPERS is not set)" OFF ) +option(RDK_BUILD_DOTNET_CSHARP_TESTS "build the DotNet Core tests for C# wrappers (does nothing if RDK_BUILD_SWIG_CSHARP_WRAPPER is not set)" OFF ) option(RDK_SWIG_STATIC "statically link rdkit libraries into the SWIG wrappers" ON ) option(RDK_TEST_MMFF_COMPLIANCE "run MMFF compliance tests (requires tar/gzip)" ON ) option(RDK_BUILD_CPP_TESTS "build the c++ tests (disabing can speed up builds" ON) diff --git a/Code/JavaWrappers/csharp_wrapper/CMakeLists.txt b/Code/JavaWrappers/csharp_wrapper/CMakeLists.txt index 883997e53..2b13a3f35 100644 --- a/Code/JavaWrappers/csharp_wrapper/CMakeLists.txt +++ b/Code/JavaWrappers/csharp_wrapper/CMakeLists.txt @@ -1,17 +1,6 @@ project (GraphMolCSharp) include_directories( ${RDKit_ExternalDir} ) - -# find the mcs executables on non-windows systems: -if(NOT MSVC) - find_program(GMCS_EXE mcs) - if (NOT GMCS_EXE) - MESSAGE ("mcs (executable) is not found. Please add it to PATH and rerun cmake.") - MESSAGE(FATAL_ERROR "Cannot find required executable mcs") - endif (NOT GMCS_EXE) -endif(NOT MSVC) - - SET_SOURCE_FILES_PROPERTIES(GraphMolCSharp.i PROPERTIES CPLUSPLUS ON ) # Setup a few variables for environment-specific things @@ -92,22 +81,32 @@ SWIG_LINK_LIBRARIES(RDKFuncs ${RDKit_Wrapper_Libs} INSTALL(TARGETS RDKFuncs DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} ) +if (RDK_BUILD_DOTNET_CSHARP_TESTS) -if(NOT MSVC) - # code adapted from the wrapper code for - # GDCM: http://gdcm.svn.sf.net/viewvc/gdcm/trunk/Wrapping/Java/CMakeLists.txt?view=markup - ADD_CUSTOM_COMMAND( - OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/RDKit2DotNet.dll + find_program(DOTNET_EXE dotnet) + if (NOT DOTNET_EXE) + MESSAGE("dotnet (executable) is not found. Pleae add it to PATH and rerun cmake.") + MESSAGE(FATAL_ERROR "Cannot find required executable dotnet") + endif (NOT DOTNET_EXE) - COMMAND ${CMAKE_COMMAND} -E make_directory swig_csharp + ADD_CUSTOM_COMMAND( + OUTPUT RDKitDotNetLib SYMBOLIC + + COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ${DOTNET_EXE} build RDKitDotNetCore.sln + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS RDKFuncs + ) + + ADD_CUSTOM_TARGET(RDKitDotNet ALL + DEPENDS RDKFuncs RDKitDotNetLib + COMMENT "Building RDKit DotNet project" + ) + + ADD_TEST( + NAME CSharpTests + COMMAND ${DOTNET_EXE} test RDKitDotNetCore.sln "-l:console$verbosity=normal" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) - ## 1. run this custom command only after swig has been run. - COMMAND ${GMCS_EXE} -platform:${PLATFORM} -out:RDKit2DotNet.dll -t:library "swig_csharp/*.cs" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - DEPENDS "${swig_generated_file_fullname}" - ) - ADD_CUSTOM_TARGET(RDKFuncsDLL ALL - DEPENDS RDKFuncs ${CMAKE_CURRENT_SOURCE_DIR}/RDKit2DotNet.dll - COMMENT "building mono dll" - ) -endif(NOT MSVC) +endif() diff --git a/Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/MolToFromByteArray.cs b/Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/MolToFromByteArray.cs deleted file mode 100644 index 7a91c5ebb..000000000 --- a/Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/MolToFromByteArray.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Linux: -// compile with -// mcs -platform:x64 -r:../RDKit2DotNet.dll -out:MolToFromByteArray.exe MolToFromByteArray.cs -// and run with -// LD_LIBRARY_PATH=..:$RDBASE/lib:$LD_LIBRARY_PATH MONO_PATH=.. mono MolToFromByteArray.exe - -using System.IO; -using System.Diagnostics; -using GraphMolWrap; - -public class MolToFromByteArrayTest -{ - static void Main(string[] args) - { - string smi = "CN(C)c1ccc2c(=O)cc[nH]c2c1"; - string pklFileName = "quinolone.pkl"; - { - ROMol mol = RWMol.MolFromSmiles(smi); - byte[] pkl = mol.ToByteArray(); - File.WriteAllBytes(pklFileName, pkl); - mol.Dispose(); - } - { - byte[] pkl = File.ReadAllBytes(pklFileName); - ROMol mol = ROMol.FromByteArray(pkl); - Debug.Assert(mol.MolToSmiles() == smi); - mol.Dispose(); - } - } -} \ No newline at end of file diff --git a/Code/JavaWrappers/csharp_wrapper/RDKitDotNetCore.sln b/Code/JavaWrappers/csharp_wrapper/RDKitDotNetCore.sln new file mode 100644 index 000000000..fdbd2dffb --- /dev/null +++ b/Code/JavaWrappers/csharp_wrapper/RDKitDotNetCore.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RDKitDotNetCoreWrapper", "swig_csharp\RDKitDotNetCoreWrapper.csproj", "{B97DDA0A-D8BF-4653-926B-F13DFC27FA7C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RDKitCSharpTest", "RdkitTests\RDKitCSharpTest.csproj", "{65A680C7-921C-47CF-9737-BF8726396B92}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B97DDA0A-D8BF-4653-926B-F13DFC27FA7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B97DDA0A-D8BF-4653-926B-F13DFC27FA7C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B97DDA0A-D8BF-4653-926B-F13DFC27FA7C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B97DDA0A-D8BF-4653-926B-F13DFC27FA7C}.Release|Any CPU.Build.0 = Release|Any CPU + {65A680C7-921C-47CF-9737-BF8726396B92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {65A680C7-921C-47CF-9737-BF8726396B92}.Debug|Any CPU.Build.0 = Debug|Any CPU + {65A680C7-921C-47CF-9737-BF8726396B92}.Release|Any CPU.ActiveCfg = Release|Any CPU + {65A680C7-921C-47CF-9737-BF8726396B92}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/ExplicitBitVectTest.cs b/Code/JavaWrappers/csharp_wrapper/RdkitTests/ExplicitBitVectTest.cs similarity index 100% rename from Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/ExplicitBitVectTest.cs rename to Code/JavaWrappers/csharp_wrapper/RdkitTests/ExplicitBitVectTest.cs diff --git a/Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/GeneralizedSubstructTest.cs b/Code/JavaWrappers/csharp_wrapper/RdkitTests/GeneralizedSubstructTest.cs similarity index 100% rename from Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/GeneralizedSubstructTest.cs rename to Code/JavaWrappers/csharp_wrapper/RdkitTests/GeneralizedSubstructTest.cs diff --git a/Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/MolDraw2DCairoTest.cs b/Code/JavaWrappers/csharp_wrapper/RdkitTests/MolDraw2DCairoTest.cs similarity index 100% rename from Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/MolDraw2DCairoTest.cs rename to Code/JavaWrappers/csharp_wrapper/RdkitTests/MolDraw2DCairoTest.cs diff --git a/Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/MolDrawHighlightTest.cs b/Code/JavaWrappers/csharp_wrapper/RdkitTests/MolDrawHighlightTest.cs old mode 100755 new mode 100644 similarity index 100% rename from Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/MolDrawHighlightTest.cs rename to Code/JavaWrappers/csharp_wrapper/RdkitTests/MolDrawHighlightTest.cs diff --git a/Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/MolEnumeratorTest.cs b/Code/JavaWrappers/csharp_wrapper/RdkitTests/MolEnumeratorTest.cs similarity index 100% rename from Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/MolEnumeratorTest.cs rename to Code/JavaWrappers/csharp_wrapper/RdkitTests/MolEnumeratorTest.cs diff --git a/Code/JavaWrappers/csharp_wrapper/RdkitTests/MolToFromByteArray.cs b/Code/JavaWrappers/csharp_wrapper/RdkitTests/MolToFromByteArray.cs new file mode 100644 index 000000000..66480aa66 --- /dev/null +++ b/Code/JavaWrappers/csharp_wrapper/RdkitTests/MolToFromByteArray.cs @@ -0,0 +1,36 @@ +// Linux: +// compile with +// mcs -platform:x64 -r:../RDKit2DotNet.dll -out:MolToFromByteArray.exe MolToFromByteArray.cs +// and run with +// LD_LIBRARY_PATH=..:$RDBASE/lib:$LD_LIBRARY_PATH MONO_PATH=.. mono MolToFromByteArray.exe + +using System.IO; +using System.Diagnostics; +using GraphMolWrap; +using Xunit; + +namespace RdkitTests +{ + public class MolToFromByteArrayTest + { + [Fact] + public void TestMolToFromByteArray() + { + string smi = "CN(C)c1ccc2c(=O)cc[nH]c2c1"; + string pklFileName = "quinolone.pkl"; + { + ROMol mol = RWMol.MolFromSmiles(smi); + byte[] pkl = mol.ToByteArray(); + File.WriteAllBytes(pklFileName, pkl); + mol.Dispose(); + } + { + byte[] pkl = File.ReadAllBytes(pklFileName); + ROMol mol = ROMol.FromByteArray(pkl); + Assert.Equal(smi, mol.MolToSmiles()); + mol.Dispose(); + File.Delete(pklFileName); + } + } + } +} \ No newline at end of file diff --git a/Code/JavaWrappers/csharp_wrapper/RdkitTests/RDKitCSharpTest.csproj b/Code/JavaWrappers/csharp_wrapper/RdkitTests/RDKitCSharpTest.csproj new file mode 100644 index 000000000..26a006321 --- /dev/null +++ b/Code/JavaWrappers/csharp_wrapper/RdkitTests/RDKitCSharpTest.csproj @@ -0,0 +1,41 @@ + + + + net8.0 + enable + enable + + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + + + + + + + + Always + + + + diff --git a/Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/RGroupDecompositionTest.cs b/Code/JavaWrappers/csharp_wrapper/RdkitTests/RGroupDecompositionTest.cs similarity index 100% rename from Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/RGroupDecompositionTest.cs rename to Code/JavaWrappers/csharp_wrapper/RdkitTests/RGroupDecompositionTest.cs diff --git a/Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/ToMolMemoryTest.cs b/Code/JavaWrappers/csharp_wrapper/RdkitTests/ToMolMemoryTest.cs similarity index 64% rename from Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/ToMolMemoryTest.cs rename to Code/JavaWrappers/csharp_wrapper/RdkitTests/ToMolMemoryTest.cs index e6db66194..123b8cd28 100644 --- a/Code/JavaWrappers/csharp_wrapper/RDKitCSharpTest/ToMolMemoryTest.cs +++ b/Code/JavaWrappers/csharp_wrapper/RdkitTests/ToMolMemoryTest.cs @@ -7,7 +7,8 @@ namespace RdkitTests { public class ToMolMemoryTest { - private static readonly long hundredMB = 1024 * 1024 * 100; + private static readonly long OneHundredMB = 1024 * 1024 * 100; + private static readonly long TwoHundredMB = OneHundredMB * 2; private static void gc() { @@ -24,22 +25,28 @@ namespace RdkitTests "CC(C)C[C@H](NC(=O)[C@H](CC(=O)O)NC(=O)[C@H](Cc1ccccc1)NC(=O)[C@H](CO)NC(=O)[C@@H]1CCCN1C(=O)[C@H](CCC(N)=O)NC(=O)[C@@H](N)CS)C(=O)N[C@@H](CCC(N)=O)C(=O)N[C@@H](CS)C(=O)O"; var before = Process.GetCurrentProcess().VirtualMemorySize64; + var privateBefore = Process.GetCurrentProcess().PrivateMemorySize64; long after; - for (int i = 0; i < 10000; ++i) + long privateAfter; + for (int i = 0; i < 500; ++i) { - using RWMol mol = RDKFuncs.SmilesToMol(smi); - mol?.Dispose(); - if (i % 1000 == 0) + RWMol mol = RDKFuncs.SmilesToMol(smi); + RWMol mol2 = RWMol.MolFromSmiles(smi); + if (i % 50 == 0) { gc(); after = Process.GetCurrentProcess().VirtualMemorySize64; - Assert.True(after - before < hundredMB); + Assert.True(after - before < TwoHundredMB); + privateAfter = Process.GetCurrentProcess().PrivateMemorySize64; + Assert.True(privateAfter - privateBefore < OneHundredMB); } } gc(); after = Process.GetCurrentProcess().VirtualMemorySize64; - Assert.True(after - before < hundredMB); + Assert.True(after - before < TwoHundredMB); + privateAfter = Process.GetCurrentProcess().PrivateMemorySize64; + Assert.True(privateAfter - privateBefore < OneHundredMB); } [Fact] @@ -65,21 +72,20 @@ M END "; var before = Process.GetCurrentProcess().VirtualMemorySize64; long after; - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < 500; ++i) { - using RWMol mol = RDKFuncs.MolBlockToMol(block); - mol?.Dispose(); - if (i % 1000 == 0) + RWMol mol = RDKFuncs.MolBlockToMol(block); + if (i % 50 == 0) { gc(); after = Process.GetCurrentProcess().VirtualMemorySize64; - Assert.True(after - before < hundredMB); + Assert.True(after - before < TwoHundredMB); } } gc(); after = System.Diagnostics.Process.GetCurrentProcess().PeakVirtualMemorySize64; - Assert.True(after - before < hundredMB); + Assert.True(after - before < TwoHundredMB); } } } \ No newline at end of file diff --git a/Code/JavaWrappers/csharp_wrapper/RdkitTests/Usings.cs b/Code/JavaWrappers/csharp_wrapper/RdkitTests/Usings.cs new file mode 100644 index 000000000..8c927eb74 --- /dev/null +++ b/Code/JavaWrappers/csharp_wrapper/RdkitTests/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/Code/JavaWrappers/csharp_wrapper/RdkitTests/xunit.runner.json b/Code/JavaWrappers/csharp_wrapper/RdkitTests/xunit.runner.json new file mode 100644 index 000000000..7c6944a1d --- /dev/null +++ b/Code/JavaWrappers/csharp_wrapper/RdkitTests/xunit.runner.json @@ -0,0 +1,4 @@ +{ + "parallelizeTestCollections": false, + "maxParallelThreads": -1 +} diff --git a/Code/JavaWrappers/csharp_wrapper/swig_csharp/RDKitDotNetCoreWrapper.csproj b/Code/JavaWrappers/csharp_wrapper/swig_csharp/RDKitDotNetCoreWrapper.csproj new file mode 100644 index 000000000..22ad1c673 --- /dev/null +++ b/Code/JavaWrappers/csharp_wrapper/swig_csharp/RDKitDotNetCoreWrapper.csproj @@ -0,0 +1,15 @@ + + + + net8.0 + enable + enable + + + + + + + + +