mirror of
				https://github.com/Z3Prover/z3
				synced 2025-11-04 05:19:11 +00:00 
			
		
		
		
	Added/improved facilities for strong name signing of the .NET assembly.
This commit is contained in:
		
							parent
							
								
									0d83f99d8d
								
							
						
					
					
						commit
						7fefe40f21
					
				
					 3 changed files with 33 additions and 18 deletions
				
			
		| 
						 | 
					@ -88,7 +88,7 @@ def init_project_def():
 | 
				
			||||||
                              dll_name='libz3',
 | 
					                              dll_name='libz3',
 | 
				
			||||||
                              static=build_static_lib(),
 | 
					                              static=build_static_lib(),
 | 
				
			||||||
                              export_files=API_files)
 | 
					                              export_files=API_files)
 | 
				
			||||||
    add_dot_net_dll('dotnet', ['api_dll'], 'api/dotnet', dll_name='Microsoft.Z3', assembly_info_dir='Properties')
 | 
					    add_dot_net_dll('dotnet', ['api_dll'], 'api/dotnet', dll_name='Microsoft.Z3', assembly_info_dir='Properties', default_key_file='src/api/dotnet/Microsoft.Z3.snk')
 | 
				
			||||||
    add_java_dll('java', ['api_dll'], 'api/java', dll_name='libz3java', package_name="com.microsoft.z3", manifest_file='manifest')
 | 
					    add_java_dll('java', ['api_dll'], 'api/java', dll_name='libz3java', package_name="com.microsoft.z3", manifest_file='manifest')
 | 
				
			||||||
    add_ml_lib('ml', ['api_dll'], 'api/ml', lib_name='libz3ml')
 | 
					    add_ml_lib('ml', ['api_dll'], 'api/ml', lib_name='libz3ml')
 | 
				
			||||||
    add_hlib('cpp', 'api/c++', includes2install=['z3++.h'])
 | 
					    add_hlib('cpp', 'api/c++', includes2install=['z3++.h'])
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -82,6 +82,7 @@ Z3PY_SRC_DIR=None
 | 
				
			||||||
VS_PROJ = False
 | 
					VS_PROJ = False
 | 
				
			||||||
TRACE = False
 | 
					TRACE = False
 | 
				
			||||||
DOTNET_ENABLED=False
 | 
					DOTNET_ENABLED=False
 | 
				
			||||||
 | 
					DOTNET_KEY_FILE=None
 | 
				
			||||||
JAVA_ENABLED=False
 | 
					JAVA_ENABLED=False
 | 
				
			||||||
ML_ENABLED=False
 | 
					ML_ENABLED=False
 | 
				
			||||||
PYTHON_INSTALL_ENABLED=False
 | 
					PYTHON_INSTALL_ENABLED=False
 | 
				
			||||||
| 
						 | 
					@ -638,6 +639,7 @@ def display_help(exit_code):
 | 
				
			||||||
    if IS_WINDOWS:
 | 
					    if IS_WINDOWS:
 | 
				
			||||||
        print("  --optimize                    generate optimized code during linking.")
 | 
					        print("  --optimize                    generate optimized code during linking.")
 | 
				
			||||||
    print("  --dotnet                      generate .NET bindings.")
 | 
					    print("  --dotnet                      generate .NET bindings.")
 | 
				
			||||||
 | 
					    print("  --dotnet-key=<file>           sign the .NET assembly using the private key in <file>.")
 | 
				
			||||||
    print("  --java                        generate Java bindings.")
 | 
					    print("  --java                        generate Java bindings.")
 | 
				
			||||||
    print("  --ml                          generate OCaml bindings.")
 | 
					    print("  --ml                          generate OCaml bindings.")
 | 
				
			||||||
    print("  --python                      generate Python bindings.")
 | 
					    print("  --python                      generate Python bindings.")
 | 
				
			||||||
| 
						 | 
					@ -673,14 +675,14 @@ def display_help(exit_code):
 | 
				
			||||||
# Parse configuration option for mk_make script
 | 
					# Parse configuration option for mk_make script
 | 
				
			||||||
def parse_options():
 | 
					def parse_options():
 | 
				
			||||||
    global VERBOSE, DEBUG_MODE, IS_WINDOWS, VS_X64, ONLY_MAKEFILES, SHOW_CPPS, VS_PROJ, TRACE, VS_PAR, VS_PAR_NUM
 | 
					    global VERBOSE, DEBUG_MODE, IS_WINDOWS, VS_X64, ONLY_MAKEFILES, SHOW_CPPS, VS_PROJ, TRACE, VS_PAR, VS_PAR_NUM
 | 
				
			||||||
    global DOTNET_ENABLED, JAVA_ENABLED, ML_ENABLED, STATIC_LIB, STATIC_BIN, PREFIX, GMP, FOCI2, FOCI2LIB, PYTHON_PACKAGE_DIR, GPROF, GIT_HASH, PYTHON_INSTALL_ENABLED
 | 
					    global DOTNET_ENABLED, DOTNET_KEY_FILE, JAVA_ENABLED, ML_ENABLED, STATIC_LIB, STATIC_BIN, PREFIX, GMP, FOCI2, FOCI2LIB, PYTHON_PACKAGE_DIR, GPROF, GIT_HASH, GIT_DESCRIBE, PYTHON_INSTALL_ENABLED
 | 
				
			||||||
    global LINUX_X64, SLOW_OPTIMIZE, USE_OMP
 | 
					    global LINUX_X64, SLOW_OPTIMIZE, USE_OMP
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        options, remainder = getopt.gnu_getopt(sys.argv[1:],
 | 
					        options, remainder = getopt.gnu_getopt(sys.argv[1:],
 | 
				
			||||||
                                               'b:df:sxhmcvtnp:gj',
 | 
					                                               'b:df:sxhmcvtnp:gj',
 | 
				
			||||||
                                               ['build=', 'debug', 'silent', 'x64', 'help', 'makefiles', 'showcpp', 'vsproj',
 | 
					                                               ['build=', 'debug', 'silent', 'x64', 'help', 'makefiles', 'showcpp', 'vsproj',
 | 
				
			||||||
                                                'trace', 'dotnet', 'staticlib', 'prefix=', 'gmp', 'foci2=', 'java', 'parallel=', 'gprof',
 | 
					                                                'trace', 'dotnet', 'dotnet-key=', 'staticlib', 'prefix=', 'gmp', 'foci2=', 'java', 'parallel=', 'gprof',
 | 
				
			||||||
                                                'githash=', 'x86', 'ml', 'optimize', 'noomp', 'pypkgdir=', 'python', 'staticbin'])
 | 
					                                                'githash=', 'git-describe', 'x86', 'ml', 'optimize', 'noomp', 'pypkgdir=', 'python', 'staticbin'])
 | 
				
			||||||
    except:
 | 
					    except:
 | 
				
			||||||
        print("ERROR: Invalid command line option")
 | 
					        print("ERROR: Invalid command line option")
 | 
				
			||||||
        display_help(1)
 | 
					        display_help(1)
 | 
				
			||||||
| 
						 | 
					@ -713,6 +715,8 @@ def parse_options():
 | 
				
			||||||
            TRACE = True
 | 
					            TRACE = True
 | 
				
			||||||
        elif opt in ('-.net', '--dotnet'):
 | 
					        elif opt in ('-.net', '--dotnet'):
 | 
				
			||||||
            DOTNET_ENABLED = True
 | 
					            DOTNET_ENABLED = True
 | 
				
			||||||
 | 
					        elif opt in ('--dotnet-key'):
 | 
				
			||||||
 | 
					            DOTNET_KEY_FILE = arg
 | 
				
			||||||
        elif opt in ('--staticlib'):
 | 
					        elif opt in ('--staticlib'):
 | 
				
			||||||
            STATIC_LIB = True
 | 
					            STATIC_LIB = True
 | 
				
			||||||
        elif opt in ('--staticbin'):
 | 
					        elif opt in ('--staticbin'):
 | 
				
			||||||
| 
						 | 
					@ -1498,7 +1502,7 @@ class PythonInstallComponent(Component):
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class DotNetDLLComponent(Component):
 | 
					class DotNetDLLComponent(Component):
 | 
				
			||||||
    def __init__(self, name, dll_name, path, deps, assembly_info_dir):
 | 
					    def __init__(self, name, dll_name, path, deps, assembly_info_dir, default_key_file):
 | 
				
			||||||
        Component.__init__(self, name, path, deps)
 | 
					        Component.__init__(self, name, path, deps)
 | 
				
			||||||
        if dll_name is None:
 | 
					        if dll_name is None:
 | 
				
			||||||
            dll_name = name
 | 
					            dll_name = name
 | 
				
			||||||
| 
						 | 
					@ -1506,6 +1510,7 @@ class DotNetDLLComponent(Component):
 | 
				
			||||||
            assembly_info_dir = "."
 | 
					            assembly_info_dir = "."
 | 
				
			||||||
        self.dll_name          = dll_name
 | 
					        self.dll_name          = dll_name
 | 
				
			||||||
        self.assembly_info_dir = assembly_info_dir
 | 
					        self.assembly_info_dir = assembly_info_dir
 | 
				
			||||||
 | 
					        self.key_file = default_key_file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def mk_pkg_config_file(self):
 | 
					    def mk_pkg_config_file(self):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
| 
						 | 
					@ -1531,6 +1536,8 @@ class DotNetDLLComponent(Component):
 | 
				
			||||||
        configure_file(pkg_config_template, pkg_config_output, substitutions)
 | 
					        configure_file(pkg_config_template, pkg_config_output, substitutions)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def mk_makefile(self, out):
 | 
					    def mk_makefile(self, out):
 | 
				
			||||||
 | 
					        global DOTNET_KEY_FILE
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        if not is_dotnet_enabled():
 | 
					        if not is_dotnet_enabled():
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
        cs_fp_files = []
 | 
					        cs_fp_files = []
 | 
				
			||||||
| 
						 | 
					@ -1561,17 +1568,24 @@ class DotNetDLLComponent(Component):
 | 
				
			||||||
                                '/linkresource:{}.dll'.format(get_component(Z3_DLL_COMPONENT).dll_name),
 | 
					                                '/linkresource:{}.dll'.format(get_component(Z3_DLL_COMPONENT).dll_name),
 | 
				
			||||||
                               ]
 | 
					                               ]
 | 
				
			||||||
                             )
 | 
					                             )
 | 
				
			||||||
            pathToSnk = os.path.join(self.to_src_dir, 'z3.snk')
 | 
					
 | 
				
			||||||
            snkFile   = os.path.join(self.src_dir, 'z3.snk')
 | 
					        # We need to give the assembly a strong name so that it
 | 
				
			||||||
        else:
 | 
					        # can be installed into the GAC with ``make install``
 | 
				
			||||||
            # We need to give the assembly a strong name so that it
 | 
					        if not DOTNET_KEY_FILE is None:
 | 
				
			||||||
            # can be installed into the GAC with ``make install``
 | 
					            self.key_file = DOTNET_KEY_FILE
 | 
				
			||||||
            pathToSnk = os.path.join(self.to_src_dir, 'Microsoft.Z3.mono.snk')
 | 
					
 | 
				
			||||||
            snkFile  = os.path.join(self.src_dir, 'Microsoft.Z3.mono.snk')
 | 
					        if not self.key_file is None:
 | 
				
			||||||
        if os.path.isfile(snkFile):
 | 
					            if os.path.isfile(self.key_file):
 | 
				
			||||||
            cscCmdLine.append('/keyfile:{}'.format(pathToSnk))
 | 
					                self.key_file = os.path.abspath(self.key_file)
 | 
				
			||||||
        else:
 | 
					            elif os.path.isfile(os.path.join(self.src_dir, self.key_file)):
 | 
				
			||||||
            print("Keyfile is not configured: %s" % snkFile)
 | 
					                self.key_file = os.path.abspath(os.path.join(self.src_dir, self.key_file))
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                print("Keyfile '%s' could not be found; %s.dll will be unsigned." % (self.dll_name, self.key_file))
 | 
				
			||||||
 | 
					                self.key_file = None
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					        if not self.key_file is None:
 | 
				
			||||||
 | 
					            print("%s.dll will be signed using key '%s'." % (self.dll_name, self.key_file))
 | 
				
			||||||
 | 
					            cscCmdLine.append('/keyfile:{}'.format(self.key_file))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        cscCmdLine.extend( ['/unsafe+',
 | 
					        cscCmdLine.extend( ['/unsafe+',
 | 
				
			||||||
                            '/nowarn:1701,1702',
 | 
					                            '/nowarn:1701,1702',
 | 
				
			||||||
| 
						 | 
					@ -1595,6 +1609,7 @@ class DotNetDLLComponent(Component):
 | 
				
			||||||
                             )
 | 
					                             )
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            cscCmdLine.extend(['/optimize+'])
 | 
					            cscCmdLine.extend(['/optimize+'])
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
        if IS_WINDOWS:
 | 
					        if IS_WINDOWS:
 | 
				
			||||||
            if VS_X64:
 | 
					            if VS_X64:
 | 
				
			||||||
                cscCmdLine.extend(['/platform:x64'])
 | 
					                cscCmdLine.extend(['/platform:x64'])
 | 
				
			||||||
| 
						 | 
					@ -2179,8 +2194,8 @@ def add_dll(name, deps=[], path=None, dll_name=None, export_files=[], reexports=
 | 
				
			||||||
    reg_component(name, c)
 | 
					    reg_component(name, c)
 | 
				
			||||||
    return c
 | 
					    return c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def add_dot_net_dll(name, deps=[], path=None, dll_name=None, assembly_info_dir=None):
 | 
					def add_dot_net_dll(name, deps=[], path=None, dll_name=None, assembly_info_dir=None, default_key_file=None):
 | 
				
			||||||
    c = DotNetDLLComponent(name, dll_name, path, deps, assembly_info_dir)
 | 
					    c = DotNetDLLComponent(name, dll_name, path, deps, assembly_info_dir, default_key_file)
 | 
				
			||||||
    reg_component(name, c)
 | 
					    reg_component(name, c)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def add_java_dll(name, deps=[], path=None, dll_name=None, package_name=None, manifest_file=None):
 | 
					def add_java_dll(name, deps=[], path=None, dll_name=None, package_name=None, manifest_file=None):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue