Skip to content

Commit

Permalink
[Z3]: allow to specify Z3 library via Z3_LIBRARY_PATH environment
Browse files Browse the repository at this point in the history
  • Loading branch information
janvrany authored and shingarov committed Oct 28, 2024
1 parent f8e329b commit 862751f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
34 changes: 31 additions & 3 deletions src/Z3-FFI-Pharo/LibZ3.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
]
23 changes: 21 additions & 2 deletions src/Z3-FFI-SmalltalkX/LibZ3.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 862751f

Please sign in to comment.