Skip to content

Commit

Permalink
iox-#68 Bundle iceoryx C++ sources in crate to enable offline builds …
Browse files Browse the repository at this point in the history
…like for docs.rs
  • Loading branch information
elBoberido committed Jul 30, 2023
1 parent 9dd885b commit 433349c
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 35 deletions.
68 changes: 33 additions & 35 deletions iceoryx-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

use std::env;
use std::io::{Error, ErrorKind};
use std::path::Path;
use std::process::Command;

const ICEORYX_VERSION: &str = "v2.0.3";

fn make_and_install(source_dir: &str, build_dir: &str, install_dir: &str) -> std::io::Result<()> {
let cmake_install_prefix = format!("-DCMAKE_INSTALL_PREFIX={}", install_dir);
let cmake_prefix_path = format!("-DCMAKE_PREFIX_PATH={}", install_dir);
Expand Down Expand Up @@ -62,51 +63,48 @@ fn make_and_install(source_dir: &str, build_dir: &str, install_dir: &str) -> std
Ok(())
}

fn clone_repo(repo: &str, branch: &str, source_dir: &str) -> std::io::Result<()> {
if !Path::new(source_dir).join(".git").exists() {
Command::new("git")
.args(&[
"clone",
repo,
&format!("--branch={}", branch),
"--recursive",
source_dir,
])
.output()
.map_err(|out| {
println!("{:?}", out);
out
})
.map(|out| println!("{:?}", out))?;
} else {
Command::new("git")
.current_dir(source_dir)
.args(&["checkout", branch])
.output()
.map_err(|out| {
println!("{:?}", out);
out
})
.map(|out| println!("{:?}", out))?;
fn extract_archive(archive_dir: &str, source_dir: &str, version: &str) -> std::io::Result<()> {
if !Command::new("mkdir")
.args(&["-p", &source_dir])
.status()?
.success()
{
return Err(Error::new(
ErrorKind::Other,
format!("Could not create source dir for '{}'!", source_dir),
));
}

if !Command::new("tar")
.args(&[
"-xf",
&format!("{}/{}.tar.gz", archive_dir, version),
"-C",
&source_dir,
"--strip-components=1",
])
.status()?
.success()
{
return Err(Error::new(
ErrorKind::Other,
format!("Could not extract archive '{}' to '{}'!", version, source_dir),
));
}

Ok(())
}

fn main() -> std::io::Result<()> {
let out_dir = env::var("OUT_DIR").expect("Target output directory");
let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("Cargo manifest directory");

let iceoryx_source_dir = format!("{}/{}", out_dir, "iceoryx-git");
let iceoryx_archive_dir = format!("{}/{}", manifest_dir, "iceoryx-cpp");
let iceoryx_source_dir = format!("{}/{}/", out_dir, "iceoryx-cpp");
let iceoryx_build_dir = format!("{}/{}", out_dir, "iceoryx-build");
let iceoryx_install_dir = format!("{}/{}", out_dir, "iceoryx-install");

const ICEORYX_VERSION: &str = "v2.0.2";
const ICEORYX_GIT_BRANCH: &str = ICEORYX_VERSION;
clone_repo(
"https://github.com/eclipse-iceoryx/iceoryx.git",
ICEORYX_GIT_BRANCH,
&iceoryx_source_dir,
)?;
extract_archive(&iceoryx_archive_dir, &iceoryx_source_dir, ICEORYX_VERSION)?;

make_and_install(
&iceoryx_source_dir,
Expand Down
147 changes: 147 additions & 0 deletions iceoryx-sys/iceoryx-cpp/update-iceoryx-cpp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#! /bin/bash

shopt -s expand_aliases

# colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
COLOR_OFF='\033[0m'

GIT_TOPLEVEL=$(git rev-parse --show-toplevel)
ICEORYX_CPP_BASE_DIR=$GIT_TOPLEVEL/iceoryx-sys/iceoryx-cpp
ICEORYX_TAG="v0.0.0"

DO_BUILD_ONLY=false
DO_PREPARATORY_WORK=false
DO_RELEASE=false

OPTION_COUNTER=0
while (( "$#" )); do
((OPTION_COUNTER+=1))
if [[ $OPTION_COUNTER -gt 1 ]]; then
echo -e "${RED}Error:${COLOR_OFF} Too many arguments specified! Try '--help' for more information."
exit -1
fi

case $1 in
-h|--help)
echo "Script to update bundled iceoryx C++ source archive"
echo ""
echo "Usage: update-iceoryx-cpp.sh [option]"
echo "Only one option at a time is allowed!"
echo "Options:"
echo " -t, --tag <TAG> Updates the bundled source archive with"
echo " the given <TAG>"
echo " -h, --help Prints this help"
echo ""
echo "Example:"
echo " update-iceoryx-cpp.sh --tag v2.0.0"
exit 0
;;
-t|--tag)
if [[ $# -ne 2 ]]; then
echo -e "${RED}Error:${COLOR_OFF} No parameter specified! Try '--help' for more information."
fi
ICEORYX_TAG="$2"

shift 2
;;
*)
echo "Invalid argument '$1'. Try '--help' for options."
exit -1
;;
esac
done

if [[ $OPTION_COUNTER -eq 0 ]]; then
echo -e "${RED}Error:${COLOR_OFF} No arguments specified! Try '--help' for more information."
exit -1
fi

####################
# cd into base dir #
####################

cd $ICEORYX_CPP_BASE_DIR

echo -e "${CYAN}Info:${COLOR_OFF} Entering '$(pwd)'"

#######################
# Remove old archives #
#######################

echo -e "${CYAN}Info:${COLOR_OFF} Removing old archives with the naming pattern 'v*.tar.gz*'"

rm -rf v*\.tar\.gz*

#######################
# Downloading archive #
#######################

ICEORYX_ARCHIVE="${ICEORYX_TAG}.tar.gz"
ICEORYX_ARCHIVE_LINK="https://github.com/eclipse-iceoryx/iceoryx/archive/refs/tags/${ICEORYX_ARCHIVE}"

echo -e "${CYAN}Info:${COLOR_OFF} Fetching '${ICEORYX_ARCHIVE_LINK}'"

wget ${ICEORYX_ARCHIVE_LINK} --quiet --show-progress

if [ $? -ne 0 ]; then
echo -e "${RED}Error:${COLOR_OFF} Could not fetch '${ICEORYX_ARCHIVE_LINK}'"
exit -1
fi

##########################
# Extracting new archive #
##########################

echo -e "${CYAN}Info:${COLOR_OFF} Extracting new source archive to '${ICEORYX_TAG}'"

mkdir -p ${ICEORYX_TAG}
tar -xf ${ICEORYX_ARCHIVE} -C ${ICEORYX_TAG} --strip-components=1 --atime-preserve=replace

#################
# Strip archive #
#################

echo -e "${CYAN}Info:${COLOR_OFF} Stripping source archive from unnecessary files"

rm -rf ${ICEORYX_TAG}/.clang-format
rm -rf ${ICEORYX_TAG}/.clang-tidy
rm -rf ${ICEORYX_TAG}/.codecov.yml
rm -rf ${ICEORYX_TAG}/.gitattributes
rm -rf ${ICEORYX_TAG}/.github
rm -rf ${ICEORYX_TAG}/.gitignore
rm -rf ${ICEORYX_TAG}/cmake
rm -rf ${ICEORYX_TAG}/doc
rm -rf ${ICEORYX_TAG}/iceoryx_binding_c
rm -rf ${ICEORYX_TAG}/iceoryx_dds
rm -rf ${ICEORYX_TAG}/iceoryx_examples
rm -rf ${ICEORYX_TAG}/iceoryx_integrationtest
rm -rf ${ICEORYX_TAG}/iceoryx_meta
rm -rf ${ICEORYX_TAG}/mkdocs.yml
rm -rf ${ICEORYX_TAG}/tools

rm -rf ${ICEORYX_TAG}/iceoryx_hoofs/test
rm -rf ${ICEORYX_TAG}/iceoryx_posh/test
# restore modified timestamp to prevent changes in archive checksum for repetitive updates to the same tag
touch -r ${ICEORYX_TAG}/VERSION ${ICEORYX_TAG}/iceoryx_hoofs
touch -r ${ICEORYX_TAG}/VERSION ${ICEORYX_TAG}/iceoryx_posh
touch -r ${ICEORYX_TAG}/VERSION ${ICEORYX_TAG}

#######################
# Re-compress archive #
#######################

echo -e "${CYAN}Info:${COLOR_OFF} Re-compressing '${ICEORYX_TAG}' into '${ICEORYX_ARCHIVE}'"

tar -czf ${ICEORYX_ARCHIVE} ${ICEORYX_TAG}

##########################
# Remove extracted archive #
##########################

echo -e "${CYAN}Info:${COLOR_OFF} Removing extracted file"

rm -rf ${ICEORYX_TAG}
Binary file added iceoryx-sys/iceoryx-cpp/v2.0.3.tar.gz
Binary file not shown.

0 comments on commit 433349c

Please sign in to comment.