Build burrow library into iOS and macOS app
This commit adds a build script, build-rust.sh, which compiles the burrow crate from inside of Xcode. The network extension then links against this crate.
This commit is contained in:
parent
d966c0ff77
commit
4b0965b846
7 changed files with 129 additions and 4 deletions
13
.github/workflows/build-apple.yml
vendored
13
.github/workflows/build-apple.yml
vendored
|
|
@ -18,14 +18,22 @@ jobs:
|
||||||
destination: generic/platform=iOS
|
destination: generic/platform=iOS
|
||||||
platform: iOS
|
platform: iOS
|
||||||
sdk-name: iphoneos
|
sdk-name: iphoneos
|
||||||
|
rust-targets:
|
||||||
|
- aarch64-apple-ios
|
||||||
- scheme: Burrow
|
- scheme: Burrow
|
||||||
destination: platform=iOS Simulator,OS=16.2,name=iPhone 14 Pro
|
destination: platform=iOS Simulator,OS=16.2,name=iPhone 14 Pro
|
||||||
platform: iOS Simulator
|
platform: iOS Simulator
|
||||||
sdk-name: iphonesimulator
|
sdk-name: iphonesimulator
|
||||||
|
rust-targets:
|
||||||
|
- aarch64-apple-ios-sim
|
||||||
|
- x86_64-apple-ios
|
||||||
- scheme: Burrow
|
- scheme: Burrow
|
||||||
destination: platform=macOS
|
destination: platform=macOS
|
||||||
platform: macOS
|
platform: macOS
|
||||||
sdk-name: macos
|
sdk-name: macos
|
||||||
|
rust-targets:
|
||||||
|
- x86_64-apple-darwin
|
||||||
|
- aarch64-apple-darwin
|
||||||
env:
|
env:
|
||||||
DEVELOPER_DIR: /Applications/Xcode_14.2.app/Contents/Developer
|
DEVELOPER_DIR: /Applications/Xcode_14.2.app/Contents/Developer
|
||||||
steps:
|
steps:
|
||||||
|
|
@ -39,6 +47,11 @@ jobs:
|
||||||
with:
|
with:
|
||||||
certificate: ${{ secrets.DEVELOPER_CERT }}
|
certificate: ${{ secrets.DEVELOPER_CERT }}
|
||||||
password: ${{ secrets.DEVELOPER_CERT_PASSWORD }}
|
password: ${{ secrets.DEVELOPER_CERT_PASSWORD }}
|
||||||
|
- name: Install Rust
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
targets: ${{ join(matrix.rust-targets, ', ') }}
|
||||||
- name: Build
|
- name: Build
|
||||||
id: build
|
id: build
|
||||||
uses: ./.github/actions/build-for-testing
|
uses: ./.github/actions/build-for-testing
|
||||||
|
|
|
||||||
2
.github/workflows/build-rust.yml
vendored
2
.github/workflows/build-rust.yml
vendored
|
|
@ -50,7 +50,7 @@ jobs:
|
||||||
shell: bash
|
shell: bash
|
||||||
run: sudo apt-get install -y ${{ join(matrix.packages, ' ') }}
|
run: sudo apt-get install -y ${{ join(matrix.packages, ' ') }}
|
||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
uses: dtolnay/rust-toolchain@master
|
uses: dtolnay/rust-toolchain@stable
|
||||||
with:
|
with:
|
||||||
toolchain: stable
|
toolchain: stable
|
||||||
components: rustfmt
|
components: rustfmt
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
D05B9F7629E39EEC008CB1F9 /* BurrowApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D05B9F7529E39EEC008CB1F9 /* BurrowApp.swift */; };
|
D05B9F7629E39EEC008CB1F9 /* BurrowApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D05B9F7529E39EEC008CB1F9 /* BurrowApp.swift */; };
|
||||||
D05B9F7829E39EEC008CB1F9 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D05B9F7729E39EEC008CB1F9 /* ContentView.swift */; };
|
D05B9F7829E39EEC008CB1F9 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D05B9F7729E39EEC008CB1F9 /* ContentView.swift */; };
|
||||||
D05B9F7A29E39EED008CB1F9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D05B9F7929E39EED008CB1F9 /* Assets.xcassets */; };
|
D05B9F7A29E39EED008CB1F9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D05B9F7929E39EED008CB1F9 /* Assets.xcassets */; };
|
||||||
|
D0B98FC529FDA49E004E7149 /* libburrow.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D0B98FC429FDA476004E7149 /* libburrow.a */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
|
|
@ -57,6 +58,8 @@
|
||||||
D05B9F7529E39EEC008CB1F9 /* BurrowApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BurrowApp.swift; sourceTree = "<group>"; };
|
D05B9F7529E39EEC008CB1F9 /* BurrowApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BurrowApp.swift; sourceTree = "<group>"; };
|
||||||
D05B9F7729E39EEC008CB1F9 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
|
D05B9F7729E39EEC008CB1F9 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
|
||||||
D05B9F7929E39EED008CB1F9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
D05B9F7929E39EED008CB1F9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||||
|
D0B98FBF29FD8072004E7149 /* build-rust.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "build-rust.sh"; sourceTree = "<group>"; };
|
||||||
|
D0B98FC429FDA476004E7149 /* libburrow.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libburrow.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
|
|
@ -64,6 +67,7 @@
|
||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
D0B98FC529FDA49E004E7149 /* libburrow.a in Frameworks */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
|
@ -84,6 +88,7 @@
|
||||||
D020F64A29E4A452002790F6 /* App.xcconfig */,
|
D020F64A29E4A452002790F6 /* App.xcconfig */,
|
||||||
D020F66329E4A703002790F6 /* Extension.xcconfig */,
|
D020F66329E4A703002790F6 /* Extension.xcconfig */,
|
||||||
D020F64029E4A1FF002790F6 /* Compiler.xcconfig */,
|
D020F64029E4A1FF002790F6 /* Compiler.xcconfig */,
|
||||||
|
D0B98FBF29FD8072004E7149 /* build-rust.sh */,
|
||||||
D020F64229E4A1FF002790F6 /* Info.plist */,
|
D020F64229E4A1FF002790F6 /* Info.plist */,
|
||||||
);
|
);
|
||||||
path = Configuration;
|
path = Configuration;
|
||||||
|
|
@ -108,6 +113,7 @@
|
||||||
D020F65629E4A697002790F6 /* NetworkExtension */,
|
D020F65629E4A697002790F6 /* NetworkExtension */,
|
||||||
D020F63C29E4A1FF002790F6 /* Configuration */,
|
D020F63C29E4A1FF002790F6 /* Configuration */,
|
||||||
D05B9F7329E39EEC008CB1F9 /* Products */,
|
D05B9F7329E39EEC008CB1F9 /* Products */,
|
||||||
|
D0B98FC129FDA45D004E7149 /* Frameworks */,
|
||||||
);
|
);
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
|
@ -133,6 +139,14 @@
|
||||||
path = App;
|
path = App;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
D0B98FC129FDA45D004E7149 /* Frameworks */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
D0B98FC429FDA476004E7149 /* libburrow.a */,
|
||||||
|
);
|
||||||
|
name = Frameworks;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
/* End PBXGroup section */
|
/* End PBXGroup section */
|
||||||
|
|
||||||
/* Begin PBXNativeTarget section */
|
/* Begin PBXNativeTarget section */
|
||||||
|
|
@ -140,6 +154,7 @@
|
||||||
isa = PBXNativeTarget;
|
isa = PBXNativeTarget;
|
||||||
buildConfigurationList = D020F65E29E4A697002790F6 /* Build configuration list for PBXNativeTarget "NetworkExtension" */;
|
buildConfigurationList = D020F65E29E4A697002790F6 /* Build configuration list for PBXNativeTarget "NetworkExtension" */;
|
||||||
buildPhases = (
|
buildPhases = (
|
||||||
|
D0B98FC029FD809A004E7149 /* Compile Rust */,
|
||||||
D020F64F29E4A697002790F6 /* Sources */,
|
D020F64F29E4A697002790F6 /* Sources */,
|
||||||
D020F65029E4A697002790F6 /* Frameworks */,
|
D020F65029E4A697002790F6 /* Frameworks */,
|
||||||
D020F65129E4A697002790F6 /* Resources */,
|
D020F65129E4A697002790F6 /* Resources */,
|
||||||
|
|
@ -227,6 +242,30 @@
|
||||||
};
|
};
|
||||||
/* End PBXResourcesBuildPhase section */
|
/* End PBXResourcesBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin PBXShellScriptBuildPhase section */
|
||||||
|
D0B98FC029FD809A004E7149 /* Compile Rust */ = {
|
||||||
|
isa = PBXShellScriptBuildPhase;
|
||||||
|
alwaysOutOfDate = 1;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
);
|
||||||
|
inputFileListPaths = (
|
||||||
|
);
|
||||||
|
inputPaths = (
|
||||||
|
);
|
||||||
|
name = "Compile Rust";
|
||||||
|
outputFileListPaths = (
|
||||||
|
);
|
||||||
|
outputPaths = (
|
||||||
|
"$(BUILT_PRODUCTS_DIR)/libburrow.a",
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
shellPath = /bin/sh;
|
||||||
|
shellScript = "\"${PROJECT_DIR}/Configuration/build-rust.sh\"\n";
|
||||||
|
showEnvVarsInLog = 0;
|
||||||
|
};
|
||||||
|
/* End PBXShellScriptBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXSourcesBuildPhase section */
|
/* Begin PBXSourcesBuildPhase section */
|
||||||
D020F64F29E4A697002790F6 /* Sources */ = {
|
D020F64F29E4A697002790F6 /* Sources */ = {
|
||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
|
|
|
||||||
69
Apple/Configuration/build-rust.sh
Executable file
69
Apple/Configuration/build-rust.sh
Executable file
|
|
@ -0,0 +1,69 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
export PATH="${PATH}:${HOME}/.cargo/bin:/opt/homebrew/bin:/usr/local/bin:/etc/profiles/per-user/${USER}/bin"
|
||||||
|
|
||||||
|
if ! [[ -x "$(command -v cargo)" ]]; then
|
||||||
|
echo 'error: Unable to find cargo'
|
||||||
|
exit 127
|
||||||
|
fi
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd -- "$(dirname -- "${BASH_SOURCE[0]}")"/../../burrow
|
||||||
|
|
||||||
|
RUST_TARGETS=()
|
||||||
|
|
||||||
|
IFS=' ' read -a BURROW_ARCHS <<< "${ARCHS[@]}"
|
||||||
|
for ARCH in "${BURROW_ARCHS[@]}"; do
|
||||||
|
case $PLATFORM_NAME in
|
||||||
|
iphonesimulator)
|
||||||
|
case $ARCH in
|
||||||
|
arm64) RUST_TARGETS+=("aarch64-apple-ios-sim") ;;
|
||||||
|
x86_64) RUST_TARGETS+=("x86_64-apple-ios") ;;
|
||||||
|
*) echo "error: Unknown $PLATFORM_NAME arch, $ARCH"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
iphoneos)
|
||||||
|
case $ARCH in
|
||||||
|
arm64) RUST_TARGETS+=("aarch64-apple-ios") ;;
|
||||||
|
*) echo "error: Unknown $PLATFORM_NAME arch, $ARCH"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
macos*)
|
||||||
|
case $ARCH in
|
||||||
|
arm64) RUST_TARGETS+=("aarch64-apple-darwin") ;;
|
||||||
|
x86_64) RUST_TARGETS+=("x86_64-apple-darwin") ;;
|
||||||
|
*) echo "error: Unknown $PLATFORM_NAME arch, $ARCH"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
*) echo "error: Unsupported platform $PLATFORM_NAME"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
CARGO_ARGS=()
|
||||||
|
for TARGET in "${RUST_TARGETS[@]}"; do
|
||||||
|
CARGO_ARGS+=("--target")
|
||||||
|
CARGO_ARGS+=("$TARGET")
|
||||||
|
done
|
||||||
|
|
||||||
|
CARGO_ARGS+=("--lib")
|
||||||
|
|
||||||
|
if [[ $SWIFT_ACTIVE_COMPILATION_CONDITIONS == *DEBUG* ]]; then
|
||||||
|
CARGO_DIR="debug"
|
||||||
|
else
|
||||||
|
CARGO_ARGS+=("--release")
|
||||||
|
CARGO_DIR="release"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -x "$(command -v rustup)" ]]; then
|
||||||
|
CARGO_PATH="$(dirname $(rustup which cargo)):/usr/bin"
|
||||||
|
else
|
||||||
|
CARGO_PATH="$(dirname $(readlink -f $(which cargo))):/usr/bin"
|
||||||
|
fi
|
||||||
|
|
||||||
|
env -i PATH="$CARGO_PATH" cargo build "${CARGO_ARGS[@]}"
|
||||||
|
|
||||||
|
mkdir -p "${BUILT_PRODUCTS_DIR}"
|
||||||
|
/usr/bin/xcrun --sdk $PLATFORM_NAME lipo \
|
||||||
|
-create $(printf "${PROJECT_DIR}/../target/%q/${CARGO_DIR}/libburrow.a " "${RUST_TARGETS[@]}") \
|
||||||
|
-output "${BUILT_PRODUCTS_DIR}/libburrow.a"
|
||||||
|
|
@ -3,7 +3,8 @@ name = "burrow"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
[lib]
|
||||||
|
crate-type = ["lib", "staticlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = { version = "1.21", features = ["rt", "macros"] }
|
tokio = { version = "1.21", features = ["rt", "macros"] }
|
||||||
|
|
|
||||||
3
burrow/src/lib.rs
Normal file
3
burrow/src/lib.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
pub fn hello_world() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use tokio::io::Result;
|
use tokio::io::Result;
|
||||||
use tun::TunInterface;
|
use tun::TunInterface;
|
||||||
|
|
||||||
async fn lol() -> Result<()> {
|
async fn try_main() -> Result<()> {
|
||||||
let iface = TunInterface::new()?;
|
let iface = TunInterface::new()?;
|
||||||
println!("{:?}", iface.name());
|
println!("{:?}", iface.name());
|
||||||
|
|
||||||
|
|
@ -10,5 +10,5 @@ async fn lol() -> Result<()> {
|
||||||
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
lol().await.unwrap();
|
try_main().await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue