Skip to content

Commit 8567891

Browse files
committed
Defined a bazel rule of cc_import_library to only accepts system library
and use `cc_import_library` rule to prevent including GPL code. Signed-off-by: Yong Tang <[email protected]>
1 parent a928008 commit 8567891

File tree

5 files changed

+42
-129
lines changed

5 files changed

+42
-129
lines changed

WORKSPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
workspace(name = "org_tensorflow")
2+
13
load("//tf:tf_configure.bzl", "tf_configure")
24
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
35

third_party/ffmpeg_2_8.BUILD

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ licenses(["notice"]) # LGPL v2.1+ license
55

66
exports_files(["LICENSE.md"])
77

8-
cc_library(
8+
load("@org_tensorflow//third_party:repo.bzl", "cc_import_library")
9+
10+
cc_import_library(
911
name = "ffmpeg",
10-
srcs = [
11-
],
1212
hdrs = [
1313
"libavformat/avformat.h",
1414
"libavformat/avio.h",
@@ -41,53 +41,14 @@ cc_library(
4141
"libswscale/swscale.h",
4242
"libswscale/version.h",
4343
],
44-
copts = [],
45-
defines = [],
46-
includes = [],
47-
linkopts = [
48-
"-L$(GENDIR)/external/ffmpeg_2_8",
49-
"-l:libavformat-ffmpeg.so.56",
50-
"-l:libavcodec-ffmpeg.so.56",
51-
"-l:libavutil-ffmpeg.so.54",
52-
"-l:libswscale-ffmpeg.so.3",
53-
],
54-
visibility = ["//visibility:public"],
55-
deps = [],
56-
data = [
44+
libraries = [
5745
"libavformat-ffmpeg.so.56",
5846
"libavcodec-ffmpeg.so.56",
5947
"libavutil-ffmpeg.so.54",
6048
"libswscale-ffmpeg.so.3",
6149
],
6250
)
6351

64-
# Stab library files for build to be successful
65-
# even when those files are not installed (e.g., Ubuntu 14.04)
66-
# In runtime (e.g., Ubuntu 18.04) system files will be used.
67-
genrule(
68-
name = "libavformat-ffmpeg_so_56",
69-
outs = ["libavformat-ffmpeg.so.56"],
70-
cmd = "echo '' | g++ -shared -fPIC -x c++ - -o $@",
71-
)
72-
73-
genrule(
74-
name = "libavcodec-ffmpeg_so_56",
75-
outs = ["libavcodec-ffmpeg.so.56"],
76-
cmd = "echo '' | g++ -shared -fPIC -x c++ - -o $@",
77-
)
78-
79-
genrule(
80-
name = "libavutil-ffmpeg_so_54",
81-
outs = ["libavutil-ffmpeg.so.54"],
82-
cmd = "echo '' | g++ -shared -fPIC -x c++ - -o $@",
83-
)
84-
85-
genrule(
86-
name = "libswscale-ffmpeg_so_3",
87-
outs = ["libswscale-ffmpeg.so.3"],
88-
cmd = "echo '' | g++ -shared -fPIC -x c++ - -o $@",
89-
)
90-
9152
genrule(
9253
name = "libavutil_avconfig_h",
9354
outs = ["libavutil/avconfig.h"],

third_party/ffmpeg_3_4.BUILD

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ licenses(["notice"]) # LGPL v2.1+ license
55

66
exports_files(["LICENSE.md"])
77

8-
cc_library(
8+
load("@org_tensorflow//third_party:repo.bzl", "cc_import_library")
9+
10+
cc_import_library(
911
name = "ffmpeg",
10-
srcs = [
11-
],
1212
hdrs = [
1313
"libavformat/avformat.h",
1414
"libavformat/avio.h",
@@ -39,53 +39,14 @@ cc_library(
3939
"libswscale/swscale.h",
4040
"libswscale/version.h",
4141
],
42-
copts = [],
43-
defines = [],
44-
includes = [],
45-
linkopts = [
46-
"-L$(GENDIR)/external/ffmpeg_3_4",
47-
"-l:libavformat.so.57",
48-
"-l:libavcodec.so.57",
49-
"-l:libavutil.so.55",
50-
"-l:libswscale.so.4",
51-
],
52-
visibility = ["//visibility:public"],
53-
deps = [],
54-
data = [
42+
libraries = [
5543
"libavformat.so.57",
5644
"libavcodec.so.57",
5745
"libavutil.so.55",
5846
"libswscale.so.4",
5947
],
6048
)
6149

62-
# Stab library files for build to be successful
63-
# even when those files are not installed (e.g., Ubuntu 14.04)
64-
# In runtime (e.g., Ubuntu 18.04) system files will be used.
65-
genrule(
66-
name = "libavformat_so_57",
67-
outs = ["libavformat.so.57"],
68-
cmd = "echo '' | g++ -shared -fPIC -x c++ - -o $@",
69-
)
70-
71-
genrule(
72-
name = "libavcodec_so_57",
73-
outs = ["libavcodec.so.57"],
74-
cmd = "echo '' | g++ -shared -fPIC -x c++ - -o $@",
75-
)
76-
77-
genrule(
78-
name = "libavutil_so_55",
79-
outs = ["libavutil.so.55"],
80-
cmd = "echo '' | g++ -shared -fPIC -x c++ - -o $@",
81-
)
82-
83-
genrule(
84-
name = "libswscale_so_4",
85-
outs = ["libswscale.so.4"],
86-
cmd = "echo '' | g++ -shared -fPIC -x c++ - -o $@",
87-
)
88-
8950
genrule(
9051
name = "libavutil_avconfig_h",
9152
outs = ["libavutil/avconfig.h"],

third_party/libav_9_20.BUILD

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ licenses(["notice"]) # LGPL v2.1+ license
55

66
exports_files(["LICENSE.md"])
77

8-
cc_library(
8+
load("@org_tensorflow//third_party:repo.bzl", "cc_import_library")
9+
10+
cc_import_library(
911
name = "libav",
10-
srcs = [
11-
],
1212
hdrs = [
1313
"libavformat/avformat.h",
1414
"libavformat/avio.h",
@@ -39,53 +39,14 @@ cc_library(
3939
"libswscale/swscale.h",
4040
"libswscale/version.h",
4141
],
42-
copts = [],
43-
defines = [],
44-
includes = [],
45-
linkopts = [
46-
"-L$(GENDIR)/external/libav_9_20",
47-
"-l:libavformat.so.54",
48-
"-l:libavcodec.so.54",
49-
"-l:libavutil.so.52",
50-
"-l:libswscale.so.2",
51-
],
52-
visibility = ["//visibility:public"],
53-
deps = [],
54-
data = [
42+
libraries = [
5543
"libavformat.so.54",
5644
"libavcodec.so.54",
5745
"libavutil.so.52",
5846
"libswscale.so.2",
5947
],
6048
)
6149

62-
# Stab library files for build to be successful
63-
# even when those files are not installed (e.g., Ubuntu 14.04)
64-
# In runtime (e.g., Ubuntu 18.04) system files will be used.
65-
genrule(
66-
name = "libavformat_so_54",
67-
outs = ["libavformat.so.54"],
68-
cmd = "echo '' | g++ -shared -fPIC -x c++ - -o $@",
69-
)
70-
71-
genrule(
72-
name = "libavcodec_so_54",
73-
outs = ["libavcodec.so.54"],
74-
cmd = "echo '' | g++ -shared -fPIC -x c++ - -o $@",
75-
)
76-
77-
genrule(
78-
name = "libavutil_so_52",
79-
outs = ["libavutil.so.52"],
80-
cmd = "echo '' | g++ -shared -fPIC -x c++ - -o $@",
81-
)
82-
83-
genrule(
84-
name = "libswscale_so_2",
85-
outs = ["libswscale.so.2"],
86-
cmd = "echo '' | g++ -shared -fPIC -x c++ - -o $@",
87-
)
88-
8950
genrule(
9051
name = "libavutil_avconfig_h",
9152
outs = ["libavutil/avconfig.h"],

third_party/repo.bzl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# cc_import_library is a replacement of cc_import in bazel,
2+
# The purposes are:
3+
# - Allows the specification of soname e.g., libavformat.so.57
4+
# - Restrict to only allow linking against for GPL licenses libraries,
5+
# so that no srcs files are used.
6+
def cc_import_library(
7+
name,
8+
hdrs,
9+
libraries,
10+
**kwargs):
11+
for library in libraries:
12+
native.genrule(
13+
name = "stub-" + library,
14+
outs = [library],
15+
cmd = "echo '' | g++ -shared -fPIC -x c++ - -o $@",
16+
)
17+
native.cc_library(
18+
name = name,
19+
srcs = [],
20+
hdrs = hdrs,
21+
copts = [],
22+
defines = [],
23+
includes = [],
24+
linkopts = ["-L$(GENDIR)/external/" + native.repository_name()[1:]] + ["-l:" + x for x in libraries],
25+
visibility = ["//visibility:public"],
26+
data = libraries,
27+
**kwargs
28+
)

0 commit comments

Comments
 (0)