Skip to content

Commit 433349c

Browse files
committed
iox-#68 Bundle iceoryx C++ sources in crate to enable offline builds like for docs.rs
1 parent 9dd885b commit 433349c

File tree

3 files changed

+180
-35
lines changed

3 files changed

+180
-35
lines changed

iceoryx-sys/build.rs

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
use std::env;
77
use std::io::{Error, ErrorKind};
8-
use std::path::Path;
98
use std::process::Command;
109

10+
const ICEORYX_VERSION: &str = "v2.0.3";
11+
1112
fn make_and_install(source_dir: &str, build_dir: &str, install_dir: &str) -> std::io::Result<()> {
1213
let cmake_install_prefix = format!("-DCMAKE_INSTALL_PREFIX={}", install_dir);
1314
let cmake_prefix_path = format!("-DCMAKE_PREFIX_PATH={}", install_dir);
@@ -62,51 +63,48 @@ fn make_and_install(source_dir: &str, build_dir: &str, install_dir: &str) -> std
6263
Ok(())
6364
}
6465

65-
fn clone_repo(repo: &str, branch: &str, source_dir: &str) -> std::io::Result<()> {
66-
if !Path::new(source_dir).join(".git").exists() {
67-
Command::new("git")
68-
.args(&[
69-
"clone",
70-
repo,
71-
&format!("--branch={}", branch),
72-
"--recursive",
73-
source_dir,
74-
])
75-
.output()
76-
.map_err(|out| {
77-
println!("{:?}", out);
78-
out
79-
})
80-
.map(|out| println!("{:?}", out))?;
81-
} else {
82-
Command::new("git")
83-
.current_dir(source_dir)
84-
.args(&["checkout", branch])
85-
.output()
86-
.map_err(|out| {
87-
println!("{:?}", out);
88-
out
89-
})
90-
.map(|out| println!("{:?}", out))?;
66+
fn extract_archive(archive_dir: &str, source_dir: &str, version: &str) -> std::io::Result<()> {
67+
if !Command::new("mkdir")
68+
.args(&["-p", &source_dir])
69+
.status()?
70+
.success()
71+
{
72+
return Err(Error::new(
73+
ErrorKind::Other,
74+
format!("Could not create source dir for '{}'!", source_dir),
75+
));
76+
}
77+
78+
if !Command::new("tar")
79+
.args(&[
80+
"-xf",
81+
&format!("{}/{}.tar.gz", archive_dir, version),
82+
"-C",
83+
&source_dir,
84+
"--strip-components=1",
85+
])
86+
.status()?
87+
.success()
88+
{
89+
return Err(Error::new(
90+
ErrorKind::Other,
91+
format!("Could not extract archive '{}' to '{}'!", version, source_dir),
92+
));
9193
}
9294

9395
Ok(())
9496
}
9597

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

99-
let iceoryx_source_dir = format!("{}/{}", out_dir, "iceoryx-git");
102+
let iceoryx_archive_dir = format!("{}/{}", manifest_dir, "iceoryx-cpp");
103+
let iceoryx_source_dir = format!("{}/{}/", out_dir, "iceoryx-cpp");
100104
let iceoryx_build_dir = format!("{}/{}", out_dir, "iceoryx-build");
101105
let iceoryx_install_dir = format!("{}/{}", out_dir, "iceoryx-install");
102106

103-
const ICEORYX_VERSION: &str = "v2.0.2";
104-
const ICEORYX_GIT_BRANCH: &str = ICEORYX_VERSION;
105-
clone_repo(
106-
"https://github.com/eclipse-iceoryx/iceoryx.git",
107-
ICEORYX_GIT_BRANCH,
108-
&iceoryx_source_dir,
109-
)?;
107+
extract_archive(&iceoryx_archive_dir, &iceoryx_source_dir, ICEORYX_VERSION)?;
110108

111109
make_and_install(
112110
&iceoryx_source_dir,
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#! /bin/bash
2+
3+
shopt -s expand_aliases
4+
5+
# colors
6+
RED='\033[0;31m'
7+
GREEN='\033[0;32m'
8+
YELLOW='\033[0;33m'
9+
CYAN='\033[0;36m'
10+
COLOR_OFF='\033[0m'
11+
12+
GIT_TOPLEVEL=$(git rev-parse --show-toplevel)
13+
ICEORYX_CPP_BASE_DIR=$GIT_TOPLEVEL/iceoryx-sys/iceoryx-cpp
14+
ICEORYX_TAG="v0.0.0"
15+
16+
DO_BUILD_ONLY=false
17+
DO_PREPARATORY_WORK=false
18+
DO_RELEASE=false
19+
20+
OPTION_COUNTER=0
21+
while (( "$#" )); do
22+
((OPTION_COUNTER+=1))
23+
if [[ $OPTION_COUNTER -gt 1 ]]; then
24+
echo -e "${RED}Error:${COLOR_OFF} Too many arguments specified! Try '--help' for more information."
25+
exit -1
26+
fi
27+
28+
case $1 in
29+
-h|--help)
30+
echo "Script to update bundled iceoryx C++ source archive"
31+
echo ""
32+
echo "Usage: update-iceoryx-cpp.sh [option]"
33+
echo "Only one option at a time is allowed!"
34+
echo "Options:"
35+
echo " -t, --tag <TAG> Updates the bundled source archive with"
36+
echo " the given <TAG>"
37+
echo " -h, --help Prints this help"
38+
echo ""
39+
echo "Example:"
40+
echo " update-iceoryx-cpp.sh --tag v2.0.0"
41+
exit 0
42+
;;
43+
-t|--tag)
44+
if [[ $# -ne 2 ]]; then
45+
echo -e "${RED}Error:${COLOR_OFF} No parameter specified! Try '--help' for more information."
46+
fi
47+
ICEORYX_TAG="$2"
48+
49+
shift 2
50+
;;
51+
*)
52+
echo "Invalid argument '$1'. Try '--help' for options."
53+
exit -1
54+
;;
55+
esac
56+
done
57+
58+
if [[ $OPTION_COUNTER -eq 0 ]]; then
59+
echo -e "${RED}Error:${COLOR_OFF} No arguments specified! Try '--help' for more information."
60+
exit -1
61+
fi
62+
63+
####################
64+
# cd into base dir #
65+
####################
66+
67+
cd $ICEORYX_CPP_BASE_DIR
68+
69+
echo -e "${CYAN}Info:${COLOR_OFF} Entering '$(pwd)'"
70+
71+
#######################
72+
# Remove old archives #
73+
#######################
74+
75+
echo -e "${CYAN}Info:${COLOR_OFF} Removing old archives with the naming pattern 'v*.tar.gz*'"
76+
77+
rm -rf v*\.tar\.gz*
78+
79+
#######################
80+
# Downloading archive #
81+
#######################
82+
83+
ICEORYX_ARCHIVE="${ICEORYX_TAG}.tar.gz"
84+
ICEORYX_ARCHIVE_LINK="https://github.com/eclipse-iceoryx/iceoryx/archive/refs/tags/${ICEORYX_ARCHIVE}"
85+
86+
echo -e "${CYAN}Info:${COLOR_OFF} Fetching '${ICEORYX_ARCHIVE_LINK}'"
87+
88+
wget ${ICEORYX_ARCHIVE_LINK} --quiet --show-progress
89+
90+
if [ $? -ne 0 ]; then
91+
echo -e "${RED}Error:${COLOR_OFF} Could not fetch '${ICEORYX_ARCHIVE_LINK}'"
92+
exit -1
93+
fi
94+
95+
##########################
96+
# Extracting new archive #
97+
##########################
98+
99+
echo -e "${CYAN}Info:${COLOR_OFF} Extracting new source archive to '${ICEORYX_TAG}'"
100+
101+
mkdir -p ${ICEORYX_TAG}
102+
tar -xf ${ICEORYX_ARCHIVE} -C ${ICEORYX_TAG} --strip-components=1 --atime-preserve=replace
103+
104+
#################
105+
# Strip archive #
106+
#################
107+
108+
echo -e "${CYAN}Info:${COLOR_OFF} Stripping source archive from unnecessary files"
109+
110+
rm -rf ${ICEORYX_TAG}/.clang-format
111+
rm -rf ${ICEORYX_TAG}/.clang-tidy
112+
rm -rf ${ICEORYX_TAG}/.codecov.yml
113+
rm -rf ${ICEORYX_TAG}/.gitattributes
114+
rm -rf ${ICEORYX_TAG}/.github
115+
rm -rf ${ICEORYX_TAG}/.gitignore
116+
rm -rf ${ICEORYX_TAG}/cmake
117+
rm -rf ${ICEORYX_TAG}/doc
118+
rm -rf ${ICEORYX_TAG}/iceoryx_binding_c
119+
rm -rf ${ICEORYX_TAG}/iceoryx_dds
120+
rm -rf ${ICEORYX_TAG}/iceoryx_examples
121+
rm -rf ${ICEORYX_TAG}/iceoryx_integrationtest
122+
rm -rf ${ICEORYX_TAG}/iceoryx_meta
123+
rm -rf ${ICEORYX_TAG}/mkdocs.yml
124+
rm -rf ${ICEORYX_TAG}/tools
125+
126+
rm -rf ${ICEORYX_TAG}/iceoryx_hoofs/test
127+
rm -rf ${ICEORYX_TAG}/iceoryx_posh/test
128+
# restore modified timestamp to prevent changes in archive checksum for repetitive updates to the same tag
129+
touch -r ${ICEORYX_TAG}/VERSION ${ICEORYX_TAG}/iceoryx_hoofs
130+
touch -r ${ICEORYX_TAG}/VERSION ${ICEORYX_TAG}/iceoryx_posh
131+
touch -r ${ICEORYX_TAG}/VERSION ${ICEORYX_TAG}
132+
133+
#######################
134+
# Re-compress archive #
135+
#######################
136+
137+
echo -e "${CYAN}Info:${COLOR_OFF} Re-compressing '${ICEORYX_TAG}' into '${ICEORYX_ARCHIVE}'"
138+
139+
tar -czf ${ICEORYX_ARCHIVE} ${ICEORYX_TAG}
140+
141+
##########################
142+
# Remove extracted archive #
143+
##########################
144+
145+
echo -e "${CYAN}Info:${COLOR_OFF} Removing extracted file"
146+
147+
rm -rf ${ICEORYX_TAG}

iceoryx-sys/iceoryx-cpp/v2.0.3.tar.gz

447 KB
Binary file not shown.

0 commit comments

Comments
 (0)