Skip to content

fix: build script for macOS development #1491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 59 additions & 27 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -246,20 +246,37 @@ function run_package_std() {
cp "$rel_dir/"*.a "$lib_dir" 2>/dev/null || log "$rel_dir does not contain *.a files"
# Create an SO file from the copied a file
log "Creating a shared library from the compiled static library"
log "Running : $cc --shared -L$lib_dir \
-Wl,--whole-archive -liec61131std \
-o $lib_dir/out.so -Wl,--no-whole-archive \
-lm \
-fuse-ld=lld \
--target=$val"
$cc --shared -L"$lib_dir" \
-Wl,--whole-archive -liec61131std \
-o "$lib_dir/out.so" -Wl,--no-whole-archive \
-lm \
-fuse-ld=lld \
--target="$val"

mv "$lib_dir/out.so" "$lib_dir/libiec61131std.so"
# Check if we're on macOS and adjust linker flags accordingly
Copy link
Preview

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The macOS-specific linking logic is duplicated in two sections. Consider extracting this into a helper function or shared snippet to avoid repetition and simplify future maintenance.

Copilot uses AI. Check for mistakes.

unameOut="$(uname -s)"
case "${unameOut}" in
Darwin*)
log "Running : $cc --shared -L$lib_dir \
-Wl,-force_load,$lib_dir/libiec61131std.a \
-o $lib_dir/libiec61131std.so \
-lm -framework CoreFoundation \
--target=$val"
$cc --shared -L"$lib_dir" \
-Wl,-force_load,"$lib_dir/libiec61131std.a" \
-o "$lib_dir/libiec61131std.so" \
-lm -framework CoreFoundation \
--target="$val"
;;
*)
log "Running : $cc --shared -L$lib_dir \
-Wl,--whole-archive -liec61131std \
-o $lib_dir/libiec61131std.so -Wl,--no-whole-archive \
-lm \
-fuse-ld=lld \
--target=$val"
$cc --shared -L"$lib_dir" \
-Wl,--whole-archive -liec61131std \
-o "$lib_dir/libiec61131std.so" -Wl,--no-whole-archive \
-lm \
-fuse-ld=lld \
--target="$val"
;;
esac

done
else
lib_dir=$OUTPUT_DIR/lib
Expand All @@ -272,21 +289,36 @@ function run_package_std() {
cp "$rel_dir/"*.a "$lib_dir" 2>/dev/null || log "$rel_dir does not contain *.a files"
# Create an SO file from the copied a file
log "Creating a shared library from the compiled static library"
log "Running : $cc --shared -L"$lib_dir" \
-Wl,--whole-archive -liec61131std \
-o "$lib_dir/out.so" -Wl,--no-whole-archive \
-lm \
-fuse-ld=lld "
$cc --shared -L"$lib_dir" \
-Wl,--whole-archive -liec61131std \
-o "$lib_dir/out.so" -Wl,--no-whole-archive \
-lm \
-fuse-ld=lld
mv "$lib_dir/out.so" "$lib_dir/libiec61131std.so"
# Check if we're on macOS and adjust linker flags accordingly
unameOut="$(uname -s)"
case "${unameOut}" in
Darwin*)
log "Running : $cc --shared -L"$lib_dir" \
-Wl,-force_load,$lib_dir/libiec61131std.a \
-o "$lib_dir/libiec61131std.so" \
-lm -framework CoreFoundation"
$cc --shared -L"$lib_dir" \
Copy link
Preview

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The macOS branch invocation is missing the --target="$val" flag that appears in the first block, which could lead to incorrect target linking. Add --target="$val" here to match behavior.

Suggested change
$cc --shared -L"$lib_dir" \
$cc --shared -L"$lib_dir" \
--target="$val" \

Copilot uses AI. Check for mistakes.

-Wl,-force_load,"$lib_dir/libiec61131std.a" \
-o "$lib_dir/libiec61131std.so" \
-lm -framework CoreFoundation
;;
*)
log "Running : $cc --shared -L"$lib_dir" \
-Wl,--whole-archive -liec61131std \
-o "$lib_dir/libiec61131std.so" -Wl,--no-whole-archive \
-lm \
-fuse-ld=lld "
$cc --shared -L"$lib_dir" \
-Wl,--whole-archive -liec61131std \
-o "$lib_dir/libiec61131std.so" -Wl,--no-whole-archive \
-lm \
-fuse-ld=lld
;;
esac
fi

log "Enabling read/write on the output folder"
chmod a+rw $OUTPUT_DIR -R
chmod -R a+rw $OUTPUT_DIR

}

Expand Down Expand Up @@ -506,7 +538,7 @@ fi

if [[ -d $project_location/target/ ]]; then
log "Allow access to target folders"
chmod a+rw -R $project_location/target/
chmod -R a+rw $project_location/target/
fi

if [[ $offline -ne 0 ]]; then
Expand Down