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

Enhance Package.swift for local framework support and update README w… #29

Open
wants to merge 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/.swiftpm
/.build
MapLibre.dynamic.xcframework.zip
26 changes: 20 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
// swift-tools-version:5.3

import PackageDescription
import Foundation

let binaryTarget: Target
let useLocalFramework = ProcessInfo.processInfo.environment["USE_MAPLIBRE_LOCAL_FRAMEWORK"] != nil

if useLocalFramework {
binaryTarget = .binaryTarget(
name: "MapLibre",
path: "MapLibre.dynamic.xcframework.zip"
)
} else {
binaryTarget = .binaryTarget(
name: "MapLibre",
url: "https://github.com/maplibre/maplibre-native/releases/download/ios-v6.8.1/MapLibre.dynamic.xcframework.zip",
checksum: "7f7123f33ac8a7c134135b2c15bb973f046561db9dc445220f28530f1b0ac028"
)
}

let package = Package(
name: "MapLibre Native",
Expand All @@ -8,12 +26,8 @@ let package = Package(
name: "MapLibre",
targets: ["MapLibre"])
],
dependencies: [
],
dependencies: [],
targets: [
.binaryTarget(
name: "MapLibre",
url: "https://github.com/maplibre/maplibre-native/releases/download/ios-v6.8.1/MapLibre.dynamic.xcframework.zip",
checksum: "7f7123f33ac8a7c134135b2c15bb973f046561db9dc445220f28530f1b0ac028")
binaryTarget
]
)
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,34 @@ When you download this repo there is a Swift Playground that allows you to chang
* Navigate to the folder where you `clone`d, and open `Package.swift` in at least Xcode 12.
* Run Playground by choosing `Editor` > `Run Playground` or `⇧-⌘-⏎`
* See issue [maplibre-gl-native-distribution#8](https://github.com/maplibre/maplibre-gl-native-distribution/issues/8) for screenshots of the MapLibre for Swift Playgrounds in action.

## Local Development Guide

### Building and Using Local Framework

1. Clone the maplibre-native repository:
```bash
git clone https://github.com/maplibre/maplibre-native.git
```

2. Build the framework using our build script:
```bash
MAPLIBRE_DIR="/path/to/maplibre-native" ./scripts/build_maplibre.sh
```

This script will:
- Build the framework using Bazel
- Move the built framework to this repository
- Configure your environment to use the local framework

### Switching Between Local and Remote Framework

- To use local framework: `export USE_MAPLIBRE_LOCAL_FRAMEWORK=1`
- To use remote framework: `unset USE_MAPLIBRE_LOCAL_FRAMEWORK`

### Troubleshooting

If you encounter issues:
1. Ensure your Bazel build succeeds in maplibre-native
2. Check that the framework was copied to the correct location
3. Verify your environment variable is set correctly with `echo $USE_MAPLIBRE_LOCAL_FRAMEWORK`
77 changes: 77 additions & 0 deletions scripts/build_maplibre.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

ENV_VAR_NAME="USE_MAPLIBRE_LOCAL_FRAMEWORK"

verify_env_var() {
echo "Verifying environment variable setup..."

# Check current shell
if [ -z "${!ENV_VAR_NAME}" ]; then
echo -e "${RED}${ENV_VAR_NAME} not set in current shell${NC}"
else
echo -e "${GREEN}${ENV_VAR_NAME} set in current shell: ${!ENV_VAR_NAME}${NC}"
fi

# Check zshrc
if grep -q "export ${ENV_VAR_NAME}=1" ~/.zshrc; then
echo -e "${GREEN}${ENV_VAR_NAME} export found in ~/.zshrc${NC}"
else
echo -e "${RED}${ENV_VAR_NAME} export not found in ~/.zshrc${NC}"
fi

# Check launchctl
LAUNCH_VAL=$(launchctl getenv ${ENV_VAR_NAME})
if [ -z "$LAUNCH_VAL" ]; then
echo -e "${RED}${ENV_VAR_NAME} not set in launchctl${NC}"
else
echo -e "${GREEN}${ENV_VAR_NAME} set in launchctl: $LAUNCH_VAL${NC}"
fi
}

echo -e "${GREEN}MapLibre iOS Framework Builder${NC}"
echo "----------------------------------------"

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"

echo "Building MapLibre framework..."
cd "$MAPLIBRE_DIR" || exit 1

if ! bazel build --compilation_mode=opt //platform/ios:MapLibre.dynamic; then
echo -e "${RED}Build failed!${NC}"
exit 1
fi

EXECUTION_ROOT=$(bazel info execution_root)
SOURCE_PATH="${EXECUTION_ROOT}/bazel-out/darwin_arm64-opt/bin/platform/ios/MapLibre.dynamic.xcframework.zip"
DEST_PATH="${REPO_ROOT}/MapLibre.dynamic.xcframework.zip"

echo "Copying framework to destination..."
if cp -f "$SOURCE_PATH" "$DEST_PATH"; then
echo -e "${GREEN}Successfully copied framework to:${NC}"
echo "$DEST_PATH"

# Add to zshrc if not already there
if ! grep -q "export ${ENV_VAR_NAME}=1" ~/.zshrc; then
echo "export ${ENV_VAR_NAME}=1" >> ~/.zshrc
fi

# Set for current shell
export ${ENV_VAR_NAME}=1

# Add to launchctl for system-wide availability
launchctl setenv ${ENV_VAR_NAME} 1

echo -e "${GREEN}Framework copied and environment configured system-wide!${NC}"
echo -e "${YELLOW}Please restart Xcode to pick up the environment changes.${NC}"
else
echo -e "${RED}Failed to copy framework to destination!${NC}"
exit 1
fi

verify_env_var