Skip to content

Instantly share code, notes, and snippets.

@mrdomino
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrdomino/4421c3103147627925b0 to your computer and use it in GitHub Desktop.
Save mrdomino/4421c3103147627925b0 to your computer and use it in GitHub Desktop.
#!/bin/sh
function main {
for cpu in ${CPUS[@]}
do
echo ==== $cpu ====
check bazel build --ios_cpu=$cpu $DEPS
check mkdir -p $WORK/$cpu
for dep in $DEPS
do
check cp_dep_library $cpu $dep
done
check gen_packed_library $cpu
done
check gen_lipo_library
printf $'Done:\n %s\n' $LIB
}
function cp_dep_library {
cpu=$1
dep=$2
lib=$(target_to_lib $dep)
cp $lib $WORK/$cpu
}
function gen_packed_library {
cpu=$1
check pushdq $WORK/$cpu
for lib in *.a
do
check mkdir ${lib}_obj
check pushdq ${lib}_obj
check ar -x ../$lib
check ar -qc ../../lib$cpu.a *.o
check popdq
done
check popdq
}
function gen_lipo_library {
check lipo -create -output $LIB $WORK/*.a
}
function target_to_dir {
target=$1
echo $target | sed -e 's=^//\(.*\):.*$=\1='
}
function target_to_file {
target=$1
echo $target | sed -e 's=^.*:\(.*\)$=\1='
}
function target_to_lib {
target=$1
dir=$(target_to_dir $target)
file=$(target_to_file $target)
echo bazel-bin/$dir/lib$file.a
}
function target_to_src {
target=$1
echo $(target_to_dir $target)/$(target_to_file $target)
}
function check {
$@ || {
echo "FAILED: $@" 1>&2
exit 1
}
}
function pushdq { pushd $@ >/dev/null ;}
function popdq { popd $@ >/dev/null ;}
TARG=$1
shift
CPUS=$@
[ -z "$TARG" ] && exit 1
[ -z "$CPUS" ] && exit 1
DEPS=$(bazel query "kind(.*_library, deps($TARG)) - //tools/cpp:stl")
LIB=$(target_to_lib $TARG)
WORK=$(mktemp -dt $(basename $0))
trap "rm -rf $WORK" EXIT
time main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment