Skip to content

Commit 4338ad5

Browse files
committed
feat(build): support building on macos
Signed-off-by: Reuben Miller <reuben.d.miller@gmail.com>
1 parent ba3a53e commit 4338ad5

File tree

7 files changed

+63
-3
lines changed

7 files changed

+63
-3
lines changed

ci/build_scripts/build.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,22 @@ Args:
3232
3333
Example ARCH (target) values:
3434
35-
MUSL variants
35+
Linux MUSL variants
3636
* x86_64-unknown-linux-musl
3737
* aarch64-unknown-linux-musl
3838
* armv7-unknown-linux-musleabihf
3939
* arm-unknown-linux-musleabihf
4040
41-
GNU variants
41+
Linux GNU variants
4242
* x86_64-unknown-linux-gnu
4343
* aarch64-unknown-linux-gnu
4444
* armv7-unknown-linux-gnueabihf
4545
* arm-unknown-linux-gnueabihf
4646
47+
Apple
48+
* aarch64-apple-darwin
49+
* x86_64-apple-darwin
50+
4751
Flags:
4852
--help|-h Show this help
4953
--skip-build Skip building the binaries and only package them (e.g. just create the linux packages)

ci/build_scripts/package.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ VERSION=
6868
CLEAN=1
6969
PACKAGES=()
7070
COMMAND=
71-
PACKAGE_TYPES="deb,apk,rpm,tarball"
71+
PACKAGE_TYPES=
7272

7373
while [ $# -gt 0 ]
7474
do
@@ -117,6 +117,14 @@ if [ -z "$TARGET" ]; then
117117
TARGET=$(./ci/build_scripts/detect_target.sh)
118118
fi
119119

120+
if [ -z "$PACKAGE_TYPES" ]; then
121+
case "$TARGET" in
122+
*linux*) PACKAGE_TYPES="deb,apk,rpm,tarball" ;;
123+
*apple*) PACKAGE_TYPES="tarball" ;;
124+
*) PACKAGE_TYPES="tarball" ;;
125+
esac
126+
fi
127+
120128
# Normalize output dir
121129
OUTPUT_DIR="${OUTPUT_DIR%/}"
122130

@@ -204,6 +212,8 @@ get_package_arch() {
204212
riscv64gc-unknown-linux-*) pkg_arch=riscv64 ;;
205213
mips64el-unknown-linux-*abi64) pkg_arch=mips64le ;;
206214
mipsel-unknown-linux-*) pkg_arch=mipsle ;;
215+
aarch64-apple-darwin) pkg_arch=arm64 ;;
216+
x86_64-apple-darwin) pkg_arch=amd64 ;;
207217
*)
208218
echo "Unknown package architecture. value=$1"
209219
exit 1

ci/build_scripts/publish_packages.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ get_user_friendly_arch() {
183183
*arm-unknown-linux-musleabihf*)
184184
easy_arch=armv6
185185
;;
186+
*aarch64-apple-darwin*)
187+
easy_arch=macos-arm64
188+
;;
189+
*x86_64-apple-darwin*)
190+
easy_arch=macos-amd64
191+
;;
186192
esac
187193
echo "$easy_arch"
188194
}

crates/common/logged_command/src/logged_command.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ EOF
317317

318318
// On expect the errors to be logged
319319
let log_content = String::from_utf8(std::fs::read(log_file_path)?)?;
320+
#[cfg(target_os = "linux")]
320321
assert_eq!(
321322
log_content,
322323
r#"----- $ ls "dummy-file"
@@ -328,6 +329,20 @@ EOF
328329
stderr <<EOF
329330
ls: cannot access 'dummy-file': No such file or directory
330331
EOF
332+
"#
333+
);
334+
#[cfg(target_os = "macos")]
335+
assert_eq!(
336+
log_content,
337+
r#"----- $ ls "dummy-file"
338+
exit status: 1
339+
340+
stdout <<EOF
341+
EOF
342+
343+
stderr <<EOF
344+
ls: dummy-file: No such file or directory
345+
EOF
331346
"#
332347
);
333348
Ok(())

crates/common/tedge_utils/src/file.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,13 +636,22 @@ mod tests {
636636
assert!(err.to_string().contains("User not found"));
637637
}
638638

639+
#[cfg(target_os = "linux")]
639640
#[test]
640641
fn get_gid_of_groups() {
641642
assert_eq!(get_gid_by_name("root").unwrap(), 0);
642643
let err = get_gid_by_name("nonexistent_group").unwrap_err();
643644
assert!(err.to_string().contains("Group not found"));
644645
}
645646

647+
#[cfg(target_os = "macos")]
648+
#[test]
649+
fn get_gid_of_groups() {
650+
assert_ne!(get_gid_by_name("staff").unwrap(), 0);
651+
let err = get_gid_by_name("nonexistent_group").unwrap_err();
652+
assert!(err.to_string().contains("Group not found"));
653+
}
654+
646655
#[tokio::test]
647656
async fn move_file_to_different_filesystem() {
648657
let file_dir = TempDir::new().unwrap();

crates/common/tedge_utils/src/notify.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ mod tests {
222222
}
223223
}
224224

225+
#[cfg_attr(target_os = "macos", ignore)]
225226
#[tokio::test]
226227
async fn test_multiple_known_files_watched() {
227228
let ttd = Arc::new(TempTedgeDir::new());
@@ -247,6 +248,7 @@ mod tests {
247248
file_handler.await.unwrap();
248249
}
249250

251+
#[cfg_attr(target_os = "macos", ignore)]
250252
#[tokio::test]
251253
async fn it_works() {
252254
let ttd = Arc::new(TempTedgeDir::new());
@@ -280,6 +282,7 @@ mod tests {
280282
.unwrap();
281283
}
282284

285+
#[cfg_attr(target_os = "macos", ignore)]
283286
#[tokio::test]
284287
async fn test_multiple_unknown_files_watched() {
285288
let ttd = Arc::new(TempTedgeDir::new());
@@ -308,6 +311,7 @@ mod tests {
308311
file_handler.await.unwrap();
309312
}
310313

314+
#[cfg_attr(target_os = "macos", ignore)]
311315
#[tokio::test]
312316
async fn test_multiple_directories_watched() {
313317
let ttd_a = Arc::new(TempTedgeDir::new());
@@ -352,6 +356,7 @@ mod tests {
352356
/// operation may result in other events, like `Rename`, `Delete`, etc. We want these operations to emit `Modify` as
353357
/// well, so that the consumers can only subscribe to single type of event and properly respond every time a file
354358
/// they're watching changes.
359+
#[cfg_attr(target_os = "macos", ignore)]
355360
#[tokio::test]
356361
async fn modify_emitted_for_move_copy_create_delete() {
357362
// Arrange

crates/extensions/tedge_file_system_ext/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ mod tests {
196196
ttd.file("file_a");
197197
ttd.dir("dir_b").file("file_b");
198198

199+
#[cfg(target_os = "linux")]
199200
client_box
200201
.with_timeout(TEST_TIMEOUT)
201202
.assert_received_unordered([
@@ -205,6 +206,16 @@ mod tests {
205206
])
206207
.await;
207208

209+
#[cfg(target_os = "macos")]
210+
client_box
211+
.with_timeout(TEST_TIMEOUT)
212+
.assert_received_unordered([
213+
FsWatchEvent::FileCreated(ttd_full.to_path_buf().join("file_a")),
214+
FsWatchEvent::DirectoryCreated(ttd_full.to_path_buf().join("dir_b")),
215+
FsWatchEvent::FileCreated(ttd_full.to_path_buf().join("dir_b").join("file_b")),
216+
])
217+
.await;
218+
208219
Ok(())
209220
}
210221
}

0 commit comments

Comments
 (0)