2019-02-28 22:05:11 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#!/usr/bin/env bash
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-21 11:22:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								if [ "$#" -ne 1 ]; then
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    echo "Error: Must provide the full path to the project to build"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    exit 1
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fi
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-22 15:09:59 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								if [ ! -f "$1/Cargo.toml" ]; then
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-21 11:22:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      echo "Error: Cannot find project: $1"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    exit 1
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fi
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-20 16:07:12 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								echo "Building $1"
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-28 22:05:11 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								set -e
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-08 22:34:26 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								bpf_sdk=$(cd "$(dirname "$0")/.." && pwd)
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-20 16:49:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-28 22:05:11 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# Ensure the sdk is installed
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-16 17:35:42 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								"$bpf_sdk"/scripts/install.sh
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-28 22:05:11 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-07 14:38:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# Use the SDK's version of llvm to build the compiler-builtins for BPF
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-17 11:04:38 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								export CC="$bpf_sdk/dependencies/llvm-native/bin/clang"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								export AR="$bpf_sdk/dependencies/llvm-native/bin/llvm-ar"
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-20 16:49:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-07 14:38:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# Use the SDK's version of Rust to build for BPF
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-16 17:35:42 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								export RUSTUP_TOOLCHAIN=bpf
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-21 11:22:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								export RUSTFLAGS="
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-28 22:05:11 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    -C lto=no \
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    -C opt-level=2 \
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    -C link-arg=-z -C link-arg=notext \
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-17 11:04:38 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    -C link-arg=-T$bpf_sdk/rust/bpf.ld \
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-28 22:05:11 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    -C link-arg=--Bdynamic \
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    -C link-arg=-shared \
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    -C link-arg=--entry=entrypoint \
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-25 07:44:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    -C link-arg=-no-threads \
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-17 11:04:38 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    -C linker=$bpf_sdk/dependencies/llvm-native/bin/ld.lld"
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-20 16:49:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# Setup xargo
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-17 14:24:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								export XARGO_HOME="$bpf_sdk/dependencies/xargo"
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-17 11:04:38 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								export XARGO_RUST_SRC="$bpf_sdk/dependencies/rust-bpf-sysroot/src"
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 22:27:14 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								export RUST_COMPILER_RT_ROOT="$bpf_sdk/dependencies/rust-bpf-sysroot/src/compiler-rt"
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-20 16:49:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								cd "$1"
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-20 16:07:12 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								xargo build --target bpfel-unknown-unknown --release
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-28 22:05:11 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-02 21:56:54 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{ { set +x; } 2>/dev/null; echo Success; }
							 |