From 862751f9d1d82fdb4dcd2cdf3b063ff06fb0911f Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Mon, 21 Oct 2024 12:37:56 +0100 Subject: [PATCH] [Z3]: allow to specify Z3 library via `Z3_LIBRARY_PATH` environment --- src/Z3-FFI-Pharo/LibZ3.class.st | 34 +++++++++++++++++++++++++--- src/Z3-FFI-SmalltalkX/LibZ3.class.st | 23 +++++++++++++++++-- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/Z3-FFI-Pharo/LibZ3.class.st b/src/Z3-FFI-Pharo/LibZ3.class.st index b97dec938..03132f2b8 100644 --- a/src/Z3-FFI-Pharo/LibZ3.class.st +++ b/src/Z3-FFI-Pharo/LibZ3.class.st @@ -10138,17 +10138,45 @@ LibZ3 >> _update_term: c _: a _: num_args _: args [ ] +{ #category : #'accessing platform-private' } +LibZ3 >> getLibraryName: default [ + "Return path to Z3 shared library / DLL to use (as string). + If relative, the library is looked up according to OS conventions. + + By default, passed `default` is used. + + It is possible to use specific library by either setting + Z3_LIBRARY_PATH environment variable or - alternatively - + by using `LibZ3 class >> libraryName:`. + " + LibraryName isNil ifTrue:[ + | libraryNameFromEnv | + + libraryNameFromEnv := Smalltalk os environment at: 'Z3_LIBRARY_PATH' ifAbsent:[nil]. + libraryNameFromEnv notNil ifTrue:[ + libraryNameFromEnv asFileReference exists ifFalse:[ + self error:'Z3 shared library set in Z3_LIBRARY_PATH environment var does not exits: ', libraryNameFromEnv. + ^ nil. + ]. + ^ libraryNameFromEnv + ]. + + ^default + ]. + ^ LibraryName +] + { #category : #'accessing platform' } LibZ3 >> macLibraryName [ - LibraryName ifNil: [^'libz3.dylib'] ifNotNil: [^LibraryName] + ^self getLibraryName: 'libz3.dylib'. ] { #category : #'accessing platform' } LibZ3 >> unixLibraryName [ - LibraryName ifNil: [^'libz3.so'] ifNotNil: [^LibraryName] + ^self getLibraryName: 'libz3.so'. ] { #category : #'accessing platform' } LibZ3 >> win32ModuleName [ - LibraryName ifNil: [^'libz3.dll'] ifNotNil: [^LibraryName] + ^self getLibraryName: 'libz3.dll'. ] diff --git a/src/Z3-FFI-SmalltalkX/LibZ3.class.st b/src/Z3-FFI-SmalltalkX/LibZ3.class.st index ec4c06dc5..d35753fa5 100644 --- a/src/Z3-FFI-SmalltalkX/LibZ3.class.st +++ b/src/Z3-FFI-SmalltalkX/LibZ3.class.st @@ -14,12 +14,31 @@ Class { { #category : #accessing } LibZ3 class >> libraryName [ + "Return path to Z3 shared library / DLL to use (as string). + If relative, the library is looked up according to OS conventions. + By default, the OS-shipped version is used. + + It is possible to use specific library by either setting + Z3_LIBRARY_PATH environment variable or - alternatively - + by using `LibZ3 class >> libraryName:`. + " LibraryName isNil ifTrue:[ + | libraryNameFromEnv | + + libraryNameFromEnv := OperatingSystem getEnvironment: 'Z3_LIBRARY_PATH'. + libraryNameFromEnv notNil ifTrue:[ + libraryNameFromEnv asFilename exists ifFalse:[ + self error:'Z3 shared library set in Z3_LIBRARY_PATH environment var does not exits: ', libraryNameFromEnv. + ^ nil. + ]. + ^ libraryNameFromEnv + ]. + OperatingSystem isMSWINDOWSlike ifTrue: [ - LibraryName := 'libz3.dll'. + ^ 'libz3.dll'. ] ifFalse: [ - LibraryName := 'libz3.so'. + ^ 'libz3.so'. ]. ]. ^ LibraryName