Skip to content

RUNFILES_DIR is not available in environment when running bazel run #3567

@preethamrn

Description

@preethamrn

What version of rules_go are you using?

v0.39.0

What version of gazelle are you using?

v0.30.0

What version of Bazel are you using?

6.2.0

Does this issue reproduce with the latest releases of all the above?

Yes

What operating system and processor architecture are you using?

macOS Ventura / arm64

Any other potentially useful information about your toolchain?

What did you do?

Using the following files:

// main.go
package main

import (
	"os"
	"fmt"
)

func main() {
	fmt.Println(os.Getenv("RUNFILES_DIR"))
}

# BUILD.bazel
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
    name = "go_default_library",
    srcs = ["main.go"],
    importpath = "github.com/example/project",
    visibility = ["//visibility:public"],
)

go_binary(
    name = "foo",
    embed = [":go_default_library"],
    visibility = ["//visibility:public"],
)

# WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Download the Go rules.
http_archive(
    name = "io_bazel_rules_go",
    sha256 = "6b65cb7917b4d1709f9410ffe00ecf3e160edf674b78c54a894471320862184f",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.39.0/rules_go-v0.39.0.zip",
        "https://github.com/bazelbuild/rules_go/releases/download/v0.39.0/rules_go-v0.39.0.zip",
    ],
)

# Load macros and repository rules.
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

# Declare indirect dependencies and register toolchains.
go_rules_dependencies()

go_register_toolchains(version = "1.19.3")

Run the following command

bazel run foo

What did you expect to see?

The output for RUNFILES_DIR

What did you see instead?

Empty string.
When I try running a similar method through bazel test I am able to get the correct output for RUNFILES_DIR

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions