Skip to content

Commit

Permalink
Use Keith's magic library on macOS (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
dduan authored Mar 22, 2022
1 parent c71ed32 commit 44334d7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
9 changes: 5 additions & 4 deletions Documentation/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ mint install dduan/DrString

For macOS and Ubuntu Bionic/Focal, you can download a package from a release.
After unarchiving the package, the `drstring` binary should run without problems.
Make sure all content of the archive stay in the same relative location when you
move them. For example, if you move the executable to `FOO/bin/drstring`, the
content in `lib/*` should be in `FOO/lib`.

Note: if a parent process who calls `drstring` set the environment variable
For Ubuntu, Make sure all content of the archive stay in the same relative
location when you move them. For example, if you move the executable to
`FOO/bin/drstring`, the content in `lib/*` should be in `FOO/lib`.

If a parent process who calls `drstring` set the environment variable
`LD_LIBRARY_PATH` on Linux, it may affect its successful execution. You must
set `LD_LIBRARY_PATH` to the `lib` directory distributed with `drstring` in its
execution environment to restore its functionality.
Expand Down
14 changes: 12 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// swift-tools-version:5.5
import PackageDescription
#if os(macOS)
let magicLibrary = true
#else
let magicLibrary = false
#endif

let package = Package(
name: "DrString",
Expand Down Expand Up @@ -106,7 +111,8 @@ let package = Package(
),
.executableTarget(
name: "DrStringCLI",
dependencies: ["DrStringCore"]
dependencies: ["DrStringCore"] + (magicLibrary ? ["lib_InternalSwiftSyntaxParser"] : []),
linkerSettings: (magicLibrary ? [.unsafeFlags(["-Xlinker", "-dead_strip_dylibs"])] : [])
),
.testTarget(
name: "ModelsTests",
Expand Down Expand Up @@ -145,5 +151,9 @@ let package = Package(
"Fixtures/",
]
),
]
] + (magicLibrary ? [.binaryTarget(
name: "lib_InternalSwiftSyntaxParser",
url: "https://github.com/keith/StaticInternalSwiftSyntaxParser/releases/download/5.6/lib_InternalSwiftSyntaxParser.xcframework.zip",
checksum: "88d748f76ec45880a8250438bd68e5d6ba716c8042f520998a438db87083ae9d"
)] : [])
)
14 changes: 4 additions & 10 deletions Scripts/package-darwin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
set -euo pipefail

BUILD_PATH=.build/apple/Products/Release
LIB_PATH=$BUILD_PATH/lib
BIN_PATH=$BUILD_PATH/bin
COMPLETIONS_PATH=$BUILD_PATH/completions
TEMP=$(mktemp -d)
COMPLETIONS_PATH=$TEMP/completions
ARCHIVE=drstring_darwin.tar.gz
rm -rf $LIB_PATH
rm -rf $BIN_PATH
rm -rf $COMPLETIONS_PATH
mkdir -p $LIB_PATH
mkdir -p $BIN_PATH
mkdir -p $COMPLETIONS_PATH
cp -r Scripts/completions/* $COMPLETIONS_PATH
cp $BUILD_PATH/drstring-cli $BIN_PATH/drstring
cp $BUILD_PATH/lib_InternalSwiftSyntaxParser.dylib $LIB_PATH/lib_InternalSwiftSyntaxParser.dylib
tar -C $BUILD_PATH -czf $ARCHIVE bin lib completions
cp $BUILD_PATH/drstring-cli $TEMP/drstring
tar -C $TEMP -czf $ARCHIVE drstring completions

0 comments on commit 44334d7

Please sign in to comment.