main_bin.cpp 1.1 KB

123456789101112131415161718192021222324252627282930
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "explorer/main.h"
  5. #include "llvm/ADT/SmallString.h"
  6. #include "llvm/Support/FileSystem.h"
  7. #include "llvm/Support/Path.h"
  8. auto main(int argc, char** argv) -> int {
  9. // This assumes execution from bazel, in runfiles.
  10. llvm::SmallString<256> prelude_path;
  11. if (std::error_code err = llvm::sys::fs::current_path(prelude_path)) {
  12. llvm::errs() << "Failed to get working directory: " << err.message();
  13. return 1;
  14. }
  15. llvm::sys::path::append(prelude_path, "explorer/data/prelude.carbon");
  16. // Behave as if the working directory is where `bazel run` was invoked.
  17. char* build_working_dir = getenv("BUILD_WORKING_DIRECTORY");
  18. if (build_working_dir != nullptr) {
  19. if (std::error_code err =
  20. llvm::sys::fs::set_current_path(build_working_dir)) {
  21. llvm::errs() << "Failed to set working directory: " << err.message();
  22. return 1;
  23. }
  24. }
  25. return Carbon::ExplorerMain(prelude_path, argc, argv);
  26. }