Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Client] add swift client #178

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ backend/.env
/result-*
clients/haskell/result
clients/haskell/dist-newstyle
clients/swift/*.out
clients/swift/**/*/xcuserdata
# dev
bacon.toml
docker-compose/localstack/export_cyphers.sh
Expand All @@ -34,4 +36,4 @@ test_logs
.cargo
# pre-commit config
.pre-commit-config.yaml
.cargo
.cargo
25 changes: 25 additions & 0 deletions clients/swift/Config.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Config.xcconfig
// swift
//
// Created by naman agarwal on 03/08/24.
//

// Configuration settings file format documentation can be found at:
// https://help.apple.com/xcode/#/dev745c5c974

// Change env manually
// SUPERPOSITION_LIB_PATH=$(SRCROOT)/../../target/debug
// SUPERPOSITION_INCLUDE_PATH=$(SRCROOT)/../../headers

// Library Search Paths
LIBRARY_SEARCH_PATHS = $(inherited) $(SUPERPOSITION_LIB_PATH)

// Add your header search paths
HEADER_SEARCH_PATHS = $(inherited) $(SUPERPOSITION_INCLUDE_PATH)

// Linker Flags
OTHER_LDFLAGS = $(inherited) -lcac_client -lexperimentation_client

// Bridging Header
SWIFT_OBJC_BRIDGING_HEADER = $(SRCROOT)/swift/Bridging-Header.h
23 changes: 23 additions & 0 deletions clients/swift/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## CAC and Experimentation clients in `Swift`

- ## Walkthrough
- Create bridging file for each module
- add the `#include` statement for the C header file
- `using nix`: use `swiftc` to compile modules using `-L`, `-l`, `I` and `-import-objc-header` flags to specify object files search dir, object-module name, header search path and bridging file path respectively. (checkout : [default.nix](default.nix))
- `using xcode`: create a command-line project in xcode and configure `-L`, `-l` and `-import-objc-header` flags using `Build Settings` in the GUI. Settings equivalent for each compiler flags (checkout : [Config](Config.xcconfig))

- `-L` : `LIBRARY_SEARCH_PATHS`
- `-l` : `OTHER_LDFLAGS`
- `-import-objc-header` : `SWIFT_OBJC_BRIDGING_HEADER`
- `I` : `HEADER_SEARCH_PATHS`

- ## setup
- ### using nix :
1. cd to `clients/swift`
2. spawn devShell `nix develop .#swift`
3. run `compileTest`
4. use generated bins

- ### using xcode :
1. open project (`clients/swift`) in xcode
2. build & run the project
24 changes: 24 additions & 0 deletions clients/swift/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
perSystem = { config, pkgs, self', lib, ... }: {
devShells.swift = let
compileTest = pkgs.writeShellScriptBin "compileTest" ''
swiftc \
swift/main.swift swift/cac.swift swift/exp.swift swift/types.swift swift/utils.swift swift/test.swift \
-L$SUPERPOSITION_LIB_PATH \
-I$SUPERPOSITION_INCLUDE_PATH \
-lcac_client \
-lexperimentation_client \
-import-objc-header swift/Bridging-Header.h \
-o test_client.out
'';
in
pkgs.mkShell {
name = "superposition-swift-clients";
buildInputs = with pkgs; [
swift
swiftPackages.Foundation
compileTest
];
};
};
}
Loading