Build Error (iOS)

Good morning everyone.

I am guessing that I have done something wrong here, but before I spend a bunch of time trying to figure out what that might be, I thought I would ask. I figure someone else might have done the same thing at some point.

I have set up my environment to build the CZiti framework on my Mac. To that end, I have done the following, which someone else might find useful:

Install the code for CZiti

The most important part here is the --recurse-submodules as this will ensure all of the components in the SDK are actually present in your local repo. Just issue the following command from the directory you want to store your copy of the Ziti SDK source.

git clone --recurse-submodules https://github.com/openziti/ziti-sdk-swift.git

Install the required dependencies

xcpretty - Depending on which Ruby you are using on your Mac you might need to use sudo to install the gem.

(sudo) gem install xcpretty

cmake - If you do not have Homebrew installed on your Mac, it is highly recommended and makes installing dependencies like this much easier. You can find instructions for installing Homebrew here.

brew install cmake

pkg-config - I had not seen a requirement for this but ran into issues with vcpkg without it, so you will want to install it as well.

brew install pkg-config

vcpkg - Finally, you need to follow the directions in ./deps/ziti-tunnel-sdk-c/build-macosx-x86_64, but the basics are to switch to where you would like to store the vcpkg repository, which includes the scripts/components necessary to build the Ziti SDK. Then issue the following command.

git clone https://github.com/microsoft/vcpkg

You need to set an environment variable that points to the vcpkg directory, so that the build script can find the necessary scripts/components. In my case, that looked like this:

export VCPKG_ROOT=$HOME/Projects/ZPN/ziti-sdk-swift/vcpkg

Run the bootstrap command.

cd vcpkg
./bootstrap-vcpkg.sh

Build the SDK

We are ready to build the SDK.

./build_all.sh

or for a Debug version you can use:

CONFIGURATION=Debug ./build_all.sh

My Build Problem
In my case, the build progressed until it failed with the following error:

.../ziti-sdk-swift/deps/ziti-tunnel-sdk-c/lib/ziti-tunnel-cbs/dns_host.c:245:45: error: incompatible function pointer types passing 'ssize_t (ziti_connection, uint8_t *, ssize_t)' (aka 'long (struct ziti_conn *, unsigned char *, long)') to parameter of type 'ziti_data_cb' (aka 'long (*)(struct ziti_conn *, const unsigned char *, long)') [-Wincompatible-function-pointer-types]
        ziti_accept(conn, on_conn_complete, on_dns_req);
.../ziti-sdk-swift/deps/ziti-tunnel-sdk-c/build-iphoneos-arm64/_deps/ziti-sdk-c-src/library/../includes/ziti/ziti.h:761:75: note: passing argument to parameter 'data_cb' here
extern int ziti_accept(ziti_connection clt, ziti_conn_cb cb, ziti_data_cb data_cb);

Potential Solution
Looking at this function, the on_dns_req signature is missing the const keyword for the data argument. As this:

  1. Function is only used in the ziti_accept call,
  2. The on_dns_req function is only used in this file
  3. The data pointer is used only once in the function
  4. The data pointer is cast to a (const char *) prior to use

It seems reasonable to alter the on_dns_req signature to match the ziti_data_cb signature by adding the const to the argument. That does appear to resolve the build issue. For the reasons above, I don't think this change impacts the runtime usage of the function, but others would have a better idea about this.

My Confusion
I am not sure why this isn't an issue for, well everyone. When I went and looked at the definitions in the git repo, it seems that this code hasn't been touched in a couple of years. Maybe the compiler defaults changed to include -Wincompatible-function-pointer-types by default? I am still unclear how this isn't an issue for others.

Any thoughts on this are appreciated. Thanks.

Mike

Hi Mike,

I just pulled main from ziti-sdk-swift and was able to successfully build via the build_all.sh script.

Before building I checked two things (because I find I sometimes have them out of sync):

  1. I pulled the latest into my $VCPKG_ROOT dir and ran ./bootstrap-vcpkg.sh
  2. I double checked I had the expected version of ziti-tunnel-sdk-c by changing directory to ziti-sdk-swift/deps/ziti-tunnel-sdk-c, running git status, and verifying that I see I'm at fda6af5 (same as I see ziti-sdk-swift/deps at main · openziti/ziti-sdk-swift · GitHub)

I'm pretty sure I haven't done anything in the past relating to the -Wincompatible-function-pointer-types flag.

I did this from an x86_64 Mac running 14.1.1 (23B81). My Xcode is currently version 15.2. I'm pretty sure @scareything does his local development on arm64.

It looks like the CI build (ziti-sdk-swift/.github/workflows/CI.yml at main · openziti/ziti-sdk-swift · GitHub) is running Mac version 13, Xcode 15.2.

I'll also take a look through my build logs to see if anything jumps out at me.

Good Evening Dave!

Thanks for the response. Per your comments:

I have the latest VCPKG as I had just cloned the repository, but I did go ahead and run ./bootstrap-vcpkg.sh.

I verified that I have the correct version of the ziti-tunnel-sdk-c, which matches where you are at (fda6af5).

I am on an Intel Mac with version 14.4 and I am using Xcode version 15.3.

After doing the above, I restored my change to lib/ziti-tunnel-cbs/dns_host.c and kicked off a build just for the iOS components. It failed as before. If there is something else that I should try to get past this, short of changing the function signature, let me know. Thanks.

Looks like you've given me a good reason to update my macOS version to the latest :). I'll do that and see if I can still build.

Are you able to use the XCFramework that's built from this repo's GitHub Action and distributed for Swift Package Manager at GitHub - openziti/ziti-sdk-swift-dist: Swift Package Repository for binary distribution of the https://github.com/openziti/ziti-sdk-swift binary CZiti.xcframework, or do you need to build for local development?

Updated my OS to 14.4 and could build fine.

Upgraded my Xcode to 15.3 and see the exact error you ran into.

I can still successfully build other projects with this version of Xcode that rely on the latest released CZiti.xcframework installed via Swift Package Manager..

I saw this a couple of weeks ago and the fix has been merged into main of ziti-tunnel-sdk-c but not yet released. We’ll be releasing this week, but you can switch your deps/ziti-tunnel-sdk-c over to main for now if you are in a hurry.

1 Like

Thanks everyone. I will just leave my change for the moment, until the official fix propagates.