bazelbuild / rules_pkg

Bazel rules for creating packages of many types (zip, tar, deb, rpm, ...)
Apache License 2.0
216 stars 171 forks source link

no such attribute 'package_file_name' in '_real_pkg_tar' rule #767

Closed Topaz1618 closed 10 months ago

Topaz1618 commented 10 months ago

Hi, I want to use bazel to package my folder and facing below issue. Could you take a look? Is there any example of how to use this?

Error info

$ bazel build main:hello_package
ERROR: /home/topaz/Projects/BazelDemo/stage2/main/BUILD:8:8: //main:hello_package: no such attribute 'package_file_name' in '_real_pkg_tar' rule
ERROR: Skipping 'main:hello_package': Error evaluating 'main:hello_package': error loading package 'main': Package 'main' contains errors
WARNING: Target pattern parsing failed.
ERROR: Error evaluating 'main:hello_package': error loading package 'main': Package 'main' contains errors
INFO: Elapsed time: 0.139s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)

Bazel version

$ bazel version
Bazelisk version: v1.18.0
Build label: 6.4.0
Build target: bazel-out/aarch64-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Oct 19 17:07:17 2023 (1697735237)
Build timestamp: 1697735237
Build timestamp as int: 1697735237

Structure

$ tree -L 2
.
├── BUILD
├── main
│   ├── BUILD
│   └── hello.cc
└── WORKSPACE

WORKSPACE

$ cat WORKSPACE 
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "rules_pkg",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
        "https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
    ],
    sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8",
)
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
rules_pkg_dependencies()

main/BUILD

$ cat main/BUILD 
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")

cc_binary(
    name = "hello",
    srcs = ["hello.cc"],
)

pkg_tar(
    name = "hello_package",
    srcs = [
        ":hello",
    ],
    package_file_name = "hello.tar.gz"
)
aiuto commented 10 months ago

load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar") is unsupported, and not from rules_pkg Use @rules_pkg//pkg:tar.bzl", "pkg.tar")

Topaz1618 commented 10 months ago

Thank u. I've tried to build rpm using Bazel, and facing the bellow issue.

main/BUILD

$ cat main/BUILD 
load("@rules_pkg//pkg:rpm.bzl", "pkg_rpm")

cc_binary(
    name = "hello",
    srcs = ["hello.cc"],
)

pkg_rpm(
  name="hello_rpm",
  srcs = [":hello"],
  license = "Internal",
  package_file_name = "hello.rpm",
  summary = "test",
)

output

$ bazel build main:hello
INFO: Analyzed target //main:hello (1 packages loaded, 2 targets configured).
INFO: Found 1 target...
Target //main:hello up-to-date:
  bazel-bin/main/hello
INFO: Elapsed time: 0.183s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action

I can not find my rpm package by using this BUILD file.

$ find . -name "hello.rpm"
$

However, if I specify the out attribute get the below issue (The pkg_tar can specify "out" attribute)

$ bazel build main:hello
ERROR: /home/topaz/Projects/BazelDemo/stage4/main/BUILD:8:8: //main:hello_rpm: no such attribute 'out' in 'pkg_rpm' rule
ERROR: Skipping 'main:hello': Error evaluating 'main:hello': error loading package 'main': Package 'main' contains errors
WARNING: Target pattern parsing failed.
ERROR: Error evaluating 'main:hello': error loading package 'main': Package 'main' contains errors
INFO: Elapsed time: 0.112s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded)

Could u take a look anything wrong of the BUILD file

aiuto commented 10 months ago

If you want the rpm, you should do bazel build main:hello_rpm '

Also, find . won't work. Output is in bazel-bin, so you need find bazel-bin/. ...