Skip to content

Commit 2e95ae3

Browse files
Merge pull request #252 from flouthoc/test-rust-cross-build
build: run build sanity for various architecture
2 parents 5367866 + 36bf256 commit 2e95ae3

File tree

9 files changed

+53
-26
lines changed

9 files changed

+53
-26
lines changed

.cirrus.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ env:
1717
# Save a little typing (path relative to $CIRRUS_WORKING_DIR)
1818
SCRIPT_BASE: "./contrib/cirrus"
1919
FEDORA_NAME: "fedora-35"
20-
IMAGE_SUFFIX: "c4560539387953152"
20+
IMAGE_SUFFIX: "c6118659411148800"
2121
FEDORA_NETAVARK_IMAGE: "fedora-netavark-${IMAGE_SUFFIX}"
2222

2323

@@ -113,6 +113,15 @@ unit_task:
113113
setup_script: *setup
114114
main_script: *main
115115

116+
build_cross_task:
117+
alias: "build_cross"
118+
depends_on:
119+
- "build"
120+
cargo_cache: *ro_cargo_cache
121+
targets_cache: *ro_targets_cache
122+
bin_cache: *ro_bin_cache
123+
setup_script: *setup
124+
main_script: *main
116125

117126
integration_task:
118127
alias: "integration"
@@ -152,6 +161,7 @@ success_task:
152161
alias: success
153162
depends_on:
154163
- "build"
164+
- "build_cross"
155165
- "validate"
156166
- "verify_vendor"
157167
- "unit"

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ test: unit integration
7575
build_unit: $(CARGO_TARGET_DIR)
7676
cargo test --no-run
7777

78+
# Test build cross-architecture
79+
.PHONY: build_cross
80+
build_cross: $(CARGO_TARGET_DIR)
81+
cargo install cross
82+
rustup target add aarch64-unknown-linux-gnu
83+
rustup target add arm-unknown-linux-gnueabi
84+
cross build --target aarch64-unknown-linux-gnu
85+
cross build --target arm-unknown-linux-gnueabi
86+
7887
.PHONY: unit
7988
unit: $(CARGO_TARGET_DIR)
8089
cargo test

contrib/cirrus/lib.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ SECRET_ENV_RE='(ACCOUNT)|(GC[EP]..+)|(SSH)|(PASSWORD)|(TOKEN)'
2929
if [[ -r "/etc/ci_environment" ]]; then
3030
source /etc/ci_environment
3131
else # set default values - see make_cienv() below
32-
# Install rust packages globally instead of per-user
33-
CARGO_HOME="${CARGO_HOME:-/usr/local/cargo}"
34-
# Ensure cargo packages can be executed
35-
PATH="$PATH:$CARGO_HOME/bin"
32+
# VM Images are built with this setup
33+
CARGO_HOME="${CARGO_HOME:-/var/cache/cargo}"
34+
source $CARGO_HOME/env
3635
fi
3736

3837
# END Global export of all variables

contrib/cirrus/runner.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@ EOF
3535
}
3636

3737
_run_validate() {
38+
rustup install stable
39+
rustup default stable
3840
make validate
3941
}
4042

43+
_run_build_cross() {
44+
make build_cross
45+
}
46+
4147
_run_verify_vendor() {
4248
# N/B: current repo. dir. contents produced by _run_build() above.
4349
if ! git diff --no-ext-diff --quiet --exit-code; then

contrib/cirrus/setup.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ if [[ -r "/etc/ci_environment" ]]; then
1414
fi
1515
trap "complete_setup" EXIT
1616

17+
1718
msg "************************************************************"
1819
msg "Setting up runtime environment"
1920
msg "************************************************************"
21+
22+
dnf -y install make automake gcc gcc-c++ kernel-devel
23+
2024
show_env_vars
25+
26+
if [[ "$CIRRUS_TASK_NAME" == "build_cross" ]]; then
27+
# Setup short-name for rustembedded/cross
28+
# TODO: We can move this to quay.io if we reach rate-limits, hopefully that's not gonna happen for netavark
29+
echo ' "rustembedded/cross" = "docker.io/rustembedded/cross"' >> /etc/containers/registries.conf.d/000-shortnames.conf
30+
fi

src/commands/teardown.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl Teardown {
4848

4949
if Path::new(&aardvark_bin).exists() {
5050
// stop dns server first before netavark clears the interface
51-
let path = Path::new(&config_dir).join("aardvark-dns".to_string());
51+
let path = Path::new(&config_dir).join("aardvark-dns");
5252
if let Ok(path_string) = path.into_os_string().into_string() {
5353
let mut aardvark_interface = Aardvark::new(path_string, rootless, aardvark_bin);
5454
if let Err(er) =

src/dns/aardvark.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,18 @@ impl Aardvark {
4545

4646
// On success retuns aardvark server's pid or returns -1;
4747
fn get_aardvark_pid(&mut self) -> i32 {
48-
let pid: i32;
49-
let path = Path::new(&self.config).join("aardvark.pid".to_string());
50-
match fs::read_to_string(&path) {
51-
Ok(content) => {
52-
pid = match content.parse::<i32>() {
53-
Ok(val) => val,
54-
Err(_) => {
55-
return -1;
56-
}
48+
let path = Path::new(&self.config).join("aardvark.pid");
49+
let pid: i32 = match fs::read_to_string(&path) {
50+
Ok(content) => match content.parse::<i32>() {
51+
Ok(val) => val,
52+
Err(_) => {
53+
return -1;
5754
}
58-
}
55+
},
5956
Err(_) => {
6057
return -1;
6158
}
62-
}
59+
};
6360

6461
pid
6562
}
@@ -161,14 +158,13 @@ impl Aardvark {
161158
}
162159

163160
pub fn commit_entry(&mut self, entry: AardvarkEntry) -> Result<()> {
164-
let data: String;
161+
let mut data: String;
165162
let path = Path::new(&self.config).join(entry.network_name);
166163
let file_exists = path.exists();
167164
let mut file = OpenOptions::new().append(true).create(true).open(&path)?;
168165
// check if this is the first container in this network
169166
if !file_exists {
170167
// write first line as gateway ip
171-
let data: String;
172168
if !entry.network_gateway_v4.is_empty() && !entry.network_gateway_v6.is_empty() {
173169
data = format!(
174170
"{},{}\n",

src/network/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ impl Core {
535535
&container_macvlan_clone,
536536
netns_ipaddr_clone,
537537
gw_ipaddr,
538-
&"".to_string(), // do we want static mac support for macvlan ? probably later.
538+
"", // do we want static mac support for macvlan ? probably later.
539539
) {
540540
return Err(err);
541541
}

src/network/core_utils.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,9 @@ impl CoreUtils {
145145

146146
tokio::spawn(connection);
147147

148-
let master_index: u32;
149-
150148
let mut links = handle.link().get().match_name(ifname.to_string()).execute();
151-
match links.try_next().await {
152-
Ok(Some(msg)) => master_index = msg.header.index,
153-
149+
let master_index: u32 = match links.try_next().await {
150+
Ok(Some(msg)) => msg.header.index,
154151
Ok(None) => {
155152
return Err(std::io::Error::new(
156153
std::io::ErrorKind::Other,
@@ -166,7 +163,7 @@ impl CoreUtils {
166163
format!("Unable to resolve bridge interface {}: {}", ifname, err),
167164
));
168165
}
169-
}
166+
};
170167

171168
let mut links = handle
172169
.link()

0 commit comments

Comments
 (0)