Replies: 1 comment 1 reply
-
|
Waiting for the: "For Desktop Platforms" 🙏 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Introduction
Outline SDK is a powerful Go1 library that can be used to build cross-platform VPN applications. However, getting started with the cross platform compilation can be a bit tricky, especially if you are new to Go.
This guide walks you through the process of setting up your Go environment and using the Outline SDK. It also covers how to create Go libraries that can be used on a variety of platforms, including Android, iOS/macOS, Windows and Linux.
If you have any questions about the environment setup, please feel free to post them here or in a new discussion thread.
Set up Go1
This section describes how to install Go. After your environment is set up, you will be able to create an executable that splits TCP streams into two streams: The first stream contains the first 3 bytes, and the second stream contains the rest of the data. You will be using the Outline SDK to create this executable.
Install Go
You can follow the official installation guide at https://go.dev/doc/install 2. Alternatively, if you are using a package manager, you can also use it to install Go:
macOS Homebrew
3
Windows WinGet
4
Ubuntu apt
5
After Go is installed, you can verify that it is installed correctly by running the following command (make sure the version is ≥
1.20):If you want to learn some basic Go syntax, "A Tour of Go"6 is a great online tool.
Create
splitfetchApplicationThis section describes how to create a cross-platform
split-fetcherapplication that will fetch a page using HTTP/HTTPS protocol. Instead of sending the entire request in a single network packet, it will split it into two packets. This helps the app to circumvent deep-packet inspection 7. This application will run on desktop platforms. For mobile usage, see the following sections.To set up the
splitfetchproject, follow these steps:Details
go.modandgo.sumfile to this folder):mkdir splitfetch cd splitfetch go mod init local/example/splitfetch go get github.com/Jigsaw-Code/outline-sdk@latestfetcher.goandmain/main.go.fetcher.gowill include a helper function that fetches a page using Outline SDK'ssplit.NewStreamDialer. This function will be used bymain.go, which is the entrypoint of the application:Then, use your favorite code editor8 to paste the code below into
fetcher.goandmain/main.go:fetcher.go
main/main.go
After you have copied the code into the files, you can run
go mod tidyto update thego.modfile.Run
splitfetchApplicationYou can now run the
splitfetchapplication by:This will compile and run the application. If you want to create a distributable binary, you can use the
go buildcommand:Windows
macOS or Linux
Create a Go library
In some cases, it is more desirable to use the
splitfetch.FetchPageas a library rather than a standalone executable binary. For example, when developing an Android app.This section describes the process of creating a reusable library for
splitfetch.FetchPage. It demonstrates how to build this library for different platforms that can be readily integrated into your applications.Mobile Platforms
This tutorial uses Go Mobile9 to create the library for Android and iOS/macOS. First, you will need to install the
gomobilecommand line tool 10 using the following command:By default, it will be installed to the
"$(go env GOPATH)/bin"folder (typically it expands to"$HOME/go/bin"on Linux/macOS, or"%HOMEPATH%\go\bin"on Windows). You can override this location byexport GOBIN="<customized-bin-folder>"before running thego installcommand.You must also add the bin folder mentioned above to the
PATHenvironment variable, becausegomobilewill try to install and discover some additional command line tools:Linux/macOS
Windows (PowerShell)
After you have completed these steps, you can initialize the
gomobilecommand line tools 10:Build Android Library
To build an Android library (AAR, Android Archive) for the
FetchPagefunction, you need to install the Android SDK (API Level 18+) and JDK (8+). We recommend installing the latest Android Studio 11, which includes both of these requirements.After you have installed Android Studio, check that JDK is installed correctly by running
javac --versionin the terminal. If you see any errors, install the JDK from a vendor such as Oracle12 or OpenJDK13. It is also usually available in package managers such as brew14, WinGet15, and apt16.You must also set the
ANDROID_HOMEenvironment variable to the location of your Android SDK. You can find this location in Android Studio 17:You can now build the Android library using the following commands (for more
gomobileoptions, see their documentation 18):To use this library in your Android app, follow these steps:
splitfetch.aarfile into your project 20.FetchPagefunction:Build iOS/macOS Library
To create an XCFramework bundle 23 for the
FetchPagefunction, you need a macOS machine with Xcode24 installed. After Xcode24 is installed, you can build the XCFramework bundle using the following command (for moregomobileoptions, see their documentation 18):To use this multiplatform XCFramework library in your iOS or macOS app, you must first create a Swift Package 25 for the binary 26. To do this:
Package.swiftfile:Product > Buildthis project to make sure everything is good.Next, close the package project. The steps below create an app to use the package:
File > Add Packages... > Add Local... > choose "SplitFetchLib" folder > Add Package27.select project in the left nav pane > under "TARGETS", select project > General Pane > Frameworks, Libraries, and Embedded Content > + > select the leaf node of "SplitFetchLib" > Add.Outgoing Connections (Client)checkbox on theSigning & Capabilitiespage of the project. 2829FetchPagefunction:Product > Buildto make sure everything is good. If you get any errors, double-check step 2 and step 3 above. SometimesFile > Packages > Reset Package CachesandProduct > Clean Build Foldermight also help.For Desktop Platforms
The best way to consume this package on desktop platforms such as Linux and Windows is to use Go directly (you can even write GUIs in Go 31). However, if this is not possible (for example, if you have an existing application written in another language, or if you are creating an embedded application), you can still create a C library using
cgo3233. The C library is a glue that can be used to connect different programming languages together 34353637. You need to install a native C/C++ compiler on your platform before usingcgo. For example, on Linux you need to installgcc/g++3839, on Windows you need to install MinGW-w64 4041 (MSVC is not currently supported 42), and on macOS you need to install Xcode 24.To compile this package to a C library, you need to add another main package that defines C-compatible functions (you can be more creative than us when defining the parameters and return type of the functions, see more in
cgodocumentation 33):clib/main.go
After you have completed these steps, you will be able to build it into a C shared library:
Linux/macOS
Windows (PowerShell)
After running the previous command, you will have two files in the
libfolder: a shared library binary (for example,splitfetch.so/splitfetch.dll) and a header file (splitfetch.h).Use the shared library (C/C++)
This section creates a native C++ application to demonstrate how to use this shared library. Create a new folder and copy both files (i.e.
splitfetch.so/splitfetch.dllandsplitfetch.h) into it. Then create a C file calledmain.cppin this folder.main.cpp
To compile and link the C++ code with the shared library, and run the final executable file (it's important to make sure that the shared library and the executable file are in the same folder):
Linux/macOS
Windows (PowerShell)
# make sure g++.exe is available through environment variable g++ -o fetching main.cpp splitfetch.dll ./fetching.exeUse the shared library (C#)
This section demonstrates how to use this shared library in C#. First, you will need to have the .NET SDK 45 installed on your system. Then you can create, build and run your C# application:
Program.cs
Footnotes
Footnotes
The Go Programming Language ↩ ↩2
Download and Install Go ↩
Homebrew: go ↩
WinGet: Golang.Go.1.20 ↩
Install Go on Ubuntu ↩
A Tour of Go ↩
New Feature: Packet Splitting ↩
Go Editors and IDEs ↩
Go Mobile ↩
gomobileCLI ↩ ↩2Install Android Studio ↩
Oracle JDK 21 ↩
Open JDK 21 ↩
brew install openjdk↩WinGet Oracle JDK 17 ↩
apt install default-jdk↩Find Android SDK Location ↩
gomobileBuild a library for Android and iOS ↩ ↩2Go Modules: how can I track tool dependencies for a module ↩ ↩2
Android Studio: add AAR or JAR as a dependency ↩
Android Studio: declaring app permissions ↩
Network permissions for Android app ↩
Apple: multiplatform binary framework bundle ↩
Xcode on the Mac App Store ↩ ↩2 ↩3
Creating a standalone Swift package with Xcode ↩
Distributing binary frameworks as Swift packages ↩
Adding package dependencies to your app ↩
Adding capabilities to your app ↩
Configuring the macOS App Sandbox ↩
Calling Go code from Swift on iOS and vice versa with Gomobile ↩
A list of Go GUI projects ↩
C? Go? Cgo! ↩
cgo command ↩ ↩2
NodeJS: C++ addons ↩
C#: Platform Invoke ↩
Extending Python with C or C++ ↩
Java: Guide to JNI ↩
Installing GCC ↩
How to Install GCC Compiler on Ubuntu ↩
MinGW-w64 Downloads ↩
MSYS2 ↩
Go cmd/link: support msvc object files ↩
LLVM/Clang ↩
Cross compiling made easy, using Clang and LLVM ↩
Install .NET on Windows, Linux, and macOS ↩
Beta Was this translation helpful? Give feedback.
All reactions