Skip to content

Commit

Permalink
use bazel included runfiles cpp library
Browse files Browse the repository at this point in the history
  • Loading branch information
cerisier committed Jan 2, 2025
1 parent c6620b6 commit e94fc8f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion swift/runfiles/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cc_library(
":swift_hint",
],
deps = [
"@rules_cc//cc/runfiles",
"@bazel_tools//tools/cpp/runfiles",
],
)

Expand Down
16 changes: 8 additions & 8 deletions swift/runfiles/runfiles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "rules_cc/cc/runfiles/runfiles.h"
#include "tools/cpp/runfiles/runfiles.h"

static char *CopyStringToC(const std::string &str) {
char *cstr = static_cast<char *>(std::malloc(str.size() + 1));
Expand All @@ -26,7 +26,7 @@ extern "C" {
void *Runfiles_Create(const char *argv0, const char *source_repository,
char **error) {
std::string err;
auto *runfiles = rules_cc::cc::runfiles::Runfiles::Create(
auto *runfiles = bazel::tools::cpp::runfiles::Runfiles::Create(
std::string(argv0), std::string(source_repository), &err);
if (!runfiles && error) {
*error = CopyStringToC(err);
Expand All @@ -39,7 +39,7 @@ void *Runfiles_Create2(const char *argv0, const char *runfiles_manifest_file,
const char *runfiles_dir, const char *source_repository,
char **error) {
std::string err;
auto *runfiles = rules_cc::cc::runfiles::Runfiles::Create(
auto *runfiles = bazel::tools::cpp::runfiles::Runfiles::Create(
std::string(argv0), std::string(runfiles_manifest_file),
std::string(runfiles_dir), std::string(source_repository), &err);
if (!runfiles && error) {
Expand All @@ -50,21 +50,21 @@ void *Runfiles_Create2(const char *argv0, const char *runfiles_manifest_file,
}

char *Runfiles_Rlocation(void *handle, const char *path) {
auto *runfiles = static_cast<rules_cc::cc::runfiles::Runfiles *>(handle);
auto *runfiles = static_cast<bazel::tools::cpp::runfiles::Runfiles *>(handle);
std::string result = runfiles->Rlocation(std::string(path));
return CopyStringToC(result);
}

char *Runfiles_RlocationFrom(void *handle, const char *path,
const char *source_repository) {
auto *runfiles = static_cast<rules_cc::cc::runfiles::Runfiles *>(handle);
auto *runfiles = static_cast<bazel::tools::cpp::runfiles::Runfiles *>(handle);
std::string result =
runfiles->Rlocation(std::string(path), std::string(source_repository));
return CopyStringToC(result);
}

char **Runfiles_EnvVars(void *handle, size_t *size) {
auto *runfiles = static_cast<rules_cc::cc::runfiles::Runfiles *>(handle);
auto *runfiles = static_cast<bazel::tools::cpp::runfiles::Runfiles *>(handle);
auto &envVars = runfiles->EnvVars();
char **cArray =
static_cast<char **>(std::malloc(envVars.size() * 2 * sizeof(char *)));
Expand All @@ -81,13 +81,13 @@ char **Runfiles_EnvVars(void *handle, size_t *size) {

void *Runfiles_WithSourceRepository(void *handle,
const char *source_repository) {
auto *runfiles = static_cast<rules_cc::cc::runfiles::Runfiles *>(handle);
auto *runfiles = static_cast<bazel::tools::cpp::runfiles::Runfiles *>(handle);
auto runfiles_new = runfiles->WithSourceRepository(source_repository);
return runfiles_new.release();
}

void Runfiles_Destroy(void *handle) {
auto *runfiles = static_cast<rules_cc::cc::runfiles::Runfiles *>(handle);
auto *runfiles = static_cast<bazel::tools::cpp::runfiles::Runfiles *>(handle);
delete runfiles;
}

Expand Down

0 comments on commit e94fc8f

Please sign in to comment.