Skip to content

Commit

Permalink
Implement runtime_deps (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelvigee authored Nov 21, 2023
1 parent f80265e commit 26a4235
Show file tree
Hide file tree
Showing 43 changed files with 479 additions and 309 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set up Go
uses: magnetikonline/action-golang-cache@v4
with:
go-version: ~1.21
go-version: 1.21.4
cache-key-suffix: -build

- name: Cache
Expand Down
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load("//backend/node", "yarn_toolchain")

go_toolchain(
name = "go",
version = "1.21.0",
version = "1.21.4",
architectures = [
"darwin_amd64",
"darwin_arm64",
Expand Down
54 changes: 25 additions & 29 deletions backend/go/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ def _find_go_work():
parts = heph.path.split(heph.pkg.dir())

prefix = "."
for i in range(0, len(parts)+1):
p = prefix+"/go.work"
for i in range(0, len(parts) + 1):
p = prefix + "/go.work"

if len(glob(p)) > 0:
return p

prefix += "/.."

fail("unable to locate work file from "+heph.pkg.dir())
fail("unable to locate work file from " + heph.pkg.dir())

def go_mod(
mod_pkgs = [],
Expand Down Expand Up @@ -166,7 +166,7 @@ def go_mod(
if work:
p = _find_go_work()
godeps_deps += [p]
godeps_deps += glob(p+".sum")
godeps_deps += glob(p + ".sum")

imports = target(
name = "_go_mod_gen_imports",
Expand All @@ -181,19 +181,17 @@ def go_mod(
(pkg, _, _) = heph.split(go)

mod_pkgs_gen = [
"//"+pkg+":_std_pkgs_*",
"//" + pkg + ":_std_pkgs_*",
"go_lib",
"go_build_bin",
"test",
"thirdparty",
"go-test",
"//thirdparty/go/**:_go_mod_download*"
"//thirdparty/go/**:_go_mod_download*",
]

for pkg in mod_pkgs+['//thirdparty/go']:
mod_pkgs_gen += [
pkg+"/**:_go_lib*",
]
for pkg in mod_pkgs + ["//thirdparty/go"]:
mod_pkgs_gen += [pkg + "/**:_go_lib*"]

# Add labels defined in cfg
for pkg in cfg.values():
Expand All @@ -203,21 +201,22 @@ def go_mod(
labels = pkg["test"]["run"]["labels"]
if type(labels) != "list":
labels = [labels]

mod_pkgs_gen += labels

mod_pkgs_gen += [
heph.pkg.addr()+"/**:_go_lib*",
heph.pkg.addr()+"/**:go_bin#build*",
heph.pkg.addr()+"/**:_go_test_lib*",
heph.pkg.addr()+"/**:_go_xtest_lib*",
heph.pkg.addr()+"/**:_go_testmain_lib*",
heph.pkg.addr()+"/**:_go_xtestmain_lib*",
heph.pkg.addr()+"/**:_go_gen_testmain*",
heph.pkg.addr()+"/**:_go_gen_xtestmain*",
heph.pkg.addr()+"/**:_go_test#build*",
heph.pkg.addr()+"/**:_go_xtest#build*",
heph.pkg.addr()+"/**:go_test*",
heph.pkg.addr()+"/**:go_xtest*",
heph.pkg.addr() + "/**:_go_lib*",
heph.pkg.addr() + "/**:go_bin#build*",
heph.pkg.addr() + "/**:_go_test_lib*",
heph.pkg.addr() + "/**:_go_xtest_lib*",
heph.pkg.addr() + "/**:_go_testmain_lib*",
heph.pkg.addr() + "/**:_go_xtestmain_lib*",
heph.pkg.addr() + "/**:_go_gen_testmain*",
heph.pkg.addr() + "/**:_go_gen_xtestmain*",
heph.pkg.addr() + "/**:_go_test#build*",
heph.pkg.addr() + "/**:_go_xtest#build*",
heph.pkg.addr() + "/**:go_test*",
heph.pkg.addr() + "/**:go_xtest*",
]

target(
Expand All @@ -228,7 +227,7 @@ def go_mod(
"deps": godeps_deps,
"cfg": godeps_cfg,
},
hash_deps = [imports, gomodsum, godeps_cfg],
hash_deps = [imports, gomodsum],
tools = godeps,
env = {
"GOOS": get_os(),
Expand Down Expand Up @@ -330,7 +329,7 @@ def go_library(
src_dep = None,
gen_embed = False,
):
pvt_name = name if name[0] == "_" else "_"+name
pvt_name = name if name[0] == "_" else "_" + name

p = dir + "/" if dir else ""

Expand Down Expand Up @@ -521,7 +520,7 @@ def go_build_bin(
tags = [],
flags = "",
deps = {},
hash_deps = {},
runtime_deps = None,
):
if not out:
out = heph.pkg.name()
Expand All @@ -536,14 +535,11 @@ def go_build_bin(
"std": _std_pkgs(os, arch),
}

if hash_deps and type(deps) != "dict":
hash_deps = {"hash_deps": hash_deps}

return target(
name = name,
doc = "Build {} {}/{} {}".format(heph.pkg.dir(), os, arch, " ".join(tags)).strip(),
deps = _deps | deps,
hash_deps = _deps | hash_deps,
runtime_deps = runtime_deps,
run = _go_gen_importcfg() + [
'go tool link -importcfg "$SANDBOX/importconfig" -o $SANDBOX/$OUT {} $SRC_MAIN'.format(
flags,
Expand Down
8 changes: 4 additions & 4 deletions backend/go/godeps/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ type PkgCfgVariant struct {
Name string `json:"name"`
PkgCfgCompileVariant
Link struct {
Flags string `json:"flags"`
Deps map[string]interface{} `json:"deps,omitempty"`
HashDeps map[string]interface{} `json:"hash_deps,omitempty"`
Flags string `json:"flags"`
Deps map[string]interface{} `json:"deps,omitempty"`
RuntimeDeps map[string]interface{} `json:"runtime_deps,omitempty"`
} `json:"link"`
}

Expand Down Expand Up @@ -112,7 +112,7 @@ func (c PkgCfg) UniqueLinkVariants(v PkgCfgVariant) []PkgCfgVariant {
continue
}

k := fmt.Sprintf("%v_%v_%#v_%#v", VID(variant), variant.Link.Flags, variant.Link.Deps, variant.Link.HashDeps)
k := fmt.Sprintf("%v_%v_%#v_%#v", VID(variant), variant.Link.Flags, variant.Link.Deps, variant.Link.RuntimeDeps)

if _, ok := m[k]; ok {
continue
Expand Down
2 changes: 1 addition & 1 deletion backend/go/godeps/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func generate() []RenderUnit {
ximportLibs = append(ximportLibs, t.Full())
}

xtestlib := testLibFactory(targetName("_go_xtest_lib", pkg.Variant), ximportLibs, pkg.ImportPath+"_test", pkg.XTestGoFiles, nil, append(pkg.EmbedPatterns, pkg.XTestEmbedPatterns...), libPkg, pkg.Variant)
xtestlib := testLibFactory(targetName("_go_xtest_lib", pkg.Variant), ximportLibs, pkg.ImportPath+"_test", pkg.XTestGoFiles, pkg.SFiles, pkg.XTestEmbedPatterns, libPkg, pkg.Variant)

depsLibs := make([]string, 0)
for _, p := range pkgXTestDeps {
Expand Down
24 changes: 10 additions & 14 deletions backend/go/godeps/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func listImports() {

fmt.Fprintf(os.Stderr, "found %v imports\n", len(p.Imports))
fmt.Fprintf(os.Stderr, "found %v test imports\n", len(p.TestImports))
fmt.Fprintf(os.Stderr, "found %v xtest imports\n", len(p.XTestImports))

rel, err := filepath.Rel(root, path)
if err != nil {
Expand Down Expand Up @@ -84,26 +85,21 @@ func listImports() {
}
}

fmt.Println("+++")

importsm := map[string]struct{}{}

fmt.Println("+++ Imports")
sort.Strings(p.Imports)
for _, i := range p.Imports {
importsm[i] = struct{}{}
fmt.Println(i)
}

fmt.Println("+++ TestImports")
sort.Strings(p.TestImports)
for _, i := range p.TestImports {
importsm[i] = struct{}{}
}

imports := make([]string, 0)
for i := range importsm {
imports = append(imports, i)
fmt.Println(i)
}

sort.Strings(imports)

for _, i := range imports {
fmt.Println("+++ XTestImports")
sort.Strings(p.XTestImports)
for _, i := range p.XTestImports {
fmt.Println(i)
}

Expand Down
4 changes: 2 additions & 2 deletions backend/go/godeps/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ func genVariant(v PkgCfgVariant, tags, linkflags, linkdeps bool) string {
s += ",\n deps=" + genDict(v.Link.Deps, 1, true)
}

if v.Link.HashDeps != nil {
s += ",\n hash_deps=" + genDict(v.Link.HashDeps, 1, true)
if v.Link.RuntimeDeps != nil {
s += ",\n runtime_deps=" + genDict(v.Link.RuntimeDeps, 1, true)
}
}

Expand Down
1 change: 1 addition & 0 deletions bootstrap/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func RunMode(ctx context.Context, e *scheduler.Scheduler, rrs targetrun.Requests
}
tdepsMap, err := e.ScheduleTargetRRsWithDeps(ctx, rrs, skip)
if err != nil {
fgDeps.DoneSem()
return err
}

Expand Down
2 changes: 1 addition & 1 deletion graph/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (d *DAG) GetOrderedAncestorsWithOutput(targets *Targets, includeRoot bool)
}

err := d.getOrderedAncestors(targets.Slice(), includeRoot, func(target *Target) {
deps := target.Deps.All().Merge(target.HashDeps)
deps := target.Deps.All().Merge(target.HashDeps).Merge(target.RuntimeDeps.All())
for _, dep := range deps.Targets {
maybeAddAllOuts(dep.Target, dep.Output)
}
Expand Down
Loading

0 comments on commit 26a4235

Please sign in to comment.