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

Don't rebuild C static libs if the desired architecture/platform already exists #82

Closed
Closed
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions LibWally.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
75B9EE002810F88400E31B4D /* PBXContainerItemProxy */ = {
75683E51293049380014553B /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = FE9CD3A8229C397900345DFA /* Project object */;
proxyType = 1;
Expand Down Expand Up @@ -209,7 +209,7 @@
buildRules = (
);
dependencies = (
75B9EE012810F88400E31B4D /* PBXTargetDependency */,
75683E52293049380014553B /* PBXTargetDependency */,
);
name = LibWally;
productName = LibWally;
Expand Down Expand Up @@ -325,10 +325,10 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
75B9EE012810F88400E31B4D /* PBXTargetDependency */ = {
75683E52293049380014553B /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 75B9EDFC2810F83700E31B4D /* LibWallyCore */;
targetProxy = 75B9EE002810F88400E31B4D /* PBXContainerItemProxy */;
targetProxy = 75683E51293049380014553B /* PBXContainerItemProxy */;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to touch all these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, I don't see a reason why it should change -- let me take a second look here

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought maybe a checksum of some sort.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, you're right. it's the checksum of the scheme action we define here https://github.com/Sjors/libwally-swift/pull/82/files#diff-a0467817f744b83783e73e607681e81427686debb56a8ba92f697ba854994937R13

since our change works, I will go ahead and delete the pre-build script

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I misspoke, it was a checksum of our script, build-libwally.sh. Either way, I just committed 2f7f66f to remove the unneeded pre-build script.

};
FE9CD3BD229C397900345DFA /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
<ActionContent
title = "Run Script"
scriptText = "# We want to clean the libwally-core static build files for simulator so we can&#10;# build the ones for device.&#10;cd $PROJECT_DIR/CLibWally/libwally-core&#10;make clean&#10;rm -rf &quot;$(pwd)/build&quot;&#10;">
scriptText = "# We want to clean the libwally-core static build files for simulator so we can&#10;# build the ones for device.&#10;# cd $PROJECT_DIR/CLibWally/libwally-core&#10;# make clean&#10;# rm -rf &quot;$(pwd)/build&quot;&#10;">
<EnvironmentBuildable>
<BuildableReference
BuildableIdentifier = "primary"
Expand Down
31 changes: 24 additions & 7 deletions build-libwally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ build() {
CC="$(xcrun --sdk $SDK_NAME -f clang) -isysroot $(xcrun --sdk $SDK_NAME --show-sdk-path)"
CC_FOR_BUILD="$(xcrun --sdk macosx -f clang) -isysroot $(xcrun --sdk macosx --show-sdk-path)"

sh ./tools/autogen.sh
./configure --disable-shared --host=$HOST --enable-static --disable-elements --enable-standard-secp \
CC="$CC $EXTRA_CFLAGS" \
CPP="$CC $EXTRA_CFLAGS -E" \
Expand All @@ -42,8 +43,6 @@ build() {
}

if [[ ${ACTION:-build} = "build" || $ACTION = "install" ]]; then
sh ./tools/autogen.sh

if [[ $PLATFORM_NAME = "macosx" ]]; then
TARGET_OS="macos"
elif [[ $PLATFORM_NAME = "iphonesimulator" ]]; then
Expand All @@ -61,20 +60,38 @@ if [[ ${ACTION:-build} = "build" || $ACTION = "install" ]]; then
ARCHES=()
LIBWALLYCORE_EXECUTABLES=()
LIBSECP256K1_EXECUTABLES=()
NEEDS_LIPO=false

for ARCH in $ARCHS
do
TARGET_ARCH=$ARCH
if [[ $TARGET_ARCH = "arm64" ]]; then
TARGET_ARCH="aarch64"
fi

build ${PLATFORM_NAME} ${TARGET_ARCH}-apple-darwin "-arch ${ARCH} -m${TARGET_OS}-version-min=7.0 -fembed-bitcode"
LIBWALLYCORE_EXECUTABLES+=("${BUILD_DIR}/${PLATFORM_NAME}/libwallycore-${TARGET_ARCH}-apple-darwin.a")
LIBSECP256K1_EXECUTABLES+=("${BUILD_DIR}/${PLATFORM_NAME}/libsecp256k1-${TARGET_ARCH}-apple-darwin.a")
LIBWALLY_DIR="${BUILD_DIR}/${PLATFORM_NAME}/libwallycore-${TARGET_ARCH}-apple-darwin.a"
SECP_DIR="${BUILD_DIR}/${PLATFORM_NAME}/libsecp256k1-${TARGET_ARCH}-apple-darwin.a"

# If we haven't built our static library, let's go ahead and build it. Else, we can probably just not try and build at all.
if [ ! -f $LIBWALLY_DIR ] || [ ! -f $SECP_DIR ]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this means that if you change something in libwally-core you should clean the build folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, unfortunately Xcode changed its build system a couple of releases ago which does not allow for custom build targets to define their own clean behaviors when you clean from Xcode.

these lines here were meant to handle that case, but doesn't work: https://github.com/Sjors/libwally-swift/pull/82/files#diff-cf8443a1af8a2de0df5857abe08d2469008f13a0a65f4f984d3d60acdbc68679R95-R97

then
echo "DEBUG:: File not found, let's build!"
build ${PLATFORM_NAME} ${TARGET_ARCH}-apple-darwin "-arch ${ARCH} -m${TARGET_OS}-version-min=7.0 -fembed-bitcode"

# Tracks our list of executables so we know the static libraries we need to lipo later
LIBWALLYCORE_EXECUTABLES+=($LIBWALLY_DIR)
LIBSECP256K1_EXECUTABLES+=($SECP_DIR)

# Something changed, we should lipo later.
NEEDS_LIPO=true
fi
done

xcrun --sdk $PLATFORM_NAME lipo -create "${LIBWALLYCORE_EXECUTABLES[@]}" -output "${BUILD_DIR}/LibWallyCore"
xcrun --sdk $PLATFORM_NAME lipo -create "${LIBSECP256K1_EXECUTABLES[@]}" -output "${BUILD_DIR}/libsecp256k1"
# If nothing changed, we can just not try lipo at all and skip.
if [ "$NEEDS_LIPO" = true ] ; then
xcrun --sdk $PLATFORM_NAME lipo -create "${LIBWALLYCORE_EXECUTABLES[@]}" -output "${BUILD_DIR}/LibWallyCore"
xcrun --sdk $PLATFORM_NAME lipo -create "${LIBSECP256K1_EXECUTABLES[@]}" -output "${BUILD_DIR}/libsecp256k1"
fi
elif [[ $ACTION = "clean" ]]; then
make clean
fi