|
| 1 | +//===--- Paths.h - Swift Runtime path utility functions ---------*- C++ -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2022 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | +// |
| 13 | +// Functions that obtain paths that might be useful within the runtime. |
| 14 | +// |
| 15 | +//===----------------------------------------------------------------------===// |
| 16 | + |
| 17 | +#ifndef SWIFT_RUNTIME_UTILS_H |
| 18 | +#define SWIFT_RUNTIME_UTILS_H |
| 19 | + |
| 20 | +#include "swift/Runtime/Config.h" |
| 21 | + |
| 22 | +/// Return the path of the libswiftCore library. |
| 23 | +/// |
| 24 | +/// This can be used to locate files that are installed alongside the Swift |
| 25 | +/// runtime library. |
| 26 | +/// |
| 27 | +/// \return A string containing the full path to libswiftCore. The string is |
| 28 | +/// owned by the runtime and should not be freed. |
| 29 | +SWIFT_RUNTIME_EXPORT |
| 30 | +const char * |
| 31 | +swift_getRuntimeLibraryPath(); |
| 32 | + |
| 33 | +/// Return the path of the Swift root. |
| 34 | +/// |
| 35 | +/// If the path to libswiftCore is `/usr/local/swift/lib/libswiftCore.dylib`, |
| 36 | +/// this function would return `/usr/local/swift`. |
| 37 | +/// |
| 38 | +/// The path returned here can be overridden by setting the environment variable |
| 39 | +/// SWIFT_ROOT. |
| 40 | +/// |
| 41 | +/// \return A string containing the full path to the Swift root directory, based |
| 42 | +/// either on the location of the Swift runtime, or on the `SWIFT_ROOT` |
| 43 | +/// environment variable if set. The string is owned by the runtime |
| 44 | +/// and should not be freed. |
| 45 | +SWIFT_RUNTIME_EXPORT |
| 46 | +const char * |
| 47 | +swift_getRootPath(); |
| 48 | + |
| 49 | +/// Return the path of the specified auxiliary executable. |
| 50 | +/// |
| 51 | +/// This function will search for the auxiliary executable in the following |
| 52 | +/// paths: |
| 53 | +/// |
| 54 | +/// <swift-root>/libexec/swift/<platform>/<name> |
| 55 | +/// <swift-root>/libexec/swift/<name> |
| 56 | +/// <swift-root>/bin/<name> |
| 57 | +/// <swift-root>/<name> |
| 58 | +/// |
| 59 | +/// It will return the first of those that exists, but it does not test that |
| 60 | +/// the file is indeed executable. |
| 61 | +/// |
| 62 | +/// On Windows, it will automatically add `.exe` to the name, which means you |
| 63 | +/// do not need to special case the name for Windows. |
| 64 | +/// |
| 65 | +/// If you are using this function to locate a utility program for use by the |
| 66 | +/// runtime, you should provide a way to override its location using an |
| 67 | +/// environment variable. |
| 68 | +/// |
| 69 | +/// If the executable cannot be found, it will return nullptr. |
| 70 | +/// |
| 71 | +/// \param name The name of the executable to locate. |
| 72 | +/// |
| 73 | +/// \return A string containing the full path to the executable. This string |
| 74 | +/// should be released with `free()` when no longer required. |
| 75 | +SWIFT_RUNTIME_EXPORT |
| 76 | +char * |
| 77 | +swift_copyAuxiliaryExecutablePath(const char *name); |
| 78 | + |
| 79 | +#endif // SWIFT_RUNTIME_PATHS_H |
0 commit comments