-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Support Swift Package Manager #2786
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
base: next
Are you sure you want to change the base?
Changes from all commits
6548086
7ba185c
a23e668
28e581b
8a3b928
851e787
b95162f
ea35f8e
ad4ebc4
0d6f7f2
1e0c8e3
017145d
ce4a148
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| name: 'Setup Xcode Conditionally' | ||
| description: 'Check current Xcode version and setup if different from required version (Avoid unessary sudo/password input for self hosted runner)' | ||
|
|
||
| inputs: | ||
| xcode-version: | ||
| description: 'Required Xcode version' | ||
| required: true | ||
|
|
||
| outputs: | ||
| current-version: | ||
| description: 'Current Xcode version' | ||
| value: ${{ steps.current-xcode.outputs.version }} | ||
| setup-skipped: | ||
| description: 'Whether Xcode setup was skipped' | ||
| value: ${{ steps.xcode-check.outputs.skip-setup }} | ||
|
|
||
| runs: | ||
| using: 'composite' | ||
| steps: | ||
| - name: Get current Xcode version | ||
| id: current-xcode | ||
| shell: bash | ||
| run: | | ||
| CURRENT_VERSION=$(xcode-select -p | grep -o '[0-9]\+\.[0-9]\+' || echo "none") | ||
| echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT | ||
| echo "Current Xcode version: $CURRENT_VERSION" | ||
|
|
||
| - name: Check if Xcode version matches | ||
| id: xcode-check | ||
| shell: bash | ||
| run: | | ||
| CURRENT="${{ steps.current-xcode.outputs.version }}" | ||
| REQUIRED="${{ inputs.xcode-version }}" | ||
| if [ "$CURRENT" = "$REQUIRED" ]; then | ||
| echo "skip-setup=true" >> $GITHUB_OUTPUT | ||
| echo "✅ Xcode version matches: $CURRENT = $REQUIRED, skipping setup" | ||
| else | ||
| echo "skip-setup=false" >> $GITHUB_OUTPUT | ||
| echo "❌ Xcode version mismatch: $CURRENT ≠ $REQUIRED, setup required" | ||
| fi | ||
|
|
||
| - name: Setup Xcode | ||
| if: steps.xcode-check.outputs.skip-setup == 'false' | ||
| uses: maxim-lobanov/setup-xcode@v1 | ||
| with: | ||
| xcode-version: ${{ inputs.xcode-version }} | ||
| - name: Swift version | ||
| shell: bash | ||
| run: swift --version |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -226,3 +226,31 @@ jobs: | |||||||
| cmake --preset=${{ matrix.config.platform }}-x64${{ matrix.config.diet_build == true && '-diet' || '' }} | ||||||||
| cmake --build --preset build-${{ matrix.config.platform }}${{ matrix.config.diet_build == true && '-diet' || '' }}-release | ||||||||
| cmake --build --preset install-${{ matrix.config.platform }}${{ matrix.config.diet_build == true && '-diet' || '' }}-release | ||||||||
|
|
||||||||
| cmake --preset=${{ matrix.config.platform }}-x64 | ||||||||
| cmake --build --preset build-${{ matrix.config.platform }}-release | ||||||||
| cmake --build --preset install-${{ matrix.config.platform }}-release | ||||||||
| macOS: | ||||||||
| name: Execute tests on macOS | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| strategy: | ||||||||
| fail-fast: false | ||||||||
| matrix: | ||||||||
| os: [macos-15] | ||||||||
| xcode-version: ["16.4"] | ||||||||
| runs-on: ${{ matrix.os }} | ||||||||
| env: | ||||||||
| GH_TOKEN: ${{ github.token }} | ||||||||
| steps: | ||||||||
| - uses: actions/checkout@v4 | ||||||||
| - name: Setup Xcode | ||||||||
| uses: ./.github/actions/setup-xcode | ||||||||
| with: | ||||||||
| xcode-version: ${{ matrix.xcode-version }} | ||||||||
| - name: Build and run tests in debug mode | ||||||||
| run: | | ||||||||
| swift test \ | ||||||||
| -c debug | ||||||||
|
Comment on lines
+251
to
+252
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| - name: Build and run tests in release mode | ||||||||
| run: | | ||||||||
| swift test \ | ||||||||
| -c release | ||||||||
|
Comment on lines
+255
to
+256
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // swift-tools-version: 6.1 | ||
| // The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
|
||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
| name: "capstone", | ||
| products: [ | ||
| .library( | ||
| name: "Ccapstone", | ||
| targets: ["Ccapstone"] | ||
|
Comment on lines
+10
to
+11
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the name Or is it to not conflict with @santalvarez bindings?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Swift convention is to name libraries imported from C as C + LibraryName for example, Swift's official example, and then have a pure Swift binding library that drops the C and starts with an uppercase letter. |
||
| ), | ||
| ], | ||
| targets: [ | ||
| .target( | ||
| name: "Ccapstone", | ||
| path: "bindings/swift/Ccapstone", | ||
| cSettings: [ | ||
| .headerSearchPath("../../../include"), | ||
| .define("CAPSTONE_USE_SYS_DYN_MEM"), | ||
| .define("CAPSTONE_HAS_ARM"), | ||
| .define("CAPSTONE_HAS_ARM64"), | ||
| .define("CAPSTONE_HAS_AARCH64"), | ||
| .define("CAPSTONE_HAS_MIPS"), | ||
| .define("CAPSTONE_HAS_X86"), | ||
| .define("CAPSTONE_HAS_POWERPC"), | ||
| .define("CAPSTONE_HAS_SPARC"), | ||
| .define("CAPSTONE_HAS_SYSTEMZ"), | ||
| .define("CAPSTONE_HAS_XCORE"), | ||
| .define("CAPSTONE_HAS_M68K"), | ||
| .define("CAPSTONE_HAS_TMS320C64X"), | ||
| .define("CAPSTONE_HAS_M680X"), | ||
| .define("CAPSTONE_HAS_EVM"), | ||
| .define("CAPSTONE_HAS_MOS65XX"), | ||
| .define("CAPSTONE_HAS_WASM"), | ||
| .define("CAPSTONE_HAS_BPF"), | ||
| .define("CAPSTONE_HAS_RISCV"), | ||
| .define("CAPSTONE_HAS_SH"), | ||
| .define("CAPSTONE_HAS_TRICORE"), | ||
| .define("CAPSTONE_HAS_ALPHA"), | ||
| .define("CAPSTONE_HAS_HPPA"), | ||
| .define("CAPSTONE_HAS_LOONGARCH"), | ||
| .define("CAPSTONE_HAS_XTENSA"), | ||
| .define("CAPSTONE_HAS_ARC"), | ||
| ], | ||
| ), | ||
| .testTarget( | ||
| name: "CcapstoneTests", | ||
| dependencies: ["Ccapstone"], | ||
| path: "bindings/swift/CcapstoneTests", | ||
| ), | ||
| ] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the Swift documentation (https://www.swift.org/documentation/articles/wrapping-c-cpp-library-in-swift.html) source files can be added with
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the capstone directory structure does not meet SwiftPM’s requirements, specifying only the sources or headers is not sufficient for SwiftPM, so a symbolic link-based approach is needed to create a directory structure that conforms to SwiftPM |
||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../LEB128.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../MCAsmInfo.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../MCDisassembler.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../MCFixedLenDisassembler.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../MCInst.c |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../MCInst.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../MCInstPrinter.c |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../MCInstPrinter.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../MCInstrDesc.c |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../MCInstrDesc.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../MCRegisterInfo.c |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../MCRegisterInfo.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../Mapping.c |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../Mapping.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../MathExtras.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../SStream.c |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../SStream.h |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these scripts necessary? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/bin/bash | ||
|
|
||
| target_dir="../../.." | ||
|
|
||
| find "$target_dir" -maxdepth 1 \( -name "*.h" -o -name "*.c" \) -print0 | while IFS= read -r -d $'\0' header_file; do | ||
|
|
||
| relative_path=$(echo "$header_file" | sed "s#^$PWD/##") | ||
|
|
||
| ln -s "$relative_path" . | ||
|
|
||
| echo "Created symlink: $(basename "$header_file") -> $relative_path" | ||
| done |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../arch |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../cs.c |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../cs_priv.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../cs_simple_types.h |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also this one |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/bin/bash | ||
|
|
||
| target_dir="../../../../../include/capstone" | ||
|
|
||
| find "$target_dir" -name "*.h" -print0 | while IFS= read -r -d $'\0' header_file; do | ||
| relative_path=$(echo "$header_file" | sed "s#^$PWD/##") | ||
|
|
||
| ln -s "$relative_path" . | ||
|
|
||
| echo "Created symlink: $(basename "$header_file") -> $relative_path" | ||
| done |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/aarch64.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/alpha.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/arc.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/arm.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/arm64.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/bpf.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/capstone.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/cs_operand.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/evm.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/hppa.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/loongarch.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/m680x.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/m68k.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/mips.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/mos65xx.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/platform.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/ppc.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/riscv.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/sh.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/sparc.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/systemz.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/systemz_compatibility.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/tms320c64x.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/tricore.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/wasm.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/x86.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/xcore.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../../include/capstone/xtensa.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../include/platform.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../utils.c |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../utils.h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why those additions to the Windows build?