Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
feat: cross-compilation (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianpartridge authored Sep 3, 2019
1 parent f244ad1 commit eaf2cef
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 51 deletions.
33 changes: 8 additions & 25 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,6 @@

import PackageDescription

var backtraceDependencies: [Target.Dependency] = []

#if os(Linux)
backtraceDependencies.append(.target(name: "CBacktrace"))
#endif

var targets: [Target] = [
.target(
name: "Backtrace",
dependencies: backtraceDependencies),
.testTarget(
name: "BacktraceTests",
dependencies: ["Backtrace"])
]

#if os(Linux)
targets.append(
.target(
name: "CBacktrace",
dependencies: [])
)
#endif


let package = Package(
name: "swift-backtrace",
products: [
Expand All @@ -34,5 +10,12 @@ let package = Package(
targets: ["Backtrace"]),
],
dependencies: [],
targets: targets
targets: [
.target(name: "Backtrace",
dependencies: ["CBacktrace"]),
.target(name: "CBacktrace",
dependencies: []),
.testTarget(name: "BacktraceTests",
dependencies: ["Backtrace"])
]
)
35 changes: 9 additions & 26 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,6 @@

import PackageDescription

var backtraceDependencies: [Target.Dependency] = []

#if os(Linux)
backtraceDependencies.append(.target(name: "CBacktrace"))
#endif

var targets: [Target] = [
.target(
name: "Backtrace",
dependencies: backtraceDependencies),
.testTarget(
name: "BacktraceTests",
dependencies: ["Backtrace"])
]

#if os(Linux)
targets.append(
.target(
name: "CBacktrace",
dependencies: [])
)
#endif


let package = Package(
name: "swift-backtrace",
products: [
Expand All @@ -34,5 +10,12 @@ let package = Package(
targets: ["Backtrace"]),
],
dependencies: [],
targets: targets
)
targets: [
.target(name: "Backtrace",
dependencies: ["CBacktrace"]),
.target(name: "CBacktrace",
dependencies: []),
.testTarget(name: "BacktraceTests",
dependencies: ["Backtrace"])
]
)
2 changes: 2 additions & 0 deletions Sources/CBacktrace/atomic.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
/* atomic.c -- Support for atomic functions if not present.
Copyright (C) 2013-2018 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Google.
Expand Down Expand Up @@ -111,3 +112,4 @@ backtrace_atomic_store_int (int *p, int v)
}

#endif
#endif
2 changes: 2 additions & 0 deletions Sources/CBacktrace/backtrace-supported.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
/* backtrace-supported.h.in -- Whether stack backtrace is supported.
Copyright (C) 2012-2016 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Google.
Expand Down Expand Up @@ -64,3 +65,4 @@ POSSIBILITY OF SUCH DAMAGE. */
will work for variables. It will always work for functions. */

#define BACKTRACE_SUPPORTS_DATA 1
#endif
2 changes: 2 additions & 0 deletions Sources/CBacktrace/backtrace.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
/* backtrace.c -- Entry point for stack backtrace library.
Copyright (C) 2012-2018 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Google.
Expand Down Expand Up @@ -127,3 +128,4 @@ backtrace_full (struct backtrace_state *state, int skip,
_Unwind_Backtrace (unwind, &bdata);
return bdata.ret;
}
#endif
2 changes: 2 additions & 0 deletions Sources/CBacktrace/config.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */

Expand Down Expand Up @@ -148,3 +149,4 @@

/* Define to 1 if you need to in order for `stat' and other things to work. */
/* #undef _POSIX_SOURCE */
#endif
2 changes: 2 additions & 0 deletions Sources/CBacktrace/dwarf.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
/* dwarf.c -- Get file/line information from DWARF for backtraces.
Copyright (C) 2012-2018 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Google.
Expand Down Expand Up @@ -3124,3 +3125,4 @@ backtrace_dwarf_add (struct backtrace_state *state,

return 1;
}
#endif
2 changes: 2 additions & 0 deletions Sources/CBacktrace/elf.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
/* elf.c -- Get debug data from an ELF file for backtraces.
Copyright (C) 2012-2018 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Google.
Expand Down Expand Up @@ -3338,3 +3339,4 @@ backtrace_initialize (struct backtrace_state *state, const char *filename,

return 1;
}
#endif
2 changes: 2 additions & 0 deletions Sources/CBacktrace/fileline.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
/* fileline.c -- Get file and line number information in a backtrace.
Copyright (C) 2012-2018 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Google.
Expand Down Expand Up @@ -199,3 +200,4 @@ backtrace_syminfo (struct backtrace_state *state, uintptr_t pc,
state->syminfo_fn (state, pc, callback, error_callback, data);
return 1;
}
#endif
2 changes: 2 additions & 0 deletions Sources/CBacktrace/filenames.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
/* btest.c -- Filename header for libbacktrace library
Copyright (C) 2012-2018 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Google.
Expand Down Expand Up @@ -47,3 +48,4 @@ POSSIBILITY OF SUCH DAMAGE. */
#else
# define IS_DIR_SEPARATOR(c) ((c) == '/')
#endif
#endif
2 changes: 2 additions & 0 deletions Sources/CBacktrace/include/backtrace.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
/* backtrace.h -- Public header file for stack backtrace library.
Copyright (C) 2012-2018 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Google.
Expand Down Expand Up @@ -180,3 +181,4 @@ extern int backtrace_syminfo (struct backtrace_state *state, uintptr_t addr,
#endif

#endif
#endif
2 changes: 2 additions & 0 deletions Sources/CBacktrace/internal.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
/* internal.h -- Internal header file for stack backtrace library.
Copyright (C) 2012-2018 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Google.
Expand Down Expand Up @@ -302,3 +303,4 @@ extern int backtrace_uncompress_zdebug (struct backtrace_state *,
size_t *uncompressed_size);

#endif
#endif
2 changes: 2 additions & 0 deletions Sources/CBacktrace/mmap.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
/* mmap.c -- Memory allocation with mmap.
Copyright (C) 2012-2018 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Google.
Expand Down Expand Up @@ -323,3 +324,4 @@ backtrace_vector_release (struct backtrace_state *state,
vec->alc = 0;
return 1;
}
#endif
2 changes: 2 additions & 0 deletions Sources/CBacktrace/mmapio.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
/* mmapio.c -- File views using mmap.
Copyright (C) 2012-2018 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Google.
Expand Down Expand Up @@ -98,3 +99,4 @@ backtrace_release_view (struct backtrace_state *state ATTRIBUTE_UNUSED,
if (munmap (const_cast.v, view->len) < 0)
error_callback (data, "munmap", errno);
}
#endif
2 changes: 2 additions & 0 deletions Sources/CBacktrace/posix.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
/* posix.c -- POSIX file I/O routines for the backtrace library.
Copyright (C) 2012-2018 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Google.
Expand Down Expand Up @@ -98,3 +99,4 @@ backtrace_close (int descriptor, backtrace_error_callback error_callback,
}
return 1;
}
#endif
2 changes: 2 additions & 0 deletions Sources/CBacktrace/print.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
/* print.c -- Print the current backtrace.
Copyright (C) 2012-2018 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Google.
Expand Down Expand Up @@ -90,3 +91,4 @@ backtrace_print (struct backtrace_state *state, int skip, FILE *f)
backtrace_full (state, skip + 1, print_callback, error_callback,
(void *) &data);
}
#endif
2 changes: 2 additions & 0 deletions Sources/CBacktrace/simple.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
/* simple.c -- The backtrace_simple function.
Copyright (C) 2012-2018 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Google.
Expand Down Expand Up @@ -106,3 +107,4 @@ backtrace_simple (struct backtrace_state *state, int skip,
_Unwind_Backtrace (simple_unwind, &bdata);
return bdata.ret;
}
#endif
2 changes: 2 additions & 0 deletions Sources/CBacktrace/sort.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
/* sort.c -- Sort without allocating memory
Copyright (C) 2012-2018 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Google.
Expand Down Expand Up @@ -106,3 +107,4 @@ backtrace_qsort (void *basearg, size_t count, size_t size,
goto tail_recurse;
}
}
#endif
2 changes: 2 additions & 0 deletions Sources/CBacktrace/state.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
/* state.c -- Create the backtrace state.
Copyright (C) 2012-2018 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Google.
Expand Down Expand Up @@ -70,3 +71,4 @@ backtrace_create_state (const char *filename, int threaded,

return state;
}
#endif
3 changes: 3 additions & 0 deletions scripts/vendor-libbacktrace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ mv "$DSTROOT/backtrace.h" "$DSTROOT/include"
echo "REPLACING references to \"backtrace.h\" with \"include/backtrace.h\""
find $DSTROOT -name "*.[ch]" -print0 | xargs -0 sed -i -e 's#"backtrace.h"#"include/backtrace.h"#g'

echo "ADDING preprocessor conditionals"
find $DSTROOT -name "*.[ch]" -print0 | xargs -0 sed -i -e '1i#ifdef __linux__' -e '$a#endif'

echo "DONE"

0 comments on commit eaf2cef

Please sign in to comment.