diff --git a/nix/dev-shell.nix b/nix/dev-shell.nix index 5098e99b6..c7c744178 100644 --- a/nix/dev-shell.nix +++ b/nix/dev-shell.nix @@ -1,145 +1,144 @@ { mkShell , stdenv , lib , amqp-cpp , arcanist , aws-sdk-cpp , better-prompt , boost , c-ares_cmake-config -, cargo , cmake , cmake-format , cocoapods , corrosion , cryptopp , darwin , double-conversion , folly , fmt , glog , grpc , gtest , libiconv , libuv , localstack , mariadb , mariadb-up , nodejs-16_x-openssl_1_1 , olm , openjdk8 , openssl , pkg-config , protobuf_3_15_cmake , python3 , redis , redis-up -, rustc , rustup , shellcheck , sqlite , terraform , watchman , rustfmt , yarn }: mkShell { # programs which are meant to be executed should go here nativeBuildInputs = [ # generic development or tools arcanist shellcheck terraform # node development mariadb nodejs-16_x-openssl_1_1 yarn watchman # react native python3 redis # native dependencies # C/CXX toolchains are already brought in with mkShell # Identity Service - cargo # includes rustc - rustc # allow for direct invocation of rustc rustfmt rustup # Tunnelbroker + CMake amqp-cpp c-ares_cmake-config cryptopp cmake cmake-format # linting libuv # Localstack is currently broken by partial update # See https://github.com/NixOS/nixpkgs/pull/197572 #localstack pkg-config protobuf_3_15_cmake grpc ] ++ lib.optionals stdenv.isDarwin [ cocoapods # needed for ios ]; # include any libraries buildInputs buildInputs = [ # protobuf exposes both a library and a command # thus should appear in both inputs protobuf_3_15_cmake aws-sdk-cpp # tunnelbroker corrosion # tunnelbroker double-conversion # tunnelbroker glog # tunnelbroker gtest # testing services folly # cpp tools fmt # needed for folly boost # needed for folly olm # needed for CryptoTools sqlite # needed for sqlite_orm openssl # needed for grpc ] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ CoreFoundation CoreServices Security libiconv # identity service ]); JAVA_HOME = openjdk8.passthru.home; # shell commands to be ran upon entering shell shellHook = '' PRJ_ROOT=$(git rev-parse --show-toplevel) # Set development environment variable defaults source "${../scripts/source_development_defaults.sh}" # Cache development path for some use cases such as XCode "$PRJ_ROOT/scripts/save_path.sh" '' # Darwin condition can be removed once linux services are supported + lib.optionalString stdenv.isDarwin '' # Start MariaDB development services "${mariadb-up}"/bin/mariadb-up & mariadb_pid=$! "${redis-up}"/bin/redis-up & redis_pid=$! wait "$mariadb_pid" "$redis_pid" '' + '' # Render default configuration for keyserver $PRJ_ROOT/scripts/create_url_facts.sh + # Ensure rustup tooling is installed + $PRJ_ROOT/scripts/ensure_rustup_setup.sh + # Provide decent bash prompt source "${better-prompt}/bin/better-prompt" echo "Welcome to Comm dev environment! :)" ''; } diff --git a/scripts/build-rust-native-library.sh b/scripts/build-rust-native-library.sh index 892018ef1..22fb75f86 100755 --- a/scripts/build-rust-native-library.sh +++ b/scripts/build-rust-native-library.sh @@ -1,36 +1,37 @@ #!/usr/bin/env bash set -euxo pipefail COMM_NIX_PATH="$HOME/.cache/comm/path" +PRJ_ROOT="$(git rev-parse --show-toplevel)" # If in nix environment, re-expose nix PATH if [[ -f "$COMM_NIX_PATH" ]]; then # shellcheck source=/dev/null source "$COMM_NIX_PATH" fi # The $PATH used by Xcode likely won't contain Cargo, fix that. # In addition, the $PATH used by XCode has lots of Apple-specific # developer tools that your Cargo isn't expecting to use, fix that. # Note: This assumes a default `rustup` setup and default path. build_path="$HOME/.cargo/bin:/usr/local/bin:/usr/bin:/bin${PATH:+:}$PATH" + # cd to Cargo project cd "${SRCROOT}/../native_rust_library" || exit -# Add iOS targets for cross-compilation -env PATH="${build_path}" rustup target add aarch64-apple-ios -env PATH="${build_path}" rustup target add x86_64-apple-ios -# Install cargo lipo -env PATH="${build_path}" cargo install cargo-lipo + +# Ensure rust tooling is available +env PATH="${build_path}" "$PRJ_ROOT/scripts/ensure_rustup_setup.sh" + # Set C++ standard and build cxx bridge export CXXFLAGS="-std=c++14" env PATH="${build_path}" cargo build # Build universal static library (works on simulator and iOS) env PATH="${build_path}" cargo lipo --release # Unset the flag specifying C++ standard unset CXXFLAGS # Copy the CXX files to the cargo project root to make them # available to XCode cp "$(readlink target/cxxbridge/native_rust_library/src/lib.rs.cc)" . cp "$(readlink target/cxxbridge/native_rust_library/src/lib.rs.h)" . cp "$(readlink target/cxxbridge/rust/cxx.h)" . diff --git a/scripts/ensure_rustup_setup.sh b/scripts/ensure_rustup_setup.sh new file mode 100755 index 000000000..3eb3fd68f --- /dev/null +++ b/scripts/ensure_rustup_setup.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +ensure_target() { + local target="$1" + + if ! rustup target list --installed | grep "$target" > /dev/null; then + rustup target add "$1" + fi +} + +if ! command -v rustup > /dev/null; then + echo "Please install rustup" >&2 + exit 1 +fi + +if [[ "$(rustup toolchain list)" == "no installed toolchains" ]]; then + rustup toolchain install stable +fi + +ensure_target aarch64-apple-ios +ensure_target x86_64-apple-ios + +if ! command -v cargo-lipo > /dev/null; then + cargo install cargo-lipo +fi