I'm trying to download and build a project written in golang using nix
My nix file:
buildGoPackage {
name = "site";
goPackagePath = "git#github.com:username/rep.git";
src = fetchGit{
url = "git#github.com:username/rep.git";
};
}
run:
nix build -f test3.nix
error log:
last 8 log lines:
> unpacking sources
> unpacking source archive /nix/store/l1gsllgg693s46sk7b7qiwbnjysnbbz6-source
> source root is source
> patching sources
> configuring
> building
> Building subPackage git#github.com:user/rep.git
> go: modules disabled by GO111MODULE=off; see 'go help modules'
I think you should be using buildGoModule instead of buildGoPackage, as buildGoPackage is deprecated, according to the nixpkgs documentation for go.
Additionally, buildGoModule doesn't seem to set GO111MODULE=off.
Related
I am given a repository hosted on a private site, and it looks like this:
a-private-git.com/myrepo/
go/
go.mod
go.sum
bar.go
The repository is located at a-private-git.com/myrepo and the module file is: (Note that the module itself is actually located at a-private-git.com/myrepo/go)
module a-private-git.com/myrepo
Is it possible to include a specific commit/branch of this repository? Or do I need the provider of the repo to change it?
I've tried:
go get a-private-git.com/myrepo#v0.0.0-<commit time>-<commit hash>
> the module is added to go.mod, but when I build I get:
> no required module provides package a-private-git.com/myrepo; to add it:
> go get a-private-git.com/myrepo
go get a-private-git.com/myrepo/go#v0.0.0-<commit time>-<commit hash>
> module declares its path as: a-private-git.com/myrepo
> but was required as: a-private-git.com/myrepo/go
(Based on https://go.dev/doc/modules/managing-source)
go get a-private-git.com/myrepo/go#go/v0.0.0-<commit time>-<commit hash>
> invalid version: unknown revision go/v0.0.0-<commit time>-<commit hash>
The easieset way would be to simply 'go get' the commit hash you want:
go get a-private-git.com/myrepo#commit_hash
Alternatively you can use a branch name to get its latest commit:
go get a-private-git.com/myrepo#branch_name
I'm trying to run some grpc tests with bazel.
I'm using "google.golang.org/grpc/credentials/insecure" to dial insecurely.
When running bazel test ..., I get the following error:
no such package '#org_golang_google_grpc//credentials/insecure': BUILD file not found in directory 'credentials/insecure' of external repository #org_golang_google_grpc. Add a BUILD file to a directory to mark it as a package. and referenced by '//go/internal/handlers/helloworld:helloworld_test'
I am generating my BUILD files with gazelle which outputs this for the go_test
go_test(
name = "helloworld_test",
srcs = ["helloworld_test.go"],
deps = [
":helloworld",
"//protos/helloworld",
"#com_github_stretchr_testify//assert",
"#org_golang_google_grpc//:go_default_library",
"#org_golang_google_grpc//credentials/insecure",
"#org_golang_google_grpc//test/bufconn",
"#org_uber_go_zap//:zap",
"#org_uber_go_zap//zaptest",
],
)
My go.mod file contains the dep:
google.golang.org/grpc v1.47.0
My deps.bzl is auto generated by gazelle:
go_repository(
name = "org_golang_google_grpc",
importpath = "google.golang.org/grpc",
sum = "h1:9n77onPX5F3qfFCqjy9dhn8PbNQsIKeVU04J9G7umt8=",
version = "v1.47.0",
)
What am I missing?
In the WORKSPACE, the local go_repositories() generated by gazelle must be called before gazelle_dependencies(), which will
define an ancient version of org_golang_google_grpc if it doesn't
exist yet and the local go_repository for the newer version will be
silently ignored. Reference
I have a workspace where I use gazelle to generate my BUILD files and for some reason the com_github_ipfs_go_merkledag dependency is breaking the build when trying to resolve it's github.com/gogo/protobuf/gogoproto dependency. The setup and run is below.
Workspace:
# Declare indirect dependencies and init toolchains.
go_rules_dependencies()
go_register_toolchains(version = "1.16")
go_embed_data_dependencies()
load("#rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
rules_proto_dependencies()
rules_proto_toolchains()
load("#bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
gazelle_dependencies()
Commands:
bazel run //:gazelle
bazel run //:gazelle -- update-repos -from_file=go.mod
bazel build //...
Output:
...
no such package '#com_github_ipfs_go_merkledag//github.com/gogo/protobuf/gogoproto':
BUILD file not found in directory 'github.com/gogo/protobuf/gogoproto' of external repository #com_github_ipfs_go_merkledag.
Add a BUILD file to a directory to mark it as a package. and referenced by '#com_github_ipfs_go_merkledag//pb:merkledag_pb_go_proto'
...
Not sure what the solution for this is?
Add build directives to the go_repository to ignore
go_repository(
name = "com_github_ipfs_go_merkledag",
importpath = "github.com/ipfs/go-merkledag",
sum = "h1:ixNu/5MJSaT/Qs073T0/HsWKwnOoBgqSq1g+GaJIen0=",
version = "v0.4.0",
build_directives = [
"gazelle:proto disable",
],
)
I'm building a simple project in Meson Build.
While it is well documented how to create a dependency in Meson Build Documentation (With implicit assumption of UNIX / LINUX system) it is not clear how to link against arbitrary not on path library.
Let's I have the following project on Windows:
- ProjectFolder
- SrcFiles
- SrcFile1.c
- SrcFile2.c
- Lib
- MyLib1.lib
- MyLib2.lib
I want to create an executable based on SrcFile1.c and SrcFile2.c which is linked against pre built MyLib1.lib and MyLib2.lib.
What is the correct way to do so?
OK, I found solution on MesonBuild: How to define dependency to a library that cannot be found by pkg-config? on Yasushi Shoji's answer.
The only issue the dirs property requires Absolute Path.
Hence this is a sketch of what can be done:
# Constants
projectDir = meson.current_source_dir() # MESON_SOURCE_ROOT
buildDir = meson.current_build_dir() # MESON_BUILD_ROOT
lib1Path = join_paths(projectDir, 'Lib')
lib2Path = join_paths(projectDir, 'Lib')
objCCompiler = meson.get_compiler('c')
MyLib1 = objCCompiler.find_library('MyLib1', dirs : lib1Path)
MyLib2 = objCCompiler.find_library('MyLib1', dirs : lib1Pat2)
Now just to define the target build with the proper dependencies.
I'm on MacOS 10.13.2.
Go 1.10.
bazel 0.11.1
I need to compile a repo that has 2 projects (project1 and project2).
project1 has 2 subpacakges. p1lib and dep1
p1lib uses dep1.
I generate BUILD files with gazelle, files look ok.
gazelle -go_prefix=github.com/BazelBuildForGo
But when I run build I get an error that says that I'm missing direct dependency.
bazel build //project1
INFO: Analysed target //project1:project1 (3 packages loaded).
INFO: Found 1 target...
ERROR: /private/var/tmp/_bazel_user1/df78026a5ee0c7ed3d23dd05c3a3b1f7/external/com_github_wix_private_bazelbuildforgo/project1/p1lib/BUILD.bazel:3:1: GoCompile external/com_github_wix_private_bazelbuildforgo/project1/p1lib/darwin_amd64_stripped/go_default_library~/github.com/BazelBuildForGo/project1/p1lib.a failed (Exit 1)
2018/03/25 18:02:55 missing strict dependencies:
external/com_github_wix_private_bazelbuildforgo/project1/p1lib/p1lib.go: import of github.com/wix-private/BazelBuildForGo/project1/dep1, which is not a direct dependency
Target //project1:project1 failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.358s, Critical Path: 0.12s
FAILED: Build did NOT complete successfully
My project can be found here
https://github.com/wix-playground/BazelBuildForGo
I think the problem is that the import prefix you passed to Gazelle on the command line (github.com/BazelBuildForGo) is different from the imports in the .go files (github.com/wix-private/BazelBuildForGo). When Gazelle sees imports that are outside the current prefix, it will generate external dependencies for those imports, and those dependencies will be missing:
go_library(
name = "go_default_library",
srcs = ["p1lib.go"],
importpath = "github.com/BazelBuildForGo/project1/p1lib",
visibility = ["//visibility:public"],
deps = ["#com_github_wix_private_bazelbuildforgo//project1/dep1:go_default_library"],
)
The fix for this is pretty easy though. Just run Gazelle with the prefix github.com/wix-private/BazelBuildForGo. You actually already have this in //:gazelle, so just run that, then rebuild.
$ bazel run //:gazelle
$ bazel build //...
That will change the go_library rule above to this:
go_library(
name = "go_default_library",
srcs = ["p1lib.go"],
importpath = "github.com/wix-private/BazelBuildForGo/project1/p1lib",
visibility = ["//visibility:public"],
deps = ["//project1/dep1:go_default_library"],
)