Skip to content

Commit

Permalink
Allow C/C++ sources in "perl_xs" target. (#23)
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
  • Loading branch information
PiotrSikora committed Jan 13, 2022
1 parent 08f7452 commit d0f6982
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ platforms:
- "//..."
- "-//examples/cpan:IOTty"
- "-//examples/cpan:IOTtyXS"
- "-//examples/cpan_remote:fcgi_import_test"
- "-//examples/external_module:complex_deps"
test_targets:
- "//..."
- "-//examples/cpan_remote:fcgi_import_test"
- "-//examples/external_module:complex_deps"
10 changes: 10 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ register_toolchains(
"@rules_perl//:linux_toolchain",
"@rules_perl//:windows_toolchain"
)

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

http_archive(
name = "fcgi",
build_file = "//:examples/cpan_remote/fcgi.BUILD",
sha256 = "8cfa4e1b14fb8d5acaa22ced672c6af68c0a8e25dc2a9697a0ed7f4a4efb34e4",
strip_prefix = "FCGI-0.79",
url = "https://cpan.metacpan.org/authors/id/E/ET/ETHER/FCGI-0.79.tar.gz",
)
26 changes: 26 additions & 0 deletions examples/cpan_remote/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2021 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("//perl:perl.bzl", "perl_test")

package(default_visibility = ["//visibility:public"])

perl_test(
name = "fcgi_import_test",
srcs = ["fcgi_import_test.t"],
env = {
"PERL5LIB": "../fcgi/lib:../fcgi/arch",
},
deps = ["@fcgi//:FCGI"],
)
66 changes: 66 additions & 0 deletions examples/cpan_remote/fcgi.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright 2021 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_perl//perl:perl.bzl", "perl_library", "perl_xs")

perl_library(
name = "FCGI",
srcs = [
"lib/FCGI.pm",
":FCGIXS",
],
visibility = ["//visibility:public"],
)

genrule(
name = "install",
srcs = ["FCGI.pm"],
outs = ["lib/FCGI.pm"],
cmd = "cp $< $@",
)

perl_xs(
name = "FCGIXS",
srcs = ["FCGI.xs"],
cc_srcs = [
"fcgiapp.c",
"os_unix.c",
],
defines = [
"HAVE_LIMITS_H",
"HAVE_NETDB_H",
"HAVE_NETINET_IN_H",
"HAVE_SYS_SOCKET_H",
"HAVE_SYS_TIME_H",
"HAVE_SYS_TYPES_H",
"HAVE_UNISTD_H",
"VERSION=\"0.79\"",
"XS_VERSION=\"0.79\"",
],
output_loc = "arch/auto/FCGI/FCGI.so",
textual_hdrs = [
"fastcgi.h",
"fcgi_config.h",
"fcgiapp.h",
"fcgimisc.h",
"fcgios.h",
],
typemaps = ["typemap"],
)

genrule(
name = "empty",
outs = ["fcgi_config.h"],
cmd = "touch $@",
)
20 changes: 20 additions & 0 deletions examples/cpan_remote/fcgi_import_test.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2021 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

use strict;
use warnings;

use FCGI;

1;
3 changes: 2 additions & 1 deletion perl/perl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def _perl_xs_cc_lib(ctx, toolchain, srcs):
name = ctx.label.name,
feature_configuration = feature_configuration,
cc_toolchain = cc_toolchain,
srcs = srcs,
srcs = srcs + ctx.files.cc_srcs,
defines = ctx.attr.defines,
additional_inputs = textual_hdrs,
private_hdrs = xs_headers.to_list(),
Expand Down Expand Up @@ -309,6 +309,7 @@ perl_test = rule(
perl_xs = rule(
attrs = {
"srcs": attr.label_list(allow_files = [".xs"]),
"cc_srcs": attr.label_list(allow_files = [".c", ".cc"]),
"textual_hdrs": attr.label_list(allow_files = True),
"typemaps": attr.label_list(allow_files = True),
"output_loc": attr.string(),
Expand Down

0 comments on commit d0f6982

Please sign in to comment.