Skip to content

Commit

Permalink
build: remove hard-coded build setup
Browse files Browse the repository at this point in the history
the macos specific linker flags are specific to Xcode
version 15 (which is a bug and should be fixed) - so workaround
documented and linker flags removed from build settings
  • Loading branch information
kucaahbe committed Feb 11, 2024
1 parent 8acd1ff commit 85eb87b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 65 deletions.
21 changes: 9 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,23 @@ jobs:

- name: 'dub build/lint/test'
run: |
dub_configuration=application
echo "::group::Build info:"
if [[ -x /usr/bin/xcodebuild ]]; then
xcode_version_raw="$(/usr/bin/xcodebuild -version)"
xcode_version="$(echo "$xcode_version_raw" | awk '/Xcode/ { print int($2) }')"
if [[ $xcode_version -eq 15 ]]; then
dub_configuration="application-xcode$xcode_version"
else
dub_configuration="application-xcode-older"
# https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes#Known-Issues
export DFLAGS="-L-ld_classic"
fi
echo "::notice title=${{ matrix.os }} Xcode version::$xcode_version_raw"
fi
echo "::group::Build info:"
echo "::notice::$xcode_version_raw"
echo "::notice::$($DC --version)($DC)"
compiler_version="$($DC --version)"
echo "::notice title=${{ matrix.os }}/${{ matrix.dc }} compiler::$compiler_version"
echo "::endgroup::"
dub build --compiler=$DC --build=release-debug --config=$dub_configuration # --verbose
dub lint --compiler=$DC --config=$dub_configuration # --verbose
dub test --compiler=$DC --config=$dub_configuration --coverage # --verbose
dub build --compiler=$DC --build=release-debug # --verbose
dub lint --compiler=$DC # --verbose
dub test --compiler=$DC --coverage # --verbose
- name: 'Upload binary'
uses: actions/upload-artifact@v4
Expand Down
19 changes: 8 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
.dub
/dub.settings.json

# per-directory dmd configuration:
/dmd.conf

# documentation files:
docs.json
__dummy.html
docs/
/myrc
myrc.so
myrc.dylib
myrc.dll
myrc.a
myrc.lib
myrc-test-*
*.exe
*.pdb
*.o
*.obj

# generated binaries:
/myrc*
# code coverage files:
*.lst
30 changes: 1 addition & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1 @@
### MacOS Build issues

issue:
```
ld: warning: pointer not aligned at address 0x10016509F ('anon' + 146 from ../../../.dub/cache/sdlite/1.2.0/build/library-debug-Euv1mnZz1Zk-3iGZsMSgFQ/libsdlite.a(parser_419_6ff.o))
ld: warning: pointer not aligned at address 0x1001650E5 ('anon' + 216 from ../../../.dub/cache/sdlite/1.2.0/build/library-debug-Euv1mnZz1Zk-3iGZsMSgFQ/libsdlite.a(parser_419_6ff.o))
ld: unaligned pointer(s) for architecture x86_64
```
fix:
in dub.settings.json:
```json
{
"defaultBuildEnvironments": {
"MACOSX_DEPLOYMENT_TARGET": "11"
}
}
```

issue:
dub lint doesnt work (fails on running scanner)
open dscanner (dub list dscanner) dub.json and add
```json
"lflags-osx": ["-ld_classic"],
```
and modify:
```diff
- "\"$DC\" -run \"$PACKAGE_DIR/dubhash.d\""
+ "\"$DC\" -L-ld_classic -run \"$PACKAGE_DIR/dubhash.d\""
```
## myrc
54 changes: 54 additions & 0 deletions build_issues.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
## MacOS build issues

#### unaligned pointer(s)

issue:

linking errors like this:

```
ld: warning: pointer not aligned at address 0x10016509F ('anon' + 146 from ../../../.dub/cache/sdlite/1.2.0/build/library-debug-Euv1mnZz1Zk-3iGZsMSgFQ/libsdlite.a(parser_419_6ff.o))
ld: warning: pointer not aligned at address 0x1001650E5 ('anon' + 216 from ../../../.dub/cache/sdlite/1.2.0/build/library-debug-Euv1mnZz1Zk-3iGZsMSgFQ/libsdlite.a(parser_419_6ff.o))
ld: unaligned pointer(s) for architecture x86_64
```

fix:

set `MACOSX_DEPLOYMENT_TARGET` environment variable to `11` (or `12`):
```bash
env MACOSX_DEPLOYMENT_TARGET=11 dub
```

#### symbol count from symbol table and dynamic symbol table differ

issue:

linking, when XCode version is
[15](https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes#Known-Issues), errors like this:

```
ld: multiple errors: symbol count from symbol table and dynamic symbol table differ in '/Users/kucaahbe/.dub/cache/myrc/0.2.1/build/application-debug-adg7nRO7nk0vUCCcUFqMMw/myrc.o' in '/Users/kucaahbe/.dub/cache/myrc/0.2.1/build/application-debug-adg7nRO7nk0vUCCcUFqMMw/myrc.o'; address=0x0 points to section(2) with no content in '/Library/D/dmd/lib/libphobos2.a[3233](config_a98_4c3.o)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

fix:

add `-L-ld_classic` to dmd flags, either:

```bash
env DFLAGS="-L-ld_classic" dub
```

or issue could be solved globally for dmd, by copying [`dmd.conf`](https://dlang.org/dmd-osx.html#dmd-conf) file to
any [allowed location](https://dlang.org/dmd-osx.html#dmd-conf) and appending `-L-ld_classic` there:

```ini
; ~/.dmd.conf
[Environment]

; on OSX (when dmd isntalled from .dmg) the original config file is located at
; /Library/D/dmd/bin/dmd.conf and its content should be used as base.
; Original content:
;DFLAGS=-I/Library/D/dmd/src/phobos -I/Library/D/dmd/src/druntime/import -L-L/Library/D/dmd/lib
DFLAGS=-I/Library/D/dmd/src/phobos -I/Library/D/dmd/src/druntime/import -L-L/Library/D/dmd/lib -L-ld_classic
```
13 changes: 0 additions & 13 deletions dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,5 @@ mainSourceFile "source/main.d"
dependency "sdlite" version="~>1.2.0"

configuration "application" {
platforms "linux"
targetType "executable"
}

configuration "application-xcode15" {
platforms "osx-x86_64"
targetType "executable"
lflags "-ld_classic"
}

configuration "application-xcode-older" {
platforms "osx-x86_64"
targetType "executable"
# lflags "-ld_classic"
}

0 comments on commit 85eb87b

Please sign in to comment.