-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
152 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Amplitude Analytics | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
plugins { | ||
id("dev.petuska.npm.publish") version Versions.npmPublishPlugin | ||
kotlin("multiplatform") | ||
kotlin("native.cocoapods") version Versions.cocoapodsPlugin | ||
kotlin("native.cocoapods") | ||
id("org.jetbrains.kotlin.plugin.serialization") version Versions.serializationPlugin | ||
`maven-publish` | ||
} | ||
|
@@ -15,41 +15,21 @@ kotlin { | |
} | ||
|
||
cocoapods { | ||
// Configure fields required by CocoaPods. | ||
frameworkName = "EvaluationInterop" | ||
summary = "Native evaluation interoperability library for Amplitude Experiment" | ||
homepage = "https://github.com/amplitude/experiment-evaluation" | ||
|
||
// You can change the name of the produced framework. | ||
// By default, it is the name of the Gradle project. | ||
frameworkName = "EvaluationInterop" | ||
ios.deploymentTarget = "10.0" | ||
osx.deploymentTarget = "10.10" | ||
tvos.deploymentTarget = "9.0" | ||
watchos.deploymentTarget = "3.0" | ||
} | ||
|
||
val hostOs = getHostOs() | ||
if (hostOs == HostOs.MAC) { | ||
macosX64 { | ||
binaries.sharedLib() | ||
binaries.framework { | ||
baseName = "EvaluationInterop" | ||
} | ||
} | ||
iosArm32 { | ||
binaries.sharedLib() | ||
binaries.framework { | ||
baseName = "EvaluationInterop" | ||
} | ||
} | ||
iosArm64 { | ||
binaries.sharedLib() | ||
binaries.framework { | ||
baseName = "EvaluationInterop" | ||
} | ||
} | ||
iosX64 { | ||
binaries.sharedLib() | ||
binaries.framework { | ||
baseName = "EvaluationInterop" | ||
} | ||
} | ||
macosX64().binaries.sharedLib() | ||
ios() | ||
tvos() | ||
watchos() | ||
} | ||
linuxArm64().binaries.sharedLib() | ||
linuxX64().binaries.sharedLib() | ||
|
@@ -98,4 +78,31 @@ npmPublishing { | |
authToken = properties["NPM_TOKEN"] as? String | ||
} | ||
} | ||
} | ||
} | ||
|
||
tasks["podspec"].doLast { | ||
val podspec = file("${project.name.replace("-", "_")}.podspec") | ||
val newPodspecContent = podspec.readLines().map { | ||
when { | ||
// Needed to publish the pod | ||
it.contains(" spec.source") -> { | ||
" spec.source = { :git => \"https://github.com/amplitude/experiment-evaluation.git\", :tag => \"v#{spec.version}\" }" | ||
} | ||
// Silence warnings for license | ||
it.contains(" spec.license") -> { | ||
" spec.license = { :type => \"MIT\" }" | ||
} | ||
it.contains(" spec.author") -> { | ||
" spec.author = { \"Amplitude\" => \"[email protected]\" }" | ||
} | ||
// NOTE: This is required because for some reason the PODS_TARGET_SRCROOT is misconfigured | ||
// to point to the OS root directory (i.e. /). Manually set the repo root to point to the | ||
// project directory. | ||
it.contains("REPO_ROOT=\"\$PODS_TARGET_SRCROOT\"") -> { | ||
" REPO_ROOT=$projectDir" | ||
} | ||
else -> it | ||
} | ||
} | ||
podspec.writeText(newPodspecContent.joinToString(separator = "\n")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Pod::Spec.new do |spec| | ||
spec.name = 'evaluation_interop' | ||
spec.version = '0.0.1' | ||
spec.homepage = 'https://github.com/amplitude/experiment-evaluation' | ||
spec.source = { :git => "https://github.com/amplitude/experiment-evaluation.git", :tag => "v#{spec.version}" } | ||
spec.author = { "Amplitude" => "[email protected]" } | ||
spec.license = { :type => "MIT" } | ||
spec.summary = 'Native evaluation interoperability library for Amplitude Experiment' | ||
|
||
spec.static_framework = true | ||
spec.vendored_frameworks = "build/cocoapods/framework/EvaluationInterop.framework" | ||
spec.libraries = "c++" | ||
spec.module_name = "#{spec.name}_umbrella" | ||
|
||
spec.ios.deployment_target = '10.0' | ||
spec.osx.deployment_target = '10.10' | ||
spec.tvos.deployment_target = '9.0' | ||
spec.watchos.deployment_target = '3.0' | ||
|
||
|
||
|
||
spec.pod_target_xcconfig = { | ||
'KOTLIN_TARGET[sdk=iphonesimulator*]' => 'ios_x64', | ||
'KOTLIN_TARGET[sdk=iphoneos*]' => 'ios_arm', | ||
'KOTLIN_TARGET[sdk=watchsimulator*]' => 'watchos_x64', | ||
'KOTLIN_TARGET[sdk=watchos*]' => 'watchos_arm', | ||
'KOTLIN_TARGET[sdk=appletvsimulator*]' => 'tvos_x64', | ||
'KOTLIN_TARGET[sdk=appletvos*]' => 'tvos_arm64', | ||
'KOTLIN_TARGET[sdk=macosx*]' => 'macos_x64' | ||
} | ||
|
||
spec.script_phases = [ | ||
{ | ||
:name => 'Build evaluation_interop', | ||
:execution_position => :before_compile, | ||
:shell_path => '/bin/sh', | ||
:script => <<-SCRIPT | ||
set -ev | ||
REPO_ROOT=/Users/brian.giori/dev/experiment-evaluation/evaluation-interop | ||
"$REPO_ROOT/../gradlew" -p "$REPO_ROOT" :evaluation-interop:syncFramework \ | ||
-Pkotlin.native.cocoapods.target=$KOTLIN_TARGET \ | ||
-Pkotlin.native.cocoapods.configuration=$CONFIGURATION \ | ||
-Pkotlin.native.cocoapods.cflags="$OTHER_CFLAGS" \ | ||
-Pkotlin.native.cocoapods.paths.headers="$HEADER_SEARCH_PATHS" \ | ||
-Pkotlin.native.cocoapods.paths.frameworks="$FRAMEWORK_SEARCH_PATHS" | ||
SCRIPT | ||
} | ||
] | ||
end |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,7 @@ case "`uname`" in | |
Darwin* ) | ||
darwin=true | ||
;; | ||
MINGW* ) | ||
MSYS* | MINGW* ) | ||
msys=true | ||
;; | ||
NONSTOP* ) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Python Evaluation Interop | ||
|
||
This package is currently a proof-of-concept for running the | ||
evaluation-interop module as a shared library in python utilizing the CFFI package. | ||
|
||
## Install dependencies | ||
|
||
(Assuming python 3.9 installed) | ||
|
||
1. Install CFFI via pip | ||
``` | ||
pip install cffi | ||
``` | ||
|
||
## Setup & Run Proof-of-concept | ||
|
||
(Assuming macosX64) | ||
|
||
1. Build the `evaluation-interop` shared library. From the root `experimentation-evaluation` directory: | ||
``` | ||
./gradlew evaluation-interop:build | ||
``` | ||
2. Copy the shared library into `/usr/local/lib`: | ||
``` | ||
sudo cp evaluation-interop/build/bin/macosX64/debugShared/libevaluation_interop.dylib /usr/local/lib | ||
``` | ||
3. Copy the header file to the `python` directory: | ||
``` | ||
cp evaluation-interop/build/bin/macosX64/debugShared/libevaluation_interop_api.h python | ||
``` | ||
4. Change to `python` directory and run `setup.py`: | ||
``` | ||
cd python | ||
python setup.py | ||
``` | ||
5. Run the proof-of-concept python file to run an evaluation: | ||
``` | ||
python main.py | ||
``` |
Binary file not shown.