rules_perl icon indicating copy to clipboard operation
rules_perl copied to clipboard

Build rules_perl for ppc64le.

Open Sunidhi-Gaonkar1 opened this issue 11 months ago • 2 comments

Hello team, We are working on building ray on Power architecture and it has a dependency on rules_perl. There is no perl tarball released for Power by relocatable_perl. Is there a way to use system installed perl instead of fetching it from relocatable_perl? Any pointers will be helpful. Thank you.

Sunidhi-Gaonkar1 avatar Jan 08 '25 14:01 Sunidhi-Gaonkar1

It's been a while since I've done something like this and Bazel has changed, but I believe you can do this by using a genrule like:

genrule(
    name = "my_perl_rule",
    srcs = ["my_script.pl"],
    outs = ["output.txt"],
    tools = ["/usr/bin/perl"],  # Path to your host's Perl interpreter
    cmd = "$(location :perl) $(location my_script.pl) > $@",
)

This requires that each system you are running this on has the same location of Perl, preferably the same version of Perl, and all required modules are installed for that version.

skeletonkey avatar Jan 11 '25 14:01 skeletonkey

@skeletonkey , Thank you for your response and sorry for the delayed reply. facing the following issue after using genrule.

:/rules_perl# bazel build :all
ERROR: /rules_perl/BUILD:19:8: //:my_perl_rule: invalid label '/usr/bin/perl' in element 0 of attribute 'tools' in 'genrule' rule: invalid target name '/usr/bin/perl': target names may not start with '/'
ERROR: package contains errors: : //:my_perl_rule: invalid label '/usr/bin/perl' in element 0 of attribute 'tools' in 'genrule' rule: invalid target name '/usr/bin/perl': target names may not start with '/'

Looking into it further, if you have any suggestions please let me know. Thank you.

Sunidhi-Gaonkar1 avatar Feb 18 '25 04:02 Sunidhi-Gaonkar1

HI @skeletonkey,

We're making good progress integrating rules_perl—we're now able to successfully build most of the targets after adding a genrule for the required Perl headers. However, we're encountering an issue with one specific target: examples/cpan_remote.

When running bazel build //..., this target fails with the following error:

ERROR: /root/.cache/bazel/_bazel_root/.../external/+perl_dev_repositories+fcgi/BUILD.bazel:37:8: Compiling external/+perl_dev_repositories+fcgi/_objs/execroot/external/+perl_dev_repositories+fcgi/FCGI.c failed: fatal error: EXTERN.h: No such file or directory

Full error: external/+perl_dev_repositories+fcgi/FCGI.xs:3:10: fatal error: EXTERN.h: No such file or directory compilation terminated.

We verified that the file EXTERN.h exists at /usr/lib64/perl5/CORE/EXTERN.h on the system, but Bazel is not picking it up during the build of this external dependency (@+perl_dev_repositories+fcgi).

We've tried a few workarounds, including:

Adding a cc_library for system Perl headers and linking it as a dependency

Manually specifying copts = ["-I/usr/lib64/perl5/CORE"] in relevant targets

Overriding toolchains to prevent Bazel from fetching its own prebuilt Perl toolchain

However, none of these attempts resolved the issue for this specific target. The rest of the build completes successfully, and if we exclude examples/cpan_remote, we’re able to run both bazel build //... and bazel test //... without any errors.

Let us know if you’ve seen something similar before or if you’d recommend a specific way to override toolchain behavior for this case.

Thanks!

sandeepgupta12 avatar May 12 '25 11:05 sandeepgupta12

Try this branch: https://github.com/bazel-contrib/rules_perl/tree/ppc64le Let me know if it helps solve your blocker.

skeletonkey avatar May 20 '25 02:05 skeletonkey

Hi @skeletonkey, thanks for your help. I am still getting same error:

bazel build //...

ERROR: /root/.cache/bazel/_bazel_root/cbf541a54b901d5596002dfdd311019c/external/+perl_dev_repositories+fcgi/BUILD.bazel:43:8: Compiling external/+perl_dev_repositories+fcgi/_objs/execroot/external/+perl_dev_repositories+fcgi/FCGI.c failed: (Exit 1): gcc failed: error executing CppCompile command (from target @@+perl_dev_repositories+fcgi//:FCGIXS) /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -MD -MF ... (remaining 32 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging external/+perl_dev_repositories+fcgi/FCGI.xs:3:10: fatal error: EXTERN.h: No such file or directory compilation terminated. INFO: Elapsed time: 0.222s, Critical Path: 0.03s INFO: 2 processes: 2 internal. ERROR: Build did NOT complete successfully FAILED: Fetching repository @@+perl_repositories+perl_darwin_arm64; Downloading perl Fetching repository @@+perl_repositories+perl_darwin_amd64; Downloading perl Fetching repository @@+perl_repositories+perl_linux_arm64; Downloading perl Fetching repository @@+perl_repositories+perl_linux_amd64; Downloading perl Fetching repository @@+perl_repositories+perl_windows_x86_64; Downloading perl

I have made the following changes for toolchain. Please review them as well

diff --git a/MODULE.bazel b/MODULE.bazel diff --git a/MODULE.bazel b/MODULE.bazel index d5f0bfe..df46c5a 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -22,6 +22,7 @@ use_repo( "perl_windows_x86_64", )

+register_toolchains("//perl/system:perl_ppc64le_toolchain") register_toolchains( "@rules_perl//perl:perl_darwin_arm64_toolchain", "@rules_perl//perl:perl_darwin_amd64_toolchain", diff --git a/perl/system/BUILD.bazel b/perl/system/BUILD.bazel new file mode 100644 index 0000000..ce184bb --- /dev/null +++ b/perl/system/BUILD.bazel @@ -0,0 +1,38 @@ +load("//perl:toolchain.bzl", "perl_toolchain") + +toolchain_type(name = "toolchain_type") + +genrule( +name = "copy_perl_to_bin", +outs = ["perl"], +cmd = "cp /usr/bin/perl $@", +executable = True, +visibility = ["//visibility:public"], +) + +genrule( +name = "copy_xsubpp_to_bin", +outs = ["xsubpp"], +cmd = "cp /usr/bin/xsubpp $@ +executable = True, +visibility = ["//visibility:public"], +) + +perl_toolchain( +name = "perl_ppc64le_toolchain_impl", +runtime = [ +":copy_perl_to_bin", +":copy_xsubpp_to_bin", +], +# perl_include_paths = ["/usr/lib64/perl5/CORE"], +visibility = ["//visibility:public"], +) + +toolchain( +name = "perl_ppc64le_toolchain", +toolchain = ":perl_ppc64le_toolchain_impl", +toolchain_type = "//perl:toolchain_type", +#target_compatible_with = ["@platforms//cpu:ppc64le"], +visibility = ["//visibility:public"], +) +

sandeepgupta12 avatar May 21 '25 12:05 sandeepgupta12