Skip to content
This repository has been archived by the owner on Sep 21, 2024. It is now read-only.

Commit

Permalink
chore: Provide a script to generate headers that uses codegen_units=1…
Browse files Browse the repository at this point in the history
… when building on macos to circumvent a header generation issue. Update CI and C makefile to use this script. Fixes #473
  • Loading branch information
jsantell committed Jul 10, 2023
1 parent f19fb4a commit 3785536
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 9 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/noosphere_apple_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ jobs:
brew: protobuf cmake
- name: 'Generate the header'
run: |
cd rust/noosphere/include/noosphere
cargo run --example generate_header --features headers --locked
cd -
scripts/generate_header
- uses: actions/upload-artifact@v3
with:
name: include
Expand Down
14 changes: 8 additions & 6 deletions c/example/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
LIBNOOSPHERE := ../../target/debug/deps/libnoosphere.a
HEADER := ../../target/headers/include/noosphere/noosphere.h
INCLUDE_PATH := ../../target/headers/include/noosphere

noosphere.h:
cargo run -p noosphere --example generate_header --features headers
$(HEADER):
../../scripts/generate_headers
$(LIBNOOSPHERE):
cargo build -p noosphere
main.o: noosphere.h
$(CC) -c main.c
main.o: $(HEADER)
$(CC) -I$(INCLUDE_PATH) -c main.c
main.out: main.o $(LIBNOOSPHERE)
$(CC) main.o $(LIBNOOSPHERE) -lm -o main.out
$(CC) $(LIBNOOSPHERE) -I$(INCLUDE_PATH) main.o -lm -o main.out

.PHONY: build run clean

Expand All @@ -16,4 +18,4 @@ build: main.out
run: main.out
./main.out
clean:
rm -rf noosphere.h main.o main.out
rm -rf $(HEADER) main.o main.out
27 changes: 27 additions & 0 deletions scripts/generate_headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -e
set -x

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
PROJECT_DIR="$SCRIPT_DIR/../"

pushd $PROJECT_DIR

rm -rf ./target/headers
mkdir -p ./target/headers
cp -r ./rust/noosphere/include ./target/headers/

if [[ "$OSTYPE" == "darwin"* ]]; then
# macos linker fails to generate all exports without this flag
# https://github.com/subconsciousnetwork/noosphere/issues/473
CARGO_PROFILE_DEV_CODEGEN_UNITS=1 cargo run --verbose --package noosphere --example generate_header --features headers --locked
else
cargo run --verbose --package noosphere --example generate_header --features headers --locked
fi

mv ./noosphere.h ./target/headers/include/noosphere/noosphere.h

popd

set +x
set +e
53 changes: 53 additions & 0 deletions scripts/xcode_local_build
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
set -e
set -x

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
PROJECT_DIR="$SCRIPT_DIR/../"

pushd $PROJECT_DIR

rm -rf ./LibNoosphere.xcframework

$SCRIPT_DIR/generate_headers

TARGETS=(
"aarch64-apple-ios"
"x86_64-apple-ios"
"aarch64-apple-ios-sim"
"x86_64-apple-darwin"
"aarch64-apple-darwin"
)

for TARGET in "${TARGETS[@]}"; do
rustup target install $TARGET
cargo build --package noosphere --release --target $TARGET --locked
# cargo build --package noosphert buie --target $TARGET --locked
done

mkdir -p ./target/macos
mkdir -p ./target/simulator

lipo -create \
./target/x86_64-apple-darwin/release/libnoosphere.a \
./target/aarch64-apple-darwin/release/libnoosphere.a \
-output ./target/macos/libnoosphere.a

lipo -create \
./target/x86_64-apple-ios/release/libnoosphere.a \
./target/aarch64-apple-ios-sim/release/libnoosphere.a \
-output ./target/simulator/libnoosphere.a

xcodebuild -create-xcframework \
-library ./target/macos/libnoosphere.a \
-headers ./target/headers/include/ \
-library ./target/simulator/libnoosphere.a \
-headers ./target/headers/include/ \
-library ./target/aarch64-apple-ios/release/libnoosphere.a \
-headers ./target/headers/include/ \
-output ./LibNoosphere.xcframework

popd

set +x
set +e

0 comments on commit 3785536

Please sign in to comment.