• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env bash
2
3# Copyright 2024 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Build and update Rust bindings for libslirp-rs & hostapd-rs on netsim-dev branch
18
19# To update an individual library only, pass in "libslirp-rs" or "hostapd-rs" as argument.
20
21# The script is necessary because Clang binary, used for creating bindings,
22# isn't included in prebuilts for all platforms.
23
24# Prerequisites (Linux/macOS):
25# Install Clang to use bindgen: https://rust-lang.github.io/rust-bindgen/requirements.html
26
27# Instructions (Linux/macOS):
28# Run this script manually to regenerate all bindings.rs files.
29
30# Windows instructions:
31# 1. Install official pre-built LLVM binary:
32#    https://rust-lang.github.io/rust-bindgen/requirements.html
33# 2. Set the `LIBCLANG_PATH` environment variable to point to the 'bin'
34#    directory within your LLVM installation:
35#    `set LIBCLANG_PATH=C:\Program Files\LLVM\bin`
36# 3. Uncomment the lines starting with `##` in Cargo.toml.
37# 4. Navigate to the rust/hostapd-rs directory and run `cargo build`.
38# 5. Revert the change in Cargo.toml: `git checkout rust/hostapd-rs/Cargo.toml`
39
40if [ $# -ne 1 ] || ([ "$1" != "libslirp-rs" ] && [ "$1" != "hostapd-rs" ]); then
41    echo "Must provide library name to update bindings i.e. libslirp-rs or hostapd-rs"
42    exit 1
43fi
44
45# Absolute path to tools/netsim using this scripts directory
46REPO_NETSIM=$(dirname $(readlink -f "$0"))/..
47echo "REPO_NETSIM: ${REPO_NETSIM}"
48CARGO_MANIFEST=$REPO_NETSIM/rust/$1/Cargo.toml
49
50# Uncomment lines starting with `##`
51OS=$(uname | tr '[:upper:]' '[:lower:]')
52if [[ "$OS" == "linux" ]]; then
53    sed -i 's/^##//g' $CARGO_MANIFEST
54fi
55if [[ "$OS" == "darwin" ]]; then
56    sed -i '' 's/^##//g' $CARGO_MANIFEST
57fi
58
59if [ ! -d "$REPO_NETSIM/objs/rust/.cargo" ]; then
60    python3 $REPO_NETSIM/scripts/build_tools.py
61fi
62
63# Use Rust dependency crates available on netsim-dev branch
64export CARGO_HOME=$REPO_NETSIM/objs/rust/.cargo
65
66cd $REPO_NETSIM
67cargo build --manifest-path $CARGO_MANIFEST
68
69# Undo changed to Cargo.toml
70git checkout $CARGO_MANIFEST
71
72rm $REPO_NETSIM/rust/Cargo.lock
73