Skip to content

Commit 785fe2f

Browse files
add main remaining updates from Z3Prover#1815
Signed-off-by: Nikolaj Bjorner <[email protected]>
1 parent 5cdbb1f commit 785fe2f

7 files changed

+76
-158
lines changed

contrib/ci/Dockerfiles/z3_base_ubuntu32_16.04.Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ RUN apt-get update && \
3232
libomp-dev \
3333
llvm-3.9 \
3434
make \
35-
mono-devel \
3635
ninja-build \
3736
python3 \
3837
python3-setuptools \
@@ -48,5 +47,6 @@ RUN useradd -m user && \
4847
echo 'user ALL=(root) NOPASSWD: ALL' >> /etc/sudoers
4948
USER user
5049
WORKDIR /home/user
51-
# dotnet core doesn't support x86
50+
# TODO .NET core does not support Linux x86 yet, disable it for now.
51+
# see: https://github.com/dotnet/coreclr/issues/9265
5252
ENV ASAN_SYMBOLIZER_PATH=/usr/lib/llvm-3.9/bin/llvm-symbolizer DOTNET_BINDINGS=0

contrib/ci/Dockerfiles/z3_base_ubuntu_14.04.Dockerfile

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ FROM ubuntu:14.04
22

33
RUN apt-get update && \
44
apt-get -y --no-install-recommends install \
5+
apt-transport-https \
56
binutils \
67
clang-3.9 \
7-
cmake \
8+
curl \
89
doxygen \
910
default-jdk \
1011
gcc-multilib \
@@ -18,13 +19,20 @@ RUN apt-get update && \
1819
lib32gomp1 \
1920
llvm-3.9 \
2021
make \
21-
mono-devel \
2222
ninja-build \
2323
python3 \
2424
python3-setuptools \
2525
python2.7 \
2626
python-setuptools
2727

28+
RUN curl -SL https://packages.microsoft.com/config/ubuntu/14.04/packages-microsoft-prod.deb --output packages-microsoft-prod.deb && \
29+
dpkg -i packages-microsoft-prod.deb && \
30+
apt-get update && \
31+
apt-get -y --no-install-recommends install dotnet-sdk-2.1
32+
33+
RUN curl -SL https://cmake.org/files/v3.12/cmake-3.12.0-Linux-x86_64.sh --output cmake-3.12.0-Linux-x86_64.sh && \
34+
sh cmake-3.12.0-Linux-x86_64.sh --prefix=/usr/local --exclude-subdir
35+
2836
# Create `user` user for container with password `user`. and give it
2937
# password-less sudo access
3038
RUN useradd -m user && \

contrib/ci/Dockerfiles/z3_base_ubuntu_16.04.Dockerfile

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ FROM ubuntu:16.04
22

33
RUN apt-get update && \
44
apt-get -y --no-install-recommends install \
5+
apt-transport-https \
56
binutils \
67
clang \
78
clang-3.9 \
89
cmake \
10+
curl \
911
doxygen \
1012
default-jdk \
1113
gcc-multilib \
@@ -20,14 +22,18 @@ RUN apt-get update && \
2022
libomp-dev \
2123
llvm-3.9 \
2224
make \
23-
mono-devel \
2425
ninja-build \
2526
python3 \
2627
python3-setuptools \
2728
python2.7 \
2829
python-setuptools \
2930
sudo
3031

32+
RUN curl -SL https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb --output packages-microsoft-prod.deb && \
33+
dpkg -i packages-microsoft-prod.deb && \
34+
apt-get update && \
35+
apt-get -y --no-install-recommends install dotnet-sdk-2.1
36+
3137
# Create `user` user for container with password `user`. and give it
3238
# password-less sudo access
3339
RUN useradd -m user && \

contrib/ci/scripts/test_z3_examples_cmake.sh

+7-4
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,14 @@ if [ "X${PYTHON_BINDINGS}" = "X1" ]; then
8888
fi
8989

9090
if [ "X${DOTNET_BINDINGS}" = "X1" ]; then
91-
# Build .NET example
92-
# FIXME: Move compliation step into CMake target
93-
mcs ${Z3_SRC_DIR}/examples/dotnet/Program.cs /target:exe /out:dotnet_test.exe /reference:Microsoft.Z3.dll /r:System.Numerics.dll
9491
# Run .NET example
95-
run_quiet run_non_native_binding mono ./dotnet_test.exe
92+
if [ "X${ASAN_BUILD}" = "X1" ]; then
93+
# The dotnet test get stuck on ASAN
94+
# so don't run it for now.
95+
echo "Skipping .NET example under ASan build"
96+
else
97+
run_quiet run_non_native_binding dotnet ${Z3_BUILD_DIR}/dotnet/netcoreapp2.0/dotnet.dll
98+
fi
9699
fi
97100

98101
if [ "X${JAVA_BINDINGS}" = "X1" ]; then

examples/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,6 @@ endif()
116116
################################################################################
117117
# Build dotnet examples
118118
################################################################################
119-
#if (BUILD_DOTNET_BINDINGS)
120-
# add_subdirectory(dotnet)
121-
#endif()
119+
if (BUILD_DOTNET_BINDINGS)
120+
add_subdirectory(dotnet)
121+
endif()

examples/dotnet/README

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Small example using the .Net bindings.
2-
This example is only built if you have Visual Studio.
32
To build the example execute
43
make examples
54
in the build directory.
65

7-
It will create the executable dotnet_example.exe
6+
It will create a .net core 2.0 app.

src/api/dotnet/CMakeLists.txt

+46-144
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
find_package(DotNetToolchain REQUIRED)
1+
find_package(Dotnet REQUIRED)
22

33
# Configure AssemblyInfo.cs
44
set(VER_MAJOR "${Z3_VERSION_MAJOR}")
55
set(VER_MINOR "${Z3_VERSION_MINOR}")
66
set(VER_BUILD "${Z3_VERSION_PATCH}")
77
set(VER_REVISION "${Z3_VERSION_TWEAK}")
8-
set(Z3_DOTNET_ASSEMBLY_INFO_FILE "${CMAKE_CURRENT_BINARY_DIR}/Properties/AssemblyInfo.cs")
9-
configure_file("Properties/AssemblyInfo.cs.in" "${Z3_DOTNET_ASSEMBLY_INFO_FILE}" @ONLY)
108

119
# Generate Native.cs
1210
set(Z3_DOTNET_NATIVE_FILE "${CMAKE_CURRENT_BINARY_DIR}/Native.cs")
@@ -127,160 +125,64 @@ endforeach()
127125
list(APPEND Z3_DOTNET_ASSEMBLY_SOURCES
128126
"${Z3_DOTNET_CONST_FILE}"
129127
"${Z3_DOTNET_NATIVE_FILE}"
130-
"${Z3_DOTNET_ASSEMBLY_INFO_FILE}"
131128
)
132129

133-
# ``csc.exe`` doesn't like UNIX style paths so convert them
134-
# if necessary first to native paths.
135-
set(Z3_DOTNET_ASSEMBLY_SOURCES_NATIVE_PATH "")
136-
foreach (csfile_path ${Z3_DOTNET_ASSEMBLY_SOURCES})
137-
file(TO_NATIVE_PATH "${csfile_path}" csfile_path_native)
138-
list(APPEND Z3_DOTNET_ASSEMBLY_SOURCES_NATIVE_PATH "${csfile_path_native}")
139-
endforeach()
140130

141-
set(CSC_FLAGS "")
142-
if (DOTNET_TOOLCHAIN_IS_WINDOWS)
143-
# FIXME: Why use these flags?
144-
# Note these flags have been copied from the Python build system.
145-
list(APPEND CSC_FLAGS
146-
"/noconfig"
147-
"/nostdlib+"
148-
"/reference:mscorlib.dll"
149-
)
150-
elseif (DOTNET_TOOLCHAIN_IS_MONO)
151-
# We need to give the assembly a strong name so that it can be installed
152-
# into the GAC.
153-
list(APPEND CSC_FLAGS
154-
"/keyfile:${CMAKE_CURRENT_SOURCE_DIR}/Microsoft.Z3.snk"
155-
)
156-
else()
157-
message(FATAL_ERROR "Unknown .NET toolchain")
158-
endif()
159-
160-
# Common flags
161-
list(APPEND CSC_FLAGS
162-
"/unsafe+"
163-
"/nowarn:1701,1702"
164-
"/errorreport:prompt"
165-
"/warn:4"
166-
"/reference:System.Core.dll"
167-
"/reference:System.dll"
168-
"/reference:System.Numerics.dll"
169-
"/filealign:512" # Why?
170-
"/target:library"
171-
)
131+
# Generate <Compile Include="files.cs" /> items
132+
set(Z3_DOTNET_COMPILE_ITEMS "")
133+
foreach(csfile ${Z3_DOTNET_ASSEMBLY_SOURCES})
134+
set(Z3_DOTNET_COMPILE_ITEMS "${Z3_DOTNET_COMPILE_ITEMS}\n <Compile Include=\"${csfile}\" />")
135+
endforeach()
172136

173-
# Set the build type flags. The build type for the assembly roughly corresponds
174-
# with the native code build type.
175-
list(APPEND CSC_FLAGS
176-
# Debug flags, expands to nothing if we aren't doing a debug build
177-
"$<$<CONFIG:Debug>:/debug+>"
178-
"$<$<CONFIG:Debug>:/debug:full>"
179-
"$<$<CONFIG:Debug>:/optimize->"
180-
# This has to be quoted otherwise the ``;`` is interpreted as a command separator
181-
"$<$<CONFIG:Debug>:\"/define:DEBUG$<SEMICOLON>TRACE\">"
182-
# Release flags, expands to nothing if we are doing a debug build
183-
"$<$<NOT:$<CONFIG:Debug>>:/optimize+>"
184-
)
185137

186-
# Mono's gacutil crashes when trying to install an assembly if we set the
187-
# platform in some cases, so only set it on Windows. This bug has been
188-
# reported at https://bugzilla.xamarin.com/show_bug.cgi?id=39955 . However mono
189-
# ignores the platform of an assembly when running it (
190-
# http://lists.ximian.com/pipermail/mono-devel-list/2015-November/043370.html )
191-
# so this shouldn't matter in practice.
192-
if (DOTNET_TOOLCHAIN_IS_WINDOWS)
193-
# Set platform for assembly
194-
if ("${TARGET_ARCHITECTURE}" STREQUAL "x86_64")
195-
list(APPEND CSC_FLAGS "/platform:x64")
196-
elseif ("${TARGET_ARCHITECTURE}" STREQUAL "i686")
197-
list(APPEND CSC_FLAGS "/platform:x86")
198-
endif()
199-
endif()
138+
# FindDotnet.cmake forwards CMake build type to MSBuild.
139+
# And thus we can put the conditional properties in the project file.
140+
# Note, nuget package file names do not have the ${VER_REV} part.
200141

201-
# FIXME: Ideally we should emit files into a configuration specific directory
202-
# when using multi-configuration generators so that the files generated by each
203-
# configuration don't clobber each other. Unfortunately the ``get_property()``
204-
# command only works correctly for single configuration generators so we can't
205-
# use it. We also can't use ``$<TARGET_FILE_DIR:libz3>`` because the ``OUTPUT``
206-
# argument to ``add_custom_commands()`` won't accept it.
207-
# See http://public.kitware.com/pipermail/cmake/2016-March/063101.html
208-
#
209-
# For now just output file to the root binary directory like the Python build
210-
# system does and emit a warning when appropriate.
211-
if (DEFINED CMAKE_CONFIGURATION_TYPES)
212-
# Multi-configuration build (e.g. Visual Studio and Xcode).
213-
message(WARNING "You are using a multi-configuration generator. The build rules for"
214-
" the \".NET\" bindings currently do not emit files per configuration so previously"
215-
" generated files for other configurations will be overwritten.")
142+
set(Z3_DOTNET_NUPKG_VERSION "${VER_MAJOR}.${VER_MINOR}.${VER_BUILD}")
143+
if("${TARGET_ARCHITECTURE}" STREQUAL "i686")
144+
set(Z3_DOTNET_PLATFORM "x86")
145+
else()
146+
set(Z3_DOTNET_PLATFORM "AnyCPU")
216147
endif()
217148

218-
set(Z3_DOTNET_ASSEMBLY_OUTPUT_DIR "${CMAKE_BINARY_DIR}")
219-
set(Z3_DOTNET_ASSEMBLY_NAME "Microsoft.Z3.dll")
220-
set(Z3_DOTNET_ASSEMBLY_DLL "${Z3_DOTNET_ASSEMBLY_OUTPUT_DIR}/${Z3_DOTNET_ASSEMBLY_NAME}")
221-
# csc.exe doesn't work with UNIX style paths so convert to native path
222-
file(TO_NATIVE_PATH "${Z3_DOTNET_ASSEMBLY_DLL}" Z3_DOTNET_ASSEMBLY_DLL_NATIVE_PATH)
223-
set(Z3_DOTNET_ASSEMBLY_DLL_DOC "${Z3_DOTNET_ASSEMBLY_OUTPUT_DIR}/Microsoft.Z3.xml")
224-
file(TO_NATIVE_PATH "${Z3_DOTNET_ASSEMBLY_DLL_DOC}" Z3_DOTNET_ASSEMBLY_DLL_DOC_NATIVE_PATH)
225-
add_custom_command(OUTPUT "${Z3_DOTNET_ASSEMBLY_DLL}" "${Z3_DOTNET_ASSEMBLY_DLL_DOC}"
226-
COMMAND
227-
"${DOTNET_CSC_EXECUTABLE}"
228-
${CSC_FLAGS}
229-
"/out:${Z3_DOTNET_ASSEMBLY_DLL_NATIVE_PATH}"
230-
"/doc:${Z3_DOTNET_ASSEMBLY_DLL_DOC_NATIVE_PATH}"
231-
${Z3_DOTNET_ASSEMBLY_SOURCES_NATIVE_PATH}
232-
DEPENDS
233-
${Z3_DOTNET_ASSEMBLY_SOURCES}
234-
libz3
235-
WORKING_DIRECTORY "${Z3_DOTNET_ASSEMBLY_OUTPUT_DIR}"
236-
COMMENT "Building \"${Z3_DOTNET_ASSEMBLY_DLL}\""
237-
)
149+
# TODO conditional for signing. we can then enable the ``Release_delaysign`` configuration
150+
151+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Microsoft.Z3.csproj.in ${CMAKE_CURRENT_BINARY_DIR}/build/Microsoft.Z3.csproj)
152+
ADD_DOTNET(${CMAKE_CURRENT_BINARY_DIR}/build/Microsoft.Z3.csproj
153+
VERSION ${Z3_DOTNET_NUPKG_VERSION}
154+
PLATFORM ${Z3_DOTNET_PLATFORM}
155+
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Microsoft.Z3.csproj.in
156+
${CMAKE_CURRENT_SOURCE_DIR}/Microsoft.Z3.props
157+
${CMAKE_CURRENT_SOURCE_DIR}/Microsoft.Z3.targets
158+
${Z3_DOTNET_ASSEMBLY_SOURCES}
159+
PACKAGE Microsoft.Z3
160+
PACK_ARGUMENTS "/p:_DN_CMAKE_CONFIG=$<CONFIG>"
161+
)
162+
add_dependencies(BUILD_Microsoft.Z3 libz3)
238163

239164
# Convenient top-level target
240-
add_custom_target(build_z3_dotnet_bindings
241-
ALL
242-
DEPENDS
243-
"${Z3_DOTNET_ASSEMBLY_DLL}"
244-
)
165+
add_custom_target(build_z3_dotnet_bindings ALL DEPENDS BUILD_Microsoft.Z3)
166+
167+
# Register the local nupkg repo
168+
set(Z3_DOTNET_LOCALREPO_NAME "Microsoft Z3 Local Repository")
169+
DOTNET_REGISTER_LOCAL_REPOSITORY(${Z3_DOTNET_LOCALREPO_NAME} ${CMAKE_BINARY_DIR})
245170

246171
###############################################################################
247-
# Install
172+
# Install: register a local nuget repo and install our package.
173+
# the build step depends on the 'purge' target, making sure that
174+
# a user will always restore the freshly-built package.
248175
###############################################################################
249176
option(INSTALL_DOTNET_BINDINGS "Install .NET bindings when invoking install target" ON)
250-
set(GAC_PKG_NAME "Microsoft.Z3.Sharp")
251-
set(PREFIX "${CMAKE_INSTALL_PREFIX}")
252-
set(VERSION "${Z3_VERSION}")
253-
set(Z3_DOTNET_PKGCONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/Microsoft.Z3.Sharp.pc")
254-
configure_file("Microsoft.Z3.Sharp.pc.in" "${Z3_DOTNET_PKGCONFIG_FILE}" @ONLY)
255-
256-
if (DOTNET_TOOLCHAIN_IS_MONO)
257-
message(STATUS "Emitting install rules for .NET bindings")
258-
# Install pkgconfig file for the assembly. This is needed by Monodevelop
259-
# to find the assembly
260-
install(FILES "${Z3_DOTNET_PKGCONFIG_FILE}" DESTINATION "${CMAKE_INSTALL_PKGCONFIGDIR}")
261177

262-
# Configure the install and uninstall scripts.
263-
# Note: If multi-configuration generator support is ever fixed then these
264-
# scripts will be broken.
265-
configure_file(cmake_install_gac.cmake.in cmake_install_gac.cmake @ONLY)
266-
configure_file(cmake_uninstall_gac.cmake.in cmake_uninstall_gac.cmake @ONLY)
267-
268-
# Tell CMake to Invoke a script to install assembly to the GAC during install
269-
install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/cmake_install_gac.cmake")
270-
271-
# Add custom target to uninstall the assembly from the GAC
272-
add_custom_target(remove_dotnet_dll_from_gac
273-
COMMAND "${CMAKE_COMMAND}" "-P" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall_gac.cmake"
274-
COMMENT "Uninstalling ${Z3_DOTNET_ASSEMBLY_NAME} from the GAC"
275-
${ADD_CUSTOM_COMMAND_USES_TERMINAL_ARG}
276-
)
277-
add_dependencies(uninstall remove_dotnet_dll_from_gac)
278-
279-
elseif(DOTNET_TOOLCHAIN_IS_WINDOWS)
280-
# Don't install Z3_DOTNET_ASSEMBLY_DLL into the gac. Instead just copy into
281-
# installation directory.
282-
install(FILES "${Z3_DOTNET_ASSEMBLY_DLL}" DESTINATION "${CMAKE_INSTALL_LIBDIR}")
283-
install(FILES "${Z3_DOTNET_ASSEMBLY_DLL_DOC}" DESTINATION "${CMAKE_INSTALL_LIBDIR}")
284-
else()
285-
message(FATAL_ERROR "Unknown .NET toolchain")
178+
if(INSTALL_DOTNET_BINDINGS)
179+
install(FILES "${CMAKE_BINARY_DIR}/Microsoft.Z3/Microsoft.Z3.${Z3_DOTNET_NUPKG_VERSION}.nupkg" DESTINATION "${CMAKE_INSTALL_LIBDIR}/z3.nuget")
180+
# move the local repo to the installation directory (cancel the build-time repo)
181+
install(CODE "include(${CMAKE_CURRENT_LIST_DIR}/../../../cmake/modules/FindDotnet.cmake)\n DOTNET_REGISTER_LOCAL_REPOSITORY(\"${Z3_DOTNET_LOCALREPO_NAME}\" ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/z3.nuget)")
182+
install(FILES "${CMAKE_BINARY_DIR}/Microsoft.Z3/Microsoft.Z3.xml" DESTINATION "${CMAKE_INSTALL_LIBDIR}/z3.nuget")
183+
# TODO GAC?
184+
# set(GAC_PKG_NAME "Microsoft.Z3.Sharp")
185+
# set(PREFIX "${CMAKE_INSTALL_PREFIX}")
186+
# set(VERSION "${Z3_VERSION}")
286187
endif()
188+

0 commit comments

Comments
 (0)