9 changed files with 1422 additions and 1918 deletions
@ -1,127 +0,0 @@
|
||||
DIST_BUILD_SCRIPT := ./dist.sh
|
||||
|
||||
#EXECUTABLES = cmake
|
||||
#build_reqs := $(foreach exec,$(EXECUTABLES),\
|
||||
# $(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH")))
|
||||
|
||||
.PHONY: list |
||||
list: |
||||
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= \
|
||||
-F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") \
|
||||
{print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs
|
||||
|
||||
# Pull all submodules
|
||||
update: |
||||
@git submodule update --init
|
||||
@git submodule status
|
||||
|
||||
# Patch submodules (issue update first)
|
||||
patch: |
||||
#-cd ext/lwip; git apply ../lwip.patch;
|
||||
#-cd ext/lwip-contrib; git apply ../lwip-contrib.patch;
|
||||
#-cd ext/ZeroTierOne; git apply ../ZeroTierOne.patch;
|
||||
|
||||
# Target-specific clean
|
||||
clean_ios: |
||||
-rm -rf ports/xcode_ios
|
||||
-rm -rf ports/xcode_ios_simulator
|
||||
clean_macos: |
||||
-rm -rf ports/xcode_macos
|
||||
clean_android: |
||||
-rm -rf pkg/android/app/build
|
||||
-find pkg -name ".externalNativeBuild" -exec rm -r "{}" \;
|
||||
$(DIST_BUILD_SCRIPT) android "clean"
|
||||
clean_products: |
||||
-rm -rf products
|
||||
.PHONY: clean |
||||
clean: clean_ios clean_macos clean_android |
||||
$(DIST_BUILD_SCRIPT) clean
|
||||
|
||||
# Use CMake generators to build projects from CMakeLists.txt
|
||||
projects: |
||||
$(DIST_BUILD_SCRIPT) generate_projects
|
||||
|
||||
# Android
|
||||
android_debug: |
||||
$(DIST_BUILD_SCRIPT) android "debug"
|
||||
$(DIST_BUILD_SCRIPT) clean_android_project
|
||||
$(DIST_BUILD_SCRIPT) prep_android_example "debug"
|
||||
android_release: |
||||
$(DIST_BUILD_SCRIPT) android "release"
|
||||
$(DIST_BUILD_SCRIPT) clean_android_project
|
||||
$(DIST_BUILD_SCRIPT) prep_android_example "release"
|
||||
android: android_debug android_release |
||||
prep_android_debug_example: |
||||
$(DIST_BUILD_SCRIPT) prep_android_example "debug"
|
||||
prep_android_release_example: |
||||
$(DIST_BUILD_SCRIPT) prep_android_example "release"
|
||||
|
||||
# macOS
|
||||
macos_debug: |
||||
$(DIST_BUILD_SCRIPT) macos "debug"
|
||||
macos_release: |
||||
$(DIST_BUILD_SCRIPT) macos "release"
|
||||
macos: macos_debug macos_release |
||||
|
||||
# xcframework
|
||||
xcframework: |
||||
xcodebuild -project ports/apple/zt.xcodeproj archive -scheme zt -sdk macosx -archivePath build/macosx
|
||||
xcodebuild -project ports/apple/zt.xcodeproj archive -scheme zt -sdk iphoneos -archivePath build/iphoneos
|
||||
xcodebuild -project ports/apple/zt.xcodeproj archive -scheme zt -sdk iphonesimulator -archivePath build/iphonesimulator
|
||||
|
||||
xcodebuild -create-xcframework \
|
||||
-framework build/macosx.xcarchive/Products/Library/Frameworks/zt.framework \
|
||||
-framework build/iphoneos.xcarchive/Products/Library/Frameworks/zt.framework \
|
||||
-framework build/iphonesimulator.xcarchive/Products/Library/Frameworks/zt.framework \
|
||||
-output lib/zt.xcframework
|
||||
|
||||
rm -rf build/macosx.xcarchive
|
||||
rm -rf build/iphoneos.xcarchive
|
||||
rm -rf build/iphonesimulator.xcarchive
|
||||
|
||||
# iOS
|
||||
ios_debug: |
||||
$(DIST_BUILD_SCRIPT) ios "debug"
|
||||
ios_release: |
||||
$(DIST_BUILD_SCRIPT) ios "release"
|
||||
ios: ios_debug ios_release |
||||
|
||||
# Host
|
||||
host_release: |
||||
$(DIST_BUILD_SCRIPT) host "release"
|
||||
host_debug: |
||||
$(DIST_BUILD_SCRIPT) host "debug"
|
||||
host_clean: |
||||
$(DIST_BUILD_SCRIPT) host "clean"
|
||||
host_jar_debug: |
||||
$(DIST_BUILD_SCRIPT) host_jar "debug"
|
||||
host_jar_release: |
||||
$(DIST_BUILD_SCRIPT) host_jar "release"
|
||||
host_jar: host_jar_debug host_jar_release |
||||
|
||||
host_pinvoke_release: |
||||
$(DIST_BUILD_SCRIPT) host_pinvoke "release"
|
||||
host_pinvoke_debug: |
||||
$(DIST_BUILD_SCRIPT) host_pinvoke "debug"
|
||||
host_pinvoke: host_pinvoke_release host_pinvoke_debug |
||||
|
||||
host: host_debug host_release |
||||
|
||||
# Build every target available on this host
|
||||
all: host host_pinvoke host_jar macos ios android |
||||
$(DIST_BUILD_SCRIPT) display
|
||||
|
||||
# [For distribution process only] Prepare remote builds
|
||||
wrap: |
||||
$(DIST_BUILD_SCRIPT) wrap
|
||||
|
||||
# Binary distribution
|
||||
bdist: |
||||
$(DIST_BUILD_SCRIPT) merge
|
||||
$(DIST_BUILD_SCRIPT) bdist
|
||||
|
||||
# Source distribution
|
||||
sdist: update patch |
||||
$(DIST_BUILD_SCRIPT) sdist
|
||||
|
||||
dist: bdist sdist |
||||
@ -0,0 +1,23 @@
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------- |
||||
libzt --- Encrypted P2P SD-WAN library by ZeroTier |
||||
-------------------------------------------------------------------------------- |
||||
|
||||
This project uses cmake as a build system generator. The scripts build.sh and |
||||
build.ps1 are used to simplify building and packaging for various targets. |
||||
|
||||
dist/ : Finished targets: libraries, binaries, packages, etc. |
||||
cache/ : Build system caches that can safely be deleted after build. |
||||
pkg/ : Project, script and spec files to generate packages. |
||||
|
||||
1. git submodule update --init |
||||
2. (*)nix : ./build.sh host "release" |
||||
2. Windows : . .\build.ps1; Build-Host -BuildType "Release" |
||||
|
||||
To see additional build targets: |
||||
|
||||
./build.sh list |
||||
|
||||
Help, bugs, and feature requests: https://github.com/zerotier/libzt/issues |
||||
|
||||
@ -0,0 +1,206 @@
|
||||
function Build-Host |
||||
{ |
||||
$Arch="x64" |
||||
$Artifact="host" |
||||
$BuildType="Debug" |
||||
$Variant="-DBUILD_HOST=1" |
||||
|
||||
# Directory for CMake to build and store intermediate files |
||||
$env:BuildDir="cache\win-$Arch-$Artifact-"+$BuildType.ToLower() |
||||
md $env:BuildDir -ErrorAction:'silentlycontinue' |
||||
# Directory where we plan to store the resultant libraries |
||||
$env:OutputDir="dist\win-$Arch-$Artifact-"+$BuildType.ToLower() |
||||
md $env:OutputDir -ErrorAction:'silentlycontinue' |
||||
pushd -Path $env:BuildDir |
||||
cmake $Variant -G "Visual Studio 16 2019" -A $Arch ../../ |
||||
cmake --build . --config $BuildType |
||||
ctest -C debug |
||||
popd |
||||
# |
||||
md $env:OutputDir\lib\ -ErrorAction:'silentlycontinue' |
||||
md $env:OutputDir\bin\ -ErrorAction:'silentlycontinue' |
||||
cp $env:BuildDir\lib\$BuildType\zt.lib $env:OutputDir\lib\libzt.lib |
||||
cp $env:BuildDir\bin\$BuildType\*.exe $env:OutputDir\bin |
||||
cp $env:BuildDir\lib\$BuildType\zt-shared.dll $env:OutputDir\lib\libzt.dll |
||||
cp $env:BuildDir\lib\$BuildType\zt-shared.pdb $env:OutputDir\lib\libzt.pdb -ErrorAction:'silentlycontinue' |
||||
tree /F $env:OutputDir |
||||
} |
||||
|
||||
function Build-Library([string]$BuildType, [string]$Arch, [string]$LangBinding) |
||||
{ |
||||
$OptLangBinding="" |
||||
|
||||
if ($LangBinding -eq "csharp") { |
||||
$OptLangBinding="-DZTS_ENABLE_PINVOKE=1" |
||||
$LangBindingPostfix="pinvoke" |
||||
} |
||||
if ($LangBinding -eq "java") { |
||||
$OptLangBinding="-DZTS_ENABLE_JAVA=1" |
||||
$LangBindingPostfix="jni" |
||||
} |
||||
|
||||
$archAlias = "" |
||||
$bitCount = "" |
||||
|
||||
if ($Arch -eq "Win32") { |
||||
$bitCount="32" |
||||
$archAlias="win-x86" |
||||
} |
||||
if ($Arch -eq "x64") { |
||||
$bitCount="64" |
||||
$archAlias="win-x64" |
||||
} |
||||
#if ($Arch -eq "ARM32") { |
||||
# $bitCount="32" |
||||
# $archAlias="win-arm" |
||||
#} |
||||
if ($Arch -eq "ARM") { |
||||
$bitCount="64" |
||||
$archAlias="win-arm64" |
||||
} |
||||
|
||||
if ($archAlias -eq "" -or $bitCount -eq "") { |
||||
echo "No valid architecture specified. Breaking." |
||||
break |
||||
} |
||||
|
||||
# Directory for CMake to build and store intermediate files |
||||
$env:BuildDir="cache\win-$Arch-$LangBindingPostfix-"+$BuildType.ToLower() |
||||
md $env:BuildDir -ErrorAction:'silentlycontinue' |
||||
# Directory where we plan to store the resultant libraries |
||||
$env:OutputDir="dist\win-$Arch-$LangBindingPostfix-"+$BuildType.ToLower() |
||||
md $env:OutputDir -ErrorAction:'silentlycontinue' |
||||
pushd -Path $env:BuildDir |
||||
cmake ${OptLangBinding} -G "Visual Studio 16 2019" -A $Arch ../../ |
||||
cmake --build . --config $BuildType |
||||
popd |
||||
md $env:OutputDir\lib\ -ErrorAction:'silentlycontinue' |
||||
#cp $env:BuildDir\$BuildType\zt.lib $env:OutputDir\lib\libzt.lib |
||||
cp $env:BuildDir\$BuildType\zt-shared.dll $env:OutputDir\lib\libzt.dll |
||||
cp $env:BuildDir\$BuildType\zt-shared.pdb $env:OutputDir\lib\libzt.pdb -ErrorAction:'silentlycontinue' |
||||
} |
||||
|
||||
function Build-All |
||||
{ |
||||
# Win32 |
||||
Build-Library -BuildType "Release" -Arch "Win32" -LangBinding "" |
||||
Build-Library -BuildType "Release" -Arch "Win32" -LangBinding "csharp" |
||||
Build-Library -BuildType "Debug" -Arch "Win32" -LangBinding "" |
||||
Build-Library -BuildType "Debug" -Arch "Win32" -LangBinding "csharp" |
||||
# x64 |
||||
Build-Library -BuildType "Release" -Arch "x64" -LangBinding "" |
||||
Build-Library -BuildType "Release" -Arch "x64" -LangBinding "csharp" |
||||
Build-Library -BuildType "Debug" -Arch "x64" -LangBinding "" |
||||
Build-Library -BuildType "Debug" -Arch "x64" -LangBinding "csharp" |
||||
} |
||||
|
||||
function BuildNuGetPackages([string]$Version) |
||||
{ |
||||
BuildNuGetPackage-Sockets -BuildType "Release" -Arch "x64" -Version $Version |
||||
BuildNuGetPackage-Sockets -BuildType "Debug" -Arch "x64" -Version $Version |
||||
BuildNuGetPackage-Sockets -BuildType "Release" -Arch "Win32" -Version $Version |
||||
BuildNuGetPackage-Sockets -BuildType "Debug" -Arch "Win32" -Version $Version |
||||
} |
||||
|
||||
function BuildNuGetPackage-Sockets([string]$BuildType, [string]$Arch, [string]$Version) |
||||
{ |
||||
$archAlias = $Arch |
||||
if ($Arch -eq "Win32") { |
||||
$archAlias="x86" |
||||
} |
||||
|
||||
$TargetTuple = "win-"+$archAlias+"-nuget-"+$($BuildType.ToLower()) |
||||
|
||||
# Where we plan to output *.nupkg(s) |
||||
md pkg\nuget\ZeroTier.Sockets\bin\ -Force |
||||
md dist\$TargetTuple -Force |
||||
del dist\$TargetTuple\*.nupkg -ErrorAction:'silentlycontinue' |
||||
|
||||
# licenses |
||||
md pkg\nuget\ZeroTier.Sockets\licenses -Force |
||||
cp LICENSE.txt pkg\nuget\ZeroTier.Sockets\licenses |
||||
|
||||
# contentFiles (sources) |
||||
md pkg\nuget\ZeroTier.Sockets\contentFiles -Force |
||||
cp src\bindings\csharp\*.cs pkg\nuget\ZeroTier.Sockets\contentFiles |
||||
cp examples\csharp\*.cs pkg\nuget\ZeroTier.Sockets\contentFiles |
||||
|
||||
# runtimes |
||||
md pkg\nuget\ZeroTier.Sockets\runtimes\win10-$archAlias\native -Force |
||||
md pkg\nuget\ZeroTier.Sockets\runtimes\win10-$archAlias\lib\uap10.0 -Force |
||||
#md pkg\nuget\ZeroTier.Sockets\runtimes\win10-arm\native -Force |
||||
|
||||
# Build wrapper library for C# ZeroTier.Sockets abstraction |
||||
csc -target:library -debug:pdbonly ` |
||||
-pdb:pkg\nuget\ZeroTier.Sockets\bin\ZeroTier.Sockets.pdb ` |
||||
-out:pkg\nuget\ZeroTier.Sockets\bin\ZeroTier.Sockets.dll ` |
||||
.\src\bindings\csharp\*.cs |
||||
|
||||
# Build unmanaged native libzt.dll with exported P/INVOKE symbols |
||||
Build-Library -BuildType $BuildType -Arch $Arch -LangBinding "csharp" |
||||
|
||||
# Copy native libzt.dll into package tree |
||||
cp .\dist\win-$archAlias-pinvoke-$($BuildType.ToLower())\lib\*.dll ` |
||||
pkg\nuget\ZeroTier.Sockets\bin\libzt.dll |
||||
|
||||
# .NET Framework |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net40 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net403 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net45 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net451 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net452 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net46 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net461 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net462 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net47 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net471 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net472 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net48 -Force |
||||
|
||||
# .NET "Core" 5.0 (moniker missing from microsoft documentation?) |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net5.0 -Force |
||||
|
||||
# Copy assemblies into framework-specific directories. |
||||
$folders = Get-ChildItem pkg\nuget\ZeroTier.Sockets\lib\ |
||||
foreach ($folder in $folders.name){ |
||||
cp -Path "pkg\nuget\ZeroTier.Sockets\bin\*.*" ` |
||||
-Destination "pkg\nuget\ZeroTier.Sockets\lib\$folder" -Recurse |
||||
} |
||||
|
||||
# Native DLL placement |
||||
|
||||
cp .\dist\win-$archAlias-pinvoke-$($BuildType.ToLower())\lib\*.dll ` |
||||
pkg\nuget\ZeroTier.Sockets\runtimes\win10-$archAlias\lib\uap10.0\libzt.dll |
||||
cp .\dist\win-$archAlias-pinvoke-$($BuildType.ToLower())\lib\*.dll ` |
||||
pkg\nuget\ZeroTier.Sockets\lib\net40\libzt.dll |
||||
cp .\dist\win-$archAlias-pinvoke-$($BuildType.ToLower())\lib\*.dll ` |
||||
pkg\nuget\ZeroTier.Sockets\runtimes\win10-$archAlias\native\libzt.dll |
||||
cp .\dist\win-$archAlias-pinvoke-$($BuildType.ToLower())\lib\*.pdb ` |
||||
pkg\nuget\ZeroTier.Sockets\runtimes\win10-$archAlias\lib\uap10.0\libzt.pdb |
||||
|
||||
# Package |
||||
pushd -Path pkg\nuget\ZeroTier.Sockets |
||||
nuget pack ZeroTier.Sockets.$archAlias.nuspec ` |
||||
-Version $Version -OutputDirectory ..\..\..\dist\$TargetTuple\ |
||||
popd |
||||
} |
||||
|
||||
function Clean-PackageDirectory |
||||
{ |
||||
rm pkg\nuget\ZeroTier.Sockets\lib ` |
||||
-Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue' |
||||
rm pkg\nuget\ZeroTier.Sockets\contentFiles ` |
||||
-Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue' |
||||
rm pkg\nuget\ZeroTier.Sockets\licenses ` |
||||
-Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue' |
||||
rm pkg\nuget\ZeroTier.Sockets\runtimes ` |
||||
-Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue' |
||||
rm pkg\nuget\ZeroTier.Sockets\bin ` |
||||
-Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue' |
||||
} |
||||
|
||||
function Clean |
||||
{ |
||||
rm cache -Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue' |
||||
rm dist -Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue' |
||||
} |
||||
@ -1,175 +0,0 @@
|
||||
function Clean |
||||
{ |
||||
Remove-Item builds -Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue' |
||||
Remove-Item tmp -Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue' |
||||
Remove-Item lib -Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue' |
||||
Remove-Item bin -Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue' |
||||
# pkg |
||||
Clean-PackageDirectory |
||||
Get-ChildItem pkg -recurse -include *.dll | remove-item |
||||
Get-ChildItem pkg -recurse -include *.lib | remove-item |
||||
Get-ChildItem pkg -recurse -include *.pdb | remove-item |
||||
Get-ChildItem pkg -recurse -include *.nupkg | remove-item |
||||
# src |
||||
Get-ChildItem src -recurse -include *.dll | remove-item |
||||
Get-ChildItem src -recurse -include *.lib | remove-item |
||||
Get-ChildItem src -recurse -include *.pdb | remove-item |
||||
Get-ChildItem src -recurse -include *.dylib | remove-item |
||||
Get-ChildItem src -recurse -include *.so | remove-item |
||||
Get-ChildItem src -recurse -include *.exe | remove-item |
||||
Get-ChildItem src -recurse -include *.out | remove-item |
||||
Get-ChildItem src -recurse -include *.a | remove-item |
||||
} |
||||
|
||||
function Build-Library([string]$BuildType, [string]$Arch, [string]$LanguageBinding) |
||||
{ |
||||
$OptionalLanguageBinding="" |
||||
|
||||
if ($LanguageBinding -eq "csharp") { |
||||
$OptionalLanguageBinding="-DZTS_PINVOKE:BOOL=ON" |
||||
$LanguageBindingPostfix="-pinvoke" |
||||
} |
||||
if ($LanguageBinding -eq "java") { |
||||
#$OptionalLanguageBinding="-DSDK_JNI=ON -DSDK_JNI=1" |
||||
#$LanguageBindingPostfix="-jni" |
||||
} |
||||
|
||||
$archAlias = "" |
||||
$bitCount = "" |
||||
|
||||
if ($Arch -eq "Win32") { |
||||
$bitCount="32" |
||||
$archAlias="win-x86" |
||||
} |
||||
if ($Arch -eq "x64") { |
||||
$bitCount="64" |
||||
$archAlias="win-x64" |
||||
} |
||||
#if ($Arch -eq "ARM32") { |
||||
# $bitCount="32" |
||||
# $archAlias="win-arm" |
||||
#} |
||||
if ($Arch -eq "ARM") { |
||||
$bitCount="64" |
||||
$archAlias="win-arm64" |
||||
} |
||||
|
||||
if ($archAlias -eq "" -or $bitCount -eq "") { |
||||
echo "No valid architecture specified. Breaking." |
||||
break |
||||
} |
||||
|
||||
# Directory for CMake to build and store intermediate files |
||||
$env:BuildDir="tmp\$BuildType\"+$Arch+$LanguageBindingPostfix |
||||
md $env:BuildDir -ErrorAction:'silentlycontinue' |
||||
# Directory where we plan to store the resultant libraries |
||||
$env:OutputDir="lib\"+$BuildType.ToLower() |
||||
md $env:OutputDir\$archAlias$LanguageBindingPostfix -ErrorAction:'silentlycontinue' |
||||
Push-Location -Path $env:BuildDir |
||||
cmake ${OptionalLanguageBinding} -G "Visual Studio 16 2019" -A $Arch ../../../ |
||||
cmake --build . --config $BuildType |
||||
Pop-Location |
||||
Copy-Item $env:BuildDir\$BuildType\zt.lib $env:OutputDir\$archAlias$LanguageBindingPostfix\libzt$bitCount.lib |
||||
Copy-Item $env:BuildDir\$BuildType\zt-shared.dll $env:OutputDir\$archAlias$LanguageBindingPostfix\libzt$bitCount.dll |
||||
Copy-Item $env:BuildDir\$BuildType\zt-shared.pdb $env:OutputDir\$archAlias$LanguageBindingPostfix\libzt$bitCount.pdb -ErrorAction:'silentlycontinue' |
||||
} |
||||
|
||||
function Build-All |
||||
{ |
||||
# Win32 |
||||
Build-Library -BuildType "Release" -Arch "Win32" -LanguageBinding "" |
||||
Build-Library -BuildType "Release" -Arch "Win32" -LanguageBinding "pinvoke" |
||||
Build-Library -BuildType "Debug" -Arch "Win32" -LanguageBinding "" |
||||
Build-Library -BuildType "Debug" -Arch "Win32" -LanguageBinding "pinvoke" |
||||
# x64 |
||||
Build-Library -BuildType "Release" -Arch "x64" -LanguageBinding "" |
||||
Build-Library -BuildType "Release" -Arch "x64" -LanguageBinding "pinvoke" |
||||
Build-Library -BuildType "Debug" -Arch "x64" -LanguageBinding "" |
||||
Build-Library -BuildType "Debug" -Arch "x64" -LanguageBinding "pinvoke" |
||||
} |
||||
|
||||
function BuildNuGetPackages([string]$Version) |
||||
{ |
||||
BuildNuGetPackage-Sockets -BuildType "Release" -Arch "x64" -Version $Version |
||||
BuildNuGetPackage-Sockets -BuildType "Debug" -Arch "x64" -Version $Version |
||||
BuildNuGetPackage-Sockets -BuildType "Release" -Arch "Win32" -Version $Version |
||||
BuildNuGetPackage-Sockets -BuildType "Debug" -Arch "Win32" -Version $Version |
||||
} |
||||
|
||||
function BuildNuGetPackage-Sockets([string]$BuildType, [string]$Arch, [string]$Version) |
||||
{ |
||||
$archAlias = $Arch |
||||
if ($Arch -eq "Win32") { |
||||
$archAlias="x86" |
||||
} |
||||
|
||||
md pkg\nuget\ZeroTier.Sockets\bin\ -Force |
||||
md builds\pkg\nuget\$($BuildType.ToLower())\$archAlias -Force |
||||
del builds\pkg\nuget\$($BuildType.ToLower())\$archAlias\*.nupkg -ErrorAction:'silentlycontinue' |
||||
|
||||
# licenses |
||||
md pkg\nuget\ZeroTier.Sockets\licenses -Force |
||||
Copy-Item LICENSE.txt pkg\nuget\ZeroTier.Sockets\licenses |
||||
|
||||
# contentFiles (sources) |
||||
md pkg\nuget\ZeroTier.Sockets\contentFiles -Force |
||||
Copy-Item src\bindings\csharp\*.cs pkg\nuget\ZeroTier.Sockets\contentFiles |
||||
|
||||
# Where we plan to output *.nupkg(s) |
||||
md builds\pkg\nuget\$($BuildType.ToLower()) -Force |
||||
|
||||
# runtimes |
||||
md pkg\nuget\ZeroTier.Sockets\runtimes\win10-$archAlias\native -Force |
||||
md pkg\nuget\ZeroTier.Sockets\runtimes\win10-$archAlias\lib\uap10.0 -Force |
||||
#md pkg\nuget\ZeroTier.Sockets\runtimes\win10-arm\native -Force |
||||
|
||||
# Build wrapper library for C# ZeroTier.Sockets abstraction |
||||
csc -target:library -debug:pdbonly -pdb:pkg\nuget\ZeroTier.Sockets\bin\ZeroTier.Sockets.pdb -out:pkg\nuget\ZeroTier.Sockets\bin\ZeroTier.Sockets.dll .\src\bindings\csharp\*.cs |
||||
|
||||
# Build unmanaged native libzt.dll with exported P/INVOKE symbols |
||||
Build-Library -BuildType $BuildType -Arch $Arch -LanguageBinding "csharp" |
||||
Copy-Item .\lib\$($BuildType.ToLower())\win-$archAlias-pinvoke\*.dll pkg\nuget\ZeroTier.Sockets\bin\libzt.dll |
||||
|
||||
# .NET Framework |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net40 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net403 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net45 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net451 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net452 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net46 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net461 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net462 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net47 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net471 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net472 -Force |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net48 -Force |
||||
|
||||
# .NET "Core" 5.0 (moniker missing from microsoft documentation?) |
||||
md pkg\nuget\ZeroTier.Sockets\lib\net5.0 -Force |
||||
|
||||
# Copy assemblies into framework-specific directories. |
||||
$folders = Get-ChildItem pkg\nuget\ZeroTier.Sockets\lib\ |
||||
foreach ($folder in $folders.name){ |
||||
Copy-Item -Path "pkg\nuget\ZeroTier.Sockets\bin\*.*" -Destination "pkg\nuget\ZeroTier.Sockets\lib\$folder" -Recurse |
||||
} |
||||
|
||||
# Native DLL placement |
||||
Copy-Item .\lib\$($BuildType.ToLower())\win-$archAlias-pinvoke\*.dll pkg\nuget\ZeroTier.Sockets\runtimes\win10-$archAlias\lib\uap10.0\libzt.dll |
||||
Copy-Item .\lib\$($BuildType.ToLower())\win-$archAlias-pinvoke\*.dll pkg\nuget\ZeroTier.Sockets\lib\net40\libzt.dll |
||||
Copy-Item .\lib\$($BuildType.ToLower())\win-$archAlias-pinvoke\*.dll pkg\nuget\ZeroTier.Sockets\runtimes\win10-$archAlias\native\libzt.dll |
||||
Copy-Item .\lib\$($BuildType.ToLower())\win-$archAlias-pinvoke\*.pdb pkg\nuget\ZeroTier.Sockets\runtimes\win10-$archAlias\lib\uap10.0\libzt.pdb |
||||
|
||||
# Package |
||||
Push-Location -Path pkg\nuget\ZeroTier.Sockets |
||||
nuget pack ZeroTier.Sockets.$archAlias.nuspec -Version $Version -OutputDirectory ..\..\..\builds\pkg\nuget\$($BuildType.ToLower())\$archAlias |
||||
Pop-Location |
||||
} |
||||
|
||||
function Clean-PackageDirectory |
||||
{ |
||||
Remove-Item pkg\nuget\ZeroTier.Sockets\lib -Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue' |
||||
Remove-Item pkg\nuget\ZeroTier.Sockets\contentFiles -Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue' |
||||
Remove-Item pkg\nuget\ZeroTier.Sockets\licenses -Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue' |
||||
Remove-Item pkg\nuget\ZeroTier.Sockets\runtimes -Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue' |
||||
Remove-Item pkg\nuget\ZeroTier.Sockets\bin -Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue' |
||||
} |
||||
@ -1,737 +0,0 @@
|
||||
#!/bin/bash |
||||
|
||||
# This script works in conjunction with the Makefile and CMakeLists.txt. It is |
||||
# intended to be called from the Makefile, it generates projects and builds |
||||
# targets as specified in CMakeLists.txt. In addition, this script is |
||||
# responsible for packaging all of the resultant builds, licenses, and |
||||
# documentation as well as controlling the installation and remote execution of |
||||
# tests on mobile devices. |
||||
|
||||
# Example workflow for producing a full release package: |
||||
# |
||||
# (1) On packaging platform, build most targets (including android and ios): |
||||
# (1a) make all |
||||
# (1b) make wrap |
||||
# (2) On other supported platforms, build remaining supported targets |
||||
# and copy them into a directory structure that is expected by a later stage: |
||||
# (2a) make all |
||||
# (2b) make wrap |
||||
# (3) Copy all resultant $(ARCH)_product directories to root project directory |
||||
# of packaging platform. For instance: |
||||
# |
||||
# libzt |
||||
# ├── README.md |
||||
# ├── products |
||||
# ├── linux-x86_64_products |
||||
# ├── linux-armv7l_products |
||||
# ├── linux-armv6l_products |
||||
# ├── products |
||||
# ├── win_products |
||||
# └── ... |
||||
# |
||||
# (4) Merge all builds into single `products` directory and package: |
||||
# (4a) make clean |
||||
# (4a) make dist |
||||
|
||||
CMAKE=cmake |
||||
BUILD_CONCURRENCY= |
||||
#"-j 2" |
||||
OSNAME=$(uname | tr '[A-Z]' '[a-z]') |
||||
BUILD_TMP=$(pwd)/tmp |
||||
ANDROID_PROJ_DIR=$(pwd)/pkg/android |
||||
XCODE_IOS_PROJ_DIR=$(pwd)/ports/xcode_ios |
||||
XCODE_IOS_SIMULATOR_PROJ_DIR=$(pwd)/ports/xcode_ios_simulator |
||||
XCODE_MACOS_PROJ_DIR=$(pwd)/ports/xcode_macos |
||||
|
||||
# Generates wrapper source files for various target languages |
||||
generate_swig_wrappers() |
||||
{ |
||||
SRC=../src |
||||
|
||||
cd ports/; |
||||
|
||||
# C# |
||||
mkdir -p ${SRC}/csharp |
||||
swig -csharp -c++ zt.i |
||||
# Prepend our callback garb to libzt.cs, copy new source files into src/csharp |
||||
cat csharp/csharp_callback.cs libzt.cs > libzt_concat.cs |
||||
rm libzt.cs |
||||
mv libzt_concat.cs libzt.cs |
||||
mv -f *.cs zt_wrap.cxx ${SRC}/csharp/ |
||||
|
||||
# Javascript |
||||
# Build for all three engines. Why not? |
||||
ENGINE=jsc |
||||
mkdir -p ${SRC}/js/${ENGINE} |
||||
swig -javascript -${ENGINE} -c++ zt.i |
||||
mv zt_wrap.cxx ${SRC}/js/${ENGINE} |
||||
ENGINE=v8 |
||||
mkdir -p ${SRC}/js/${ENGINE} |
||||
swig -javascript -${ENGINE} -c++ zt.i |
||||
mv zt_wrap.cxx ${SRC}/js/${ENGINE} |
||||
ENGINE=node |
||||
mkdir -p ${SRC}/js/${ENGINE} |
||||
swig -javascript -${ENGINE} -c++ zt.i |
||||
mv -f zt_wrap.cxx ${SRC}/js/${ENGINE} |
||||
|
||||
# Python |
||||
mkdir -p ${SRC}/python |
||||
swig -python -c++ zt.i |
||||
mv -f zt_wrap.cxx *.py ${SRC}/python |
||||
|
||||
# Lua |
||||
mkdir -p ${SRC}/lua |
||||
swig -lua -c++ zt.i |
||||
mv -f zt_wrap.cxx ${SRC}/lua |
||||
|
||||
# Go 64 |
||||
mkdir -p ${SRC}/go64 |
||||
swig -intgosize 64 -go -c++ zt.i |
||||
mv -f zt_wrap.cxx *.go *.c ${SRC}/go64 |
||||
|
||||
# Go 32 |
||||
mkdir -p ${SRC}/go32 |
||||
swig -intgosize 32 -go -c++ zt.i |
||||
mv -f zt_wrap.cxx *.go *.c ${SRC}/go32 |
||||
|
||||
cd - |
||||
} |
||||
|
||||
# Generates projects if needed |
||||
generate_projects() |
||||
{ |
||||
if [[ ! $OSNAME = *"darwin"* ]]; then |
||||
exit 0 |
||||
fi |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
if [[ $OSNAME = *"darwin"* ]]; then |
||||
# iOS (SDK 11+, 64-bit only, arm64) |
||||
if [ ! -d "$XCODE_IOS_PROJ_DIR" ]; then |
||||
mkdir -p $XCODE_IOS_PROJ_DIR |
||||
cd $XCODE_IOS_PROJ_DIR |
||||
$CMAKE -G Xcode ../../ -DIOS_FRAMEWORK=1 -DIOS_ARM64=1 |
||||
# Manually replace arch strings in project file |
||||
sed -i '' 's/x86_64/$(CURRENT_ARCH)/g' zt.xcodeproj/project.pbxproj |
||||
cd - |
||||
fi |
||||
|
||||
if [ ! -d "$XCODE_IOS_SIMULATOR_PROJ_DIR" ]; then |
||||
mkdir -p $XCODE_IOS_SIMULATOR_PROJ_DIR |
||||
cd $XCODE_IOS_SIMULATOR_PROJ_DIR |
||||
$CMAKE -G Xcode ../../ -DIOS_FRAMEWORK=1 |
||||
# Manually replace arch strings in project file |
||||
#sed -i '' 's/x86_64/$(CURRENT_ARCH)/g' zt.xcodeproj/project.pbxproj |
||||
cd - |
||||
fi |
||||
|
||||
# macOS |
||||
if [ ! -d "$XCODE_MACOS_PROJ_DIR" ]; then |
||||
mkdir -p $XCODE_MACOS_PROJ_DIR |
||||
cd $XCODE_MACOS_PROJ_DIR |
||||
$CMAKE -G Xcode ../../ -DMACOS_FRAMEWORK=1 |
||||
cd - |
||||
fi |
||||
fi |
||||
} |
||||
|
||||
# Build framework for iOS (with embedded static library) |
||||
ios() |
||||
{ |
||||
if [[ ! $OSNAME = *"darwin"* ]]; then |
||||
exit 0 |
||||
fi |
||||
generate_projects # if needed |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
UPPERCASE_CONFIG="$(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1}" |
||||
|
||||
cd $XCODE_IOS_PROJ_DIR |
||||
# Framework |
||||
xcodebuild -arch arm64 -target zt -configuration "$UPPERCASE_CONFIG" -sdk "iphoneos" |
||||
cd - |
||||
IOS_OUTPUT_DIR=$(pwd)/lib/$1/ios |
||||
mkdir -p $IOS_OUTPUT_DIR |
||||
rm -rf $IOS_OUTPUT_DIR/zt.framework # Remove prior to move to prevent error |
||||
mv $XCODE_IOS_PROJ_DIR/$UPPERCASE_CONFIG-iphoneos/* $IOS_OUTPUT_DIR |
||||
|
||||
cd $XCODE_IOS_SIMULATOR_PROJ_DIR |
||||
# Framework |
||||
xcodebuild -target zt -configuration "$UPPERCASE_CONFIG" -sdk "iphonesimulator" |
||||
cd - |
||||
SIMULATOR_OUTPUT_DIR=$(pwd)/lib/$1/ios-simulator |
||||
mkdir -p $SIMULATOR_OUTPUT_DIR |
||||
rm -rf $SIMULATOR_OUTPUT_DIR/zt.framework # Remove prior to move to prevent error |
||||
mv $XCODE_IOS_SIMULATOR_PROJ_DIR/$UPPERCASE_CONFIG-iphonesimulator/* $SIMULATOR_OUTPUT_DIR |
||||
|
||||
# Combine the two archs |
||||
lipo -create $IOS_OUTPUT_DIR/zt.framework/zt $SIMULATOR_OUTPUT_DIR/zt.framework/zt -output $IOS_OUTPUT_DIR/zt.framework/zt |
||||
|
||||
# Clean up |
||||
rm -rf $SIMULATOR_OUTPUT_DIR |
||||
} |
||||
|
||||
# Build framework for current host (macOS only) |
||||
macos() |
||||
{ |
||||
if [[ ! $OSNAME = *"darwin"* ]]; then |
||||
exit 0 |
||||
fi |
||||
generate_projects # if needed |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
UPPERCASE_CONFIG="$(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1}" |
||||
cd $XCODE_MACOS_PROJ_DIR |
||||
# Framework |
||||
xcodebuild -target zt -configuration "$UPPERCASE_CONFIG" -sdk "macosx" |
||||
cd - |
||||
OUTPUT_DIR=$(pwd)/lib/$1/macos-universal |
||||
mkdir -p $OUTPUT_DIR |
||||
rm -rf $OUTPUT_DIR/zt.framework # Remove prior to move to prevent error |
||||
mv $XCODE_MACOS_PROJ_DIR/$UPPERCASE_CONFIG/* $OUTPUT_DIR |
||||
} |
||||
|
||||
# Build xcframework |
||||
xcframework() |
||||
{ |
||||
if [[ ! $OSNAME = *"darwin"* ]]; then |
||||
exit 0 |
||||
fi |
||||
generate_projects # if needed |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
UPPERCASE_CONFIG="$(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1}" |
||||
OUTPUT_DIR=$(pwd)/lib/$1 |
||||
cd $XCODE_MACOS_PROJ_DIR |
||||
xcodebuild -target zt -configuration "$UPPERCASE_CONFIG" -sdk "macosx" |
||||
|
||||
cd $XCODE_IOS_PROJ_DIR |
||||
xcodebuild -arch arm64 -target zt -configuration "$UPPERCASE_CONFIG" -sdk "iphoneos" |
||||
|
||||
cd $XCODE_IOS_SIMULATOR_PROJ_DIR |
||||
xcodebuild -target zt -configuration "$UPPERCASE_CONFIG" -sdk "iphonesimulator" |
||||
|
||||
mkdir -p $OUTPUT_DIR |
||||
|
||||
rm -rf $OUTPUT_DIR/zt.xcframework # Remove prior to move to prevent error |
||||
xcodebuild -create-xcframework \ |
||||
-framework $XCODE_MACOS_PROJ_DIR/$UPPERCASE_CONFIG/zt.framework \ |
||||
-framework $XCODE_IOS_PROJ_DIR/$UPPERCASE_CONFIG-iphoneos/zt.framework \ |
||||
-framework $XCODE_IOS_SIMULATOR_PROJ_DIR/$UPPERCASE_CONFIG-iphonesimulator/zt.framework \ |
||||
-output $OUTPUT_DIR/zt.xcframework |
||||
} |
||||
|
||||
# Build Java JAR for current host (uses JNI) |
||||
host_jar() |
||||
{ |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
copy_root_java_sources_to_projects |
||||
NORMALIZED_OSNAME=$OSNAME |
||||
if [[ $OSNAME = *"darwin"* ]]; then |
||||
DYNAMIC_LIB_NAME="libzt.dylib" |
||||
NORMALIZED_OSNAME="macos" |
||||
fi |
||||
if [[ $OSNAME = *"linux"* ]]; then |
||||
DYNAMIC_LIB_NAME="libzt.so" |
||||
fi |
||||
LIB_OUTPUT_DIR=$(pwd)/lib/$1/${NORMALIZED_OSNAME}-$(uname -m) |
||||
mkdir -p $LIB_OUTPUT_DIR |
||||
rm -rf $LIB_OUTPUT_DIR/zt.jar |
||||
# Build dynamic library |
||||
BUILD_DIR=$(pwd)/tmp/${NORMALIZED_OSNAME}-$(uname -m)-jni-$1 |
||||
UPPERCASE_CONFIG="$(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1}" |
||||
$CMAKE -H. -B$BUILD_DIR -DCMAKE_BUILD_TYPE=$UPPERCASE_CONFIG -DSDK_JNI=ON "-DSDK_JNI=1" |
||||
$CMAKE --build $BUILD_DIR $BUILD_CONCURRENCY |
||||
# Copy dynamic library from previous build step |
||||
# And, remove any lib that may exist prior. We don't want accidental successes |
||||
cd $(pwd)/ports/java |
||||
rm $DYNAMIC_LIB_NAME |
||||
mv $BUILD_DIR/lib/$DYNAMIC_LIB_NAME . |
||||
# Begin constructing JAR |
||||
export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8 |
||||
javac com/zerotier/libzt/*.java |
||||
jar cf zt.jar $DYNAMIC_LIB_NAME com/zerotier/libzt/*.class |
||||
rm $DYNAMIC_LIB_NAME |
||||
cd - |
||||
# Move completed JAR |
||||
LIB_OUTPUT_DIR=$(pwd)/lib/$1/${NORMALIZED_OSNAME}-$(uname -m) |
||||
mkdir -p $LIB_OUTPUT_DIR |
||||
mv $(pwd)/ports/java/zt.jar $LIB_OUTPUT_DIR |
||||
# Build sample app classes |
||||
# Remove old dynamic library if it exists |
||||
rm -rf $(pwd)/examples/java/$DYNAMIC_LIB_NAME |
||||
javac -cp ".:"$LIB_OUTPUT_DIR/zt.jar $(pwd)/examples/java/src/com/zerotier/libzt/javasimpleexample/*.java |
||||
# To run: |
||||
# jar xf $LIB_OUTPUT_DIR/zt.jar libzt.dylib |
||||
# cp libzt.dylib examples/java/ |
||||
# java -cp "lib/debug/macos-x86_64/zt.jar:examples/java/src/main/java" ExampleApp |
||||
} |
||||
|
||||
# Build all ordinary library types for current host |
||||
host_pinvoke() |
||||
{ |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
NORMALIZED_OSNAME=$OSNAME |
||||
if [[ $OSNAME = *"darwin"* ]]; then |
||||
DYNAMIC_LIB_NAME="libzt.dylib" |
||||
NORMALIZED_OSNAME="macos" |
||||
fi |
||||
if [[ $OSNAME = *"linux"* ]]; then |
||||
DYNAMIC_LIB_NAME="libzt.so" |
||||
fi |
||||
# CMake build files |
||||
BUILD_DIR=$(pwd)/tmp/${NORMALIZED_OSNAME}-$(uname -m)-$1 |
||||
mkdir -p $BUILD_DIR |
||||
# Where to place results |
||||
BIN_OUTPUT_DIR=$(pwd)/bin/$1/${NORMALIZED_OSNAME}-$(uname -m) |
||||
mkdir -p $BIN_OUTPUT_DIR |
||||
rm -rf $BIN_OUTPUT_DIR/* |
||||
LIB_OUTPUT_DIR=$(pwd)/lib/$1/${NORMALIZED_OSNAME}-$(uname -m)-pinvoke |
||||
mkdir -p $LIB_OUTPUT_DIR |
||||
rm -rf $LIB_OUTPUT_DIR/libzt.a $LIB_OUTPUT_DIR/$DYNAMIC_LIB_NAME $LIB_OUTPUT_DIR/libztcore.a |
||||
# Build |
||||
cmake -DZTS_PINVOKE=True -H. -B$BUILD_DIR -DCMAKE_BUILD_TYPE=$1 |
||||
$CMAKE --build $BUILD_DIR $BUILD_CONCURRENCY |
||||
# Move and clean up |
||||
cp -f $BUILD_DIR/bin/* $BIN_OUTPUT_DIR |
||||
cp -f $BUILD_DIR/lib/* $LIB_OUTPUT_DIR |
||||
clean_post_build |
||||
} |
||||
|
||||
# Build all ordinary library types for current host |
||||
host() |
||||
{ |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
NORMALIZED_OSNAME=$OSNAME |
||||
if [[ $OSNAME = *"darwin"* ]]; then |
||||
DYNAMIC_LIB_NAME="libzt.dylib" |
||||
NORMALIZED_OSNAME="macos" |
||||
fi |
||||
if [[ $OSNAME = *"linux"* ]]; then |
||||
DYNAMIC_LIB_NAME="libzt.so" |
||||
fi |
||||
# CMake build files |
||||
BUILD_DIR=$(pwd)/tmp/${NORMALIZED_OSNAME}-$(uname -m)-$1 |
||||
mkdir -p $BUILD_DIR |
||||
# Where to place results |
||||
BIN_OUTPUT_DIR=$(pwd)/bin/$1/${NORMALIZED_OSNAME}-$(uname -m) |
||||
mkdir -p $BIN_OUTPUT_DIR |
||||
rm -rf $BIN_OUTPUT_DIR/* |
||||
LIB_OUTPUT_DIR=$(pwd)/lib/$1/${NORMALIZED_OSNAME}-$(uname -m) |
||||
mkdir -p $LIB_OUTPUT_DIR |
||||
rm -rf $LIB_OUTPUT_DIR/libzt.a $LIB_OUTPUT_DIR/$DYNAMIC_LIB_NAME $LIB_OUTPUT_DIR/libztcore.a |
||||
# Build |
||||
$CMAKE -H. -B$BUILD_DIR -DCMAKE_BUILD_TYPE=$1 |
||||
$CMAKE --build $BUILD_DIR $BUILD_CONCURRENCY |
||||
# Move and clean up |
||||
cp -f $BUILD_DIR/bin/* $BIN_OUTPUT_DIR |
||||
cp -f $BUILD_DIR/lib/* $LIB_OUTPUT_DIR |
||||
clean_post_build |
||||
} |
||||
|
||||
# Set important variables for Android builds |
||||
set_android_env() |
||||
{ |
||||
# Set ANDROID_HOME because setting sdk.dir in local.properties isn't always reliable |
||||
#export PATH=/Library/Java/JavaVirtualMachines/$JDK/Contents/Home/bin/:${PATH} |
||||
#export PATH=/Users/$USER/Library/Android/sdk/platform-tools/:${PATH} |
||||
GRADLE_ARGS=--stacktrace |
||||
#ANDROID_APP_NAME=com.example.mynewestapplication |
||||
# for our purposes we limit this to execution on macOS |
||||
if [[ $OSNAME = *"linux"* ]]; then |
||||
export ANDROID_HOME=/usr/lib/android-sdk/ |
||||
fi |
||||
if [[ $OSNAME = *"darwin"* ]]; then |
||||
export ANDROID_HOME=/Users/$USER/Library/Android/sdk |
||||
fi |
||||
} |
||||
|
||||
# Build android AAR |
||||
android() |
||||
{ |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
# Unsure why, but Gradle's build script chokes on this non-source file now |
||||
rm -rf ext/ZeroTierOne/ext/miniupnpc/VERSION |
||||
export PATH=$ANDROID_HOME/cmdline-tools/tools/bin:$PATH |
||||
set_android_env |
||||
# Copy source files into project |
||||
cp -f src/bindings/java/*.java ${ANDROID_PROJ_DIR}/app/src/main/java/com/zerotier/libzt |
||||
# CMake build files |
||||
BUILD_DIR=$(pwd)/tmp/android-$1 |
||||
mkdir -p $BUILD_DIR |
||||
# If clean requested, remove temp build dir |
||||
if [[ $1 = *"clean"* ]]; then |
||||
rm -rf $BUILD_DIR |
||||
exit 0 |
||||
fi |
||||
# Where to place results |
||||
LIB_OUTPUT_DIR=$(pwd)/lib/$1/android |
||||
mkdir -p $LIB_OUTPUT_DIR |
||||
# Build |
||||
UPPERCASE_CONFIG="$(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1}" |
||||
CMAKE_FLAGS="-DSDK_JNI=1 -DSDK_JNI=ON" |
||||
cd $ANDROID_PROJ_DIR |
||||
./gradlew $GRADLE_ARGS assemble$UPPERCASE_CONFIG # assembleRelease / assembleDebug |
||||
mv $ANDROID_PROJ_DIR/app/build/outputs/aar/*.aar \ |
||||
$LIB_OUTPUT_DIR/libzt-$1.aar |
||||
cd - |
||||
} |
||||
|
||||
# Remove intermediate object files and/or libraries |
||||
clean_post_build() |
||||
{ |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
find $(pwd)/lib -type f -name 'liblwip_pic.a' -exec rm {} + |
||||
find $(pwd)/lib -type f -name 'liblwip.a' -exec rm {} + |
||||
find $(pwd)/lib -type f -name 'libminiupnpc.a' -exec rm {} + |
||||
find $(pwd)/lib -type f -name 'libminiupnpc_pic.a' -exec rm {} + |
||||
find $(pwd)/lib -type f -name 'libnatpmp.a' -exec rm {} + |
||||
find $(pwd)/lib -type f -name 'libnatpmp_pic.a' -exec rm {} + |
||||
find $(pwd)/lib -type f -name 'libzto_pic.a' -exec rm {} + |
||||
find $(pwd)/lib -type f -name 'libzt_pic.a' -exec rm {} + |
||||
} |
||||
|
||||
# General clean |
||||
clean() |
||||
{ |
||||
# Remove all temporary build files, products, etc |
||||
rm -rf builds tmp lib bin products |
||||
rm -f *.o *.s *.exp *.lib *.core core |
||||
# Generally search for and remove object files, libraries, etc |
||||
find . -path './*_products' -prune -type f \( -name '*.dylib' -o -name '*.dll' -o -name '*.so' -o -name \ |
||||
'*.a' -o -name '*.o' -o -name '*.exe' -o -name '*.o.d' -o -name \ |
||||
'*.out' -o -name '*.log' -o -name '*.dSYM' -o -name '*.class' \) -delete |
||||
# Remove any sources copied to project directories |
||||
rm -rf ports/android/app/src/main/java/com/zerotier/libzt/*.java |
||||
rm -rf ports/java/com/zerotier/libzt/*.java |
||||
} |
||||
|
||||
# Copy and rename Android AAR from lib to example app directory |
||||
prep_android_example() |
||||
{ |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
mkdir -p examples/android/ExampleAndroidApp/app/libs/ |
||||
cp -f lib/$1/android/libzt-$1.aar \ |
||||
examples/android/ExampleAndroidApp/app/libs/libzt.aar |
||||
} |
||||
# Clean Android project |
||||
clean_android_project() |
||||
{ |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
set_android_env |
||||
ANDROID_EXAMPLE_PROJ_DIR="examples/android/ExampleAndroidApp" |
||||
cd $ANDROID_EXAMPLE_PROJ_DIR |
||||
./gradlew $GRADLE_ARGS clean |
||||
./gradlew $GRADLE_ARGS cleanBuildCache |
||||
cd - |
||||
} |
||||
# Build APK from AAR and sources |
||||
build_android_app() |
||||
{ |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
set_android_env |
||||
ANDROID_EXAMPLE_PROJ_DIR="examples/android/ExampleAndroidApp" |
||||
UPPERCASE_CONFIG="$(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1}" |
||||
cd $ANDROID_EXAMPLE_PROJ_DIR |
||||
./gradlew assemble$UPPERCASE_CONFIG |
||||
cd - |
||||
} |
||||
# Stops an Android app that is already installed on device |
||||
stop_android_app() |
||||
{ |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
set_android_env |
||||
adb shell am force-stop $ANDROID_APP_NAME |
||||
} |
||||
# Starts an Android app that is already installed on device |
||||
start_android_app() |
||||
{ |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
set_android_env |
||||
adb shell monkey -p $ANDROID_APP_NAME 1 |
||||
} |
||||
# Copy and install example Android app on device |
||||
install_android_app() |
||||
{ |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
set_android_env |
||||
if [[ $1 = "release" ]]; then |
||||
APKNAME=app-$1-"unsigned" |
||||
else |
||||
APKNAME=app-$1 |
||||
fi |
||||
APK=examples/android/ExampleAndroidApp/app/build/outputs/apk/$1/$APKNAME.apk |
||||
echo "Installing $APK ..." |
||||
adb install -r $APK |
||||
} |
||||
# Perform all steps necessary to run a new instance of the app on device |
||||
run_android_app() |
||||
{ |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
stop_android_app |
||||
prep_android_example $1 |
||||
clean_android_project |
||||
# The following two functions take 'debug' as an argument regardless |
||||
# of the build type since the native code is built with the proper |
||||
# configuration anyway. |
||||
build_android_app "debug" |
||||
install_android_app "debug" |
||||
start_android_app |
||||
} |
||||
# View ADB logs of running Android app |
||||
android_app_log() |
||||
{ |
||||
set_android_env |
||||
if [[ $OSNAME = *"darwin"* ]]; then |
||||
adb logcat |
||||
fi |
||||
} |
||||
# View ADB logs of running Android app (filtered, must restart for each app re-launch) |
||||
android_app_log_filtered() |
||||
{ |
||||
set_android_env |
||||
if [[ $OSNAME = *"darwin"* ]]; then |
||||
adb logcat | grep -F "`adb shell ps | grep $ANDROID_APP_NAME | cut -c10-15`" |
||||
fi |
||||
} |
||||
|
||||
|
||||
# Copy java sources to projects before build process. This is so |
||||
# that we only have to maintain one set of sources for multiple java- |
||||
# based projects. |
||||
copy_root_java_sources_to_projects() |
||||
{ |
||||
cp -f src/bindings/java/*.java ports/java/com/zerotier/libzt/ |
||||
} |
||||
|
||||
# At the end of build stage, print contents and trees for inspection |
||||
display() |
||||
{ |
||||
find $(pwd)/lib -type f -name 'zt.jar' -exec echo -e "\n" \; -exec ls {} \; -exec jar tf {} + |
||||
echo -e "\n" |
||||
tree $(pwd)/lib |
||||
} |
||||
|
||||
# Merge all remotely-built targets. This is used before dist() |
||||
merge() |
||||
{ |
||||
if [ -d "darwin-x86_64_products" ]; then |
||||
rsync -a darwin-x86_64_products/ products/ |
||||
else |
||||
echo "Warning: darwin-x86_64_products is missing" |
||||
fi |
||||
# x86_64 64-bit linux |
||||
REMOTE_PRODUCTS_DIR=linux-x86_64_products |
||||
if [ -d "$REMOTE_PRODUCTS_DIR" ]; then |
||||
rsync -a $REMOTE_PRODUCTS_DIR/ products/ |
||||
echo "Merged products from " $REMOTE_PRODUCTS_DIR " to " products |
||||
else |
||||
echo "Warning: $REMOTE_PRODUCTS_DIR is missing" |
||||
fi |
||||
# armv7l linux |
||||
REMOTE_PRODUCTS_DIR=linux-armv7l_products |
||||
if [ -d "$REMOTE_PRODUCTS_DIR" ]; then |
||||
rsync -a $REMOTE_PRODUCTS_DIR/ products/ |
||||
echo "Merged products from " $REMOTE_PRODUCTS_DIR " to " products |
||||
else |
||||
echo "Warning: $REMOTE_PRODUCTS_DIR is missing" |
||||
fi |
||||
# armv6l linux |
||||
REMOTE_PRODUCTS_DIR=linux-armv6l_products |
||||
if [ -d "$REMOTE_PRODUCTS_DIR" ]; then |
||||
rsync -a $REMOTE_PRODUCTS_DIR/ products/ |
||||
echo "Merged products from " $REMOTE_PRODUCTS_DIR " to " products |
||||
else |
||||
echo "Warning: $REMOTE_PRODUCTS_DIR is missing" |
||||
fi |
||||
# 32/64-bit windows |
||||
REMOTE_PRODUCTS_DIR=win_products |
||||
if [ -d "$REMOTE_PRODUCTS_DIR" ]; then |
||||
rsync -a $REMOTE_PRODUCTS_DIR/ products/ |
||||
echo "Merged products from " $REMOTE_PRODUCTS_DIR " to " products |
||||
else |
||||
echo "Warning: $REMOTE_PRODUCTS_DIR is missing" |
||||
fi |
||||
} |
||||
|
||||
# On hosts which are not the final packaging platform (e.g. armv7, armv6l, etc) |
||||
# we will rename the products directory so that we can merge() it at a later |
||||
# stage on the packaging platform |
||||
wrap() |
||||
{ |
||||
ARCH_WRAP_DIR=$OSNAME"-"$(uname -m)_products |
||||
cp -rf lib $ARCH_WRAP_DIR |
||||
echo "Copied products to:" $ARCH_WRAP_DIR |
||||
PROD_FILENAME=$ARCH_WRAP_DIR.tar.gz |
||||
tar --exclude=$PROD_FILENAME -zcvf $PROD_FILENAME -C $ARCH_WRAP_DIR . |
||||
} |
||||
|
||||
# Renames and copies licenses for libzt and each of its dependencies |
||||
package_licenses() |
||||
{ |
||||
CURR_DIR=$1 |
||||
DEST_DIR=$2 |
||||
mkdir -p $DEST_DIR |
||||
cp $CURR_DIR/ext/lwip/COPYING $DEST_DIR/LWIP-LICENSE.BSD |
||||
cp $CURR_DIR/ext/concurrentqueue/LICENSE.md $DEST_DIR/CONCURRENTQUEUE-LICENSE.BSD |
||||
cp $CURR_DIR/LICENSE.txt $DEST_DIR/ZEROTIER-LICENSE.BSL-1.1 |
||||
cp $CURR_DIR/include/net/ROUTE_H-LICENSE.APSL $DEST_DIR/ROUTE_H-LICENSE.APSL |
||||
cp $CURR_DIR/include/net/ROUTE_H-LICENSE $DEST_DIR/ROUTE_H-LICENSE |
||||
} |
||||
|
||||
# Copies binaries, documentation, licenses, source, etc into a products |
||||
# directory and then tarballs everything together |
||||
package_everything() |
||||
{ |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
LIBZT_VERSION=$(git describe) |
||||
PROD_NAME=$LIBZT_VERSION-$(date '+%Y%m%d_%H-%M')-$1 |
||||
PROD_DIR=$(pwd)/products/$PROD_NAME/ |
||||
# Make products directory |
||||
# Licenses |
||||
package_licenses $(pwd) $PROD_DIR/licenses |
||||
# Examples |
||||
mkdir -p $PROD_DIR/examples |
||||
cp examples/cpp/* $PROD_DIR/examples |
||||
# Source |
||||
mkdir -p $PROD_DIR/src |
||||
cp src/*.cpp src/*.hpp src/*.c src/*.h $PROD_DIR/src |
||||
cp $(pwd)/README.pdf $PROD_DIR/README.pdf |
||||
# Header(s) |
||||
mkdir -p $PROD_DIR/include |
||||
cp $(pwd)/include/*.h $PROD_DIR/include |
||||
# Libraries |
||||
mkdir -p $PROD_DIR/lib |
||||
cp -r $(pwd)/products/$1/* $PROD_DIR/lib |
||||
rm -rf $(pwd)/products/$1 |
||||
# Clean |
||||
find $PROD_DIR -type f \( -name '*.DS_Store' -o -name 'thumbs.db' \) -delete |
||||
# Record the version (and each submodule's version) |
||||
echo "$(git describe)" > $PROD_DIR/VERSION |
||||
echo -e "$(git submodule status | awk '{$1=$1};1')" >> $PROD_DIR/VERSION |
||||
echo -e "$(cat ext/ZeroTierOne/version.h | grep ZEROTIER_ONE_VERSION | sed 's/\#define//g' | awk '{$1=$1};1')" >> $PROD_DIR/VERSION |
||||
echo "$(date)" >> $PROD_DIR/VERSION |
||||
# Tar everything |
||||
PROD_FILENAME=$(pwd)/products/$PROD_NAME.tar.gz |
||||
tar --exclude=$PROD_FILENAME -zcvf $PROD_FILENAME -C $PROD_DIR . |
||||
if [[ $OSNAME = *"darwin"* ]]; then |
||||
md5 $PROD_FILENAME |
||||
fi |
||||
if [[ $OSNAME = *"linux"* ]]; then |
||||
md5sum $PROD_FILENAME |
||||
fi |
||||
# Print results for post-build inspection |
||||
echo -e "\n" |
||||
tree $PROD_DIR |
||||
cat $PROD_DIR/VERSION |
||||
# Final check. Display warnings if anything is missing |
||||
FILES="VERSION |
||||
README.md |
||||
README.pdf |
||||
reference/errno.h |
||||
licenses/LWIP-LICENSE.BSD |
||||
licenses/CONCURRENTQUEUE-LICENSE.BSD |
||||
licenses/ZEROTIER-LICENSE.BSL-1.1 |
||||
licenses/ROUTE_H-LICENSE.APSL |
||||
licenses/ROUTE_H-LICENSE |
||||
licenses/LWIP-LICENSE.BSD" |
||||
for f in $FILES |
||||
do |
||||
if [ ! -f "$PROD_DIR$f" ]; then |
||||
echo "Warning: $PROD_DIR$f is missing" |
||||
fi |
||||
done |
||||
} |
||||
|
||||
# Generates a source-only tarball |
||||
sdist() |
||||
{ |
||||
VERSION=$(git describe --abbrev=0) |
||||
TARBALL_DIR="libzt-${VERSION}" |
||||
TARBALL_NAME=libzt-${VERSION}-source.tar.gz |
||||
PROD_DIR=$(pwd)/products/ |
||||
mkdir -p $PROD_DIR |
||||
# |
||||
mkdir ${TARBALL_DIR} |
||||
# primary sources |
||||
cp -rf src ${TARBALL_DIR}/src |
||||
cp -rf include ${TARBALL_DIR}/include |
||||
# important build scripts |
||||
cp Makefile ${TARBALL_DIR} |
||||
cp CMakeLists.txt ${TARBALL_DIR} |
||||
cp *.md ${TARBALL_DIR} |
||||
cp *.sh ${TARBALL_DIR} |
||||
cp *.bat ${TARBALL_DIR} |
||||
# submodules/dependencies |
||||
# lwIP |
||||
mkdir ${TARBALL_DIR}/ext |
||||
mkdir -p ${TARBALL_DIR}/ext/lwip/src |
||||
cp -rf ext/lwip/src/api ${TARBALL_DIR}/ext/lwip/src |
||||
cp -rf ext/lwip/src/core ${TARBALL_DIR}/ext/lwip/src |
||||
cp -rf ext/lwip/src/include ${TARBALL_DIR}/ext/lwip/src |
||||
cp -rf ext/lwip/src/netif ${TARBALL_DIR}/ext/lwip/src |
||||
# lwIP ports |
||||
mkdir -p ${TARBALL_DIR}/ext/lwip-contrib/ports |
||||
cp -rf ext/lwip-contrib/ports/unix ${TARBALL_DIR}/ext/lwip-contrib/ports |
||||
cp -rf ext/lwip-contrib/ports/win32 ${TARBALL_DIR}/ext/lwip-contrib/ports |
||||
# ZeroTierOne |
||||
mkdir ${TARBALL_DIR}/ext/ZeroTierOne |
||||
cp -rf ext/ZeroTierOne/*.h ${TARBALL_DIR}/ext/ZeroTierOne |
||||
cp -rf ext/ZeroTierOne/controller ${TARBALL_DIR}/ext/ZeroTierOne |
||||
cp -rf ext/ZeroTierOne/ext ${TARBALL_DIR}/ext/ZeroTierOne |
||||
cp -rf ext/ZeroTierOne/include ${TARBALL_DIR}/ext/ZeroTierOne |
||||
cp -rf ext/ZeroTierOne/node ${TARBALL_DIR}/ext/ZeroTierOne |
||||
cp -rf ext/ZeroTierOne/osdep ${TARBALL_DIR}/ext/ZeroTierOne |
||||
# |
||||
# Perform selective removal |
||||
rm -rf ${TARBALL_DIR}/ext/ZeroTierOne/ext/bin |
||||
rm -rf ${TARBALL_DIR}/ext/ZeroTierOne/ext/tap-mac |
||||
rm -rf ${TARBALL_DIR}/ext/ZeroTierOne/ext/librethinkdbxx |
||||
rm -rf ${TARBALL_DIR}/ext/ZeroTierOne/ext/installfiles |
||||
rm -rf ${TARBALL_DIR}/ext/ZeroTierOne/ext/curl-* |
||||
rm -rf ${TARBALL_DIR}/ext/ZeroTierOne/ext/http-parser |
||||
# |
||||
mkdir ${TARBALL_DIR}/ext/concurrentqueue |
||||
cp -rf ext/concurrentqueue/*.h ${TARBALL_DIR}/ext/concurrentqueue |
||||
# Licenses |
||||
package_licenses $(pwd) $TARBALL_DIR/licenses |
||||
# Tarball everything and display the results |
||||
tar -cvf ${TARBALL_NAME} ${TARBALL_DIR} |
||||
tree ${TARBALL_DIR} |
||||
rm -rf ${TARBALL_DIR} |
||||
mv ${TARBALL_NAME} ${PROD_DIR} |
||||
} |
||||
|
||||
# Package both debug and release |
||||
bdist() |
||||
{ |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
package_everything "debug" |
||||
package_everything "release" |
||||
} |
||||
|
||||
# Generate a markdown CHANGELOG from git-log |
||||
update_changelog() |
||||
{ |
||||
first_commit=$(git rev-list --max-parents=0 HEAD) |
||||
git for-each-ref --sort=-refname --format="## [%(refname:short)] - %(taggerdate:short) &(newline)*** &(newline)- %(subject) %(body)" refs/tags > CHANGELOG.md |
||||
gsed -i '''s/\&(newline)/\n/' CHANGELOG.md # replace first instance |
||||
gsed -i '''s/\&(newline)/\n/' CHANGELOG.md # replace second instance |
||||
echo -e "\n" >> CHANGELOG.md |
||||
for curr_tag in $(git tag -l --sort=-v:refname) |
||||
do |
||||
prev_tag=$(git describe --abbrev=0 ${curr_tag}^) |
||||
if [ -z "${prev_tag}" ] |
||||
then |
||||
prev_tag=${first_commit} |
||||
fi |
||||
echo "[${curr_tag}]: https://github.com/zerotier/libzt/compare/${prev_tag}..${curr_tag}" >> CHANGELOG.md |
||||
done |
||||
} |
||||
|
||||
# List all functions in this script (just for convenience) |
||||
list() |
||||
{ |
||||
IFS=$'\n' |
||||
for f in $(declare -F); do |
||||
echo "${f:11}" |
||||
done |
||||
} |
||||
|
||||
"$@" |
||||
@ -1,57 +1 @@
|
||||
Useful things to know |
||||
===== |
||||
|
||||
### IDENTITIES and AUTHORIZATION: |
||||
|
||||
Upon the first execution of this code, a new identity will be generated and placed in the location given in the first argument to zts_start(path, ...). If you accidentally duplicate the identity files and use them simultaneously in a different node instance **you will experience undefined behavior** and it is likely that nothing will work. |
||||
|
||||
You must authorize the node ID provided by the `ZTS_EVENT_NODE_ONLINE` callback to join your network, otherwise nothing will happen. This can be done manually or via our web API: https://my.zerotier.com/help/api |
||||
|
||||
An exception to the above rule is if you are using an Ad-hoc network, it has no controller and therefore requires no authorization. |
||||
|
||||
|
||||
### ESTABLISHING A CONNECTION: |
||||
|
||||
Creating a standard socket connection generally works the same as it would using an ordinary socket interface, however with libzt there is a subtle difference in how connections are established which may cause confusion: |
||||
|
||||
The underlying virtual ZT layer creates what are called "transport-triggered links" between nodes. That is, links are not established until an attempt to communicate with a peer has taken place. The side effect is that the first few packets sent from a libzt instance are usually relayed via our free infrastructure and it isn't until a root server has passed contact information to both peers that a direct connection will be established. Therefore, it is required that multiple connection attempts be undertaken when initially communicating with a peer. After a transport-triggered link is established libzt will inform you via `ZTS_EVENT_PEER_DIRECT` for a specific peer ID. No action is required on your part for this callback event. |
||||
|
||||
*Note: In these initial moments before `ZTS_EVENT_PEER_DIRECT` has been received for a specific peer, traffic may be slow, jittery and there may be high packet loss. This will subside within a couple of seconds.* |
||||
|
||||
|
||||
### ERROR HANDLING: |
||||
|
||||
libzt's API is actually composed of two categories of functions with slightly different error reporting mechanisms. |
||||
|
||||
- Category 1: Control functions (`zts_start`, `zts_join`, `zts_get_peer_status`, etc). Errors returned by these functions can be any of the following: |
||||
|
||||
``` |
||||
ZTS_ERR_OK // No error |
||||
ZTS_ERR_SOCKET // Socket error, see zts_errno |
||||
ZTS_ERR_SERVICE // You probably did something at the wrong time |
||||
ZTS_ERR_ARG // Invalid argument |
||||
ZTS_ERR_NO_RESULT // No result (not necessarily an error) |
||||
ZTS_ERR_GENERAL // Consider filing a bug report |
||||
``` |
||||
|
||||
- Category 2: Sockets (`zts_socket`, `zts_bind`, `zts_connect`, `zts_listen`, etc). Errors returned by these functions can be the same as the above. With the added possibility of `zts_errno` being set. Much like standard errno this will provide a more specific reason for an error's occurrence. See `ZeroTierSockets.h` for values. |
||||
|
||||
|
||||
### API COMPATIBILITY WITH HOST OS: |
||||
|
||||
While the ZeroTier socket interface can coexist with your host OS's own interface in the same file with no type and naming conflicts, try not to mix and match host OS/libzt structures, functions, or constants. It may look similar and may even work some of the time but there enough differences that it will cause headaches: |
||||
|
||||
If you are calling a `zts_*` function, use the appropriate `ZTS_*` constants: |
||||
|
||||
``` |
||||
zts_socket(ZTS_AF_INET6, ZTS_SOCK_DGRAM, 0); (CORRECT) |
||||
zts_socket(AF_INET6, SOCK_DGRAM, 0); (INCORRECT) |
||||
``` |
||||
|
||||
If you are calling a `zts_*` function, use the appropriate `zts_*` structure: |
||||
|
||||
``` |
||||
struct zts_sockaddr_in in4; <------ Note the zts_* prefix |
||||
... |
||||
zts_bind(fd, (struct zts_sockaddr *)&in4, sizeof(struct zts_sockaddr_in)) < 0) |
||||
``` |
||||
Please read the [Common pitfalls](../include/README.md#common-pitfalls) section in the C API reference documentation. |
||||
Loading…
Reference in new issue