Skip to content

Commit ba59eb0

Browse files
authored
[FEAT] Removed C code already ported to Rust (#1738)
* Removal: Removed redundant C code already ported to Rust * Removal: C formatting * Removal: More Removal and CI issues in Mac * Removal: CI issues in Mac * Removal: Changes due to Rebase * Removal: Failing CI on mac * Removal: Failing regression test on dvdraw
1 parent 3f44115 commit ba59eb0

28 files changed

+199
-4217
lines changed

docs/COMPILATION.MD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ sudo make install
113113

114114
`cmake` also accepts the options:
115115
`-DWITH_OCR=ON` to enable OCR
116-
`-DWITHOUT_RUST=ON` to disable rust.
117116
`-DWITH_HARDSUBX=ON` to enable burned-in subtitles
118117

119118
([OPTIONAL] For hardsubx, you also need to set these environment variables correctly according to your machine)
@@ -176,7 +175,6 @@ make
176175

177176
`cmake` also accepts the options:
178177
`-DWITH_OCR=ON` to enable OCR
179-
`-DWITHOUT_RUST=ON` to disable rust.
180178
`-DWITH_HARDSUBX=ON` to enable burned-in subtitles
181179

182180
#### Standard compilation through Autoconf scripts:

docs/using_cmake_build.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,5 @@ cmake -DWITH_OCR=ON ../src/
3232
If you want to build CCExtractor with HARDSUBX support
3333
cmake -DWITH_HARDSUBX=ON ../src/
3434

35-
If you want to build CCExtractor with rust disabled you need to pass
36-
cmake -DWITHOUT_RUST=ON ../src/
37-
3835
Hint for looking all the things you want to set from outside
3936
cmake -LAH ../src/

linux/Makefile.am

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,7 @@ ccextractor_LDADD += $(TESS_LIB)
327327
ccextractor_LDADD += $(LEPT_LIB)
328328
endif
329329

330-
if WITH_RUST
331330
ccextractor_LDADD += ./rust/@RUST_TARGET_SUBDIR@/libccx_rust.a
332-
else
333-
ccextractor_CFLAGS += -DDISABLE_RUST
334-
ccextractor_CPPFLAGS += -DDISABLE_RUST
335-
endif
336331

337332
if DEBUG_RELEASE
338333
CARGO_RELEASE_ARGS=

linux/build

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ while [[ $# -gt 0 ]]; do
1111
RUST_LIB="rust/debug/libccx_rust.a"
1212
shift
1313
;;
14-
-without-rust)
15-
WITHOUT_RUST=true
16-
shift
17-
;;
1814
-hardsubx)
1915
HARDSUBX=true
2016
RUST_FEATURES="--features hardsubx_ocr"
@@ -90,34 +86,29 @@ echo "Running pre-build script..."
9086
./pre-build.sh
9187
echo "Trying to compile..."
9288

93-
if [ "$WITHOUT_RUST" = true ]; then
94-
echo "Building without rust files..."
95-
BLD_FLAGS="$BLD_FLAGS -DDISABLE_RUST"
96-
else
97-
BLD_LINKER="$BLD_LINKER ./libccx_rust.a"
98-
echo "Checking for cargo..."
99-
if ! [ -x "$(command -v cargo)" ]; then
100-
echo 'Error: cargo is not installed.' >&2
101-
exit 1
102-
fi
103-
104-
rustc_version="$(rustc --version)"
105-
semver=( ${rustc_version//./ } )
106-
version="${semver[1]}.${semver[2]}.${semver[3]}"
107-
MSRV="1.54.0"
108-
if [ "$(printf '%s\n' "$MSRV" "$version" | sort -V | head -n1)" = "$MSRV" ]; then
109-
echo "rustc >= MSRV(${MSRV})"
110-
else
111-
echo "Minimum supported rust version(MSRV) is ${MSRV}, please upgrade rust"
112-
exit 1
113-
fi
114-
115-
echo "Building rust files..."
116-
(cd ../src/rust && CARGO_TARGET_DIR=../../linux/rust cargo build $RUST_PROFILE $RUST_FEATURES) || { echo "Failed. " ; exit 1; }
89+
BLD_LINKER="$BLD_LINKER ./libccx_rust.a"
90+
echo "Checking for cargo..."
91+
if ! [ -x "$(command -v cargo)" ]; then
92+
echo 'Error: cargo is not installed.' >&2
93+
exit 1
94+
fi
11795

118-
cp $RUST_LIB ./libccx_rust.a
96+
rustc_version="$(rustc --version)"
97+
semver=( ${rustc_version//./ } )
98+
version="${semver[1]}.${semver[2]}.${semver[3]}"
99+
MSRV="1.54.0"
100+
if [ "$(printf '%s\n' "$MSRV" "$version" | sort -V | head -n1)" = "$MSRV" ]; then
101+
echo "rustc >= MSRV(${MSRV})"
102+
else
103+
echo "Minimum supported rust version(MSRV) is ${MSRV}, please upgrade rust"
104+
exit 1
119105
fi
120106

107+
echo "Building rust files..."
108+
(cd ../src/rust && CARGO_TARGET_DIR=../../linux/rust cargo build $RUST_PROFILE $RUST_FEATURES) || { echo "Failed. " ; exit 1; }
109+
110+
cp $RUST_LIB ./libccx_rust.a
111+
121112
echo "Building ccextractor"
122113
out=$((LC_ALL=C gcc $BLD_FLAGS $BLD_INCLUDE -o ccextractor $BLD_SOURCES $BLD_LINKER)2>&1)
123114
res=$?

mac/Makefile.am

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,8 @@ ccextractor_LDADD += $(TESS_LIB)
300300
ccextractor_LDADD += $(LEPT_LIB)
301301
endif
302302

303-
if WITH_RUST
304303
ccextractor_LDADD += ./rust/@RUST_TARGET_SUBDIR@/libccx_rust.a
305-
else
306-
ccextractor_CFLAGS += -DDISABLE_RUST
307-
ccextractor_CPPFLAGS += -DDISABLE_RUST
308-
endif
304+
309305

310306
if DEBUG_RELEASE
311307
CARGO_RELEASE_ARGS=

mac/build.command

Lines changed: 172 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,183 @@
11
#!/bin/bash
22
cd `dirname $0`
3-
BLD_FLAGS="-std=gnu99 -Wno-write-strings -Wno-pointer-sign -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -Dfopen64=fopen -Dopen64=open -Dlseek64=lseek -DFT2_BUILD_LIBRARY -DGPAC_DISABLE_VTT -DGPAC_DISABLE_OD_DUMP -DGPAC_DISABLE_REMOTERY -DNO_GZIP -DDISABLE_RUST"
4-
[[ $1 = "OCR" ]] && BLD_FLAGS="$BLD_FLAGS -DENABLE_OCR"
3+
4+
RUST_LIB="rust/release/libccx_rust.a"
5+
RUST_PROFILE="--release"
6+
RUST_FEATURES=""
7+
8+
# Parse command line arguments
9+
while [[ $# -gt 0 ]]; do
10+
case $1 in
11+
OCR)
12+
ENABLE_OCR=true
13+
shift
14+
;;
15+
-debug)
16+
DEBUG=true
17+
RUST_PROFILE=""
18+
RUST_LIB="rust/debug/libccx_rust.a"
19+
shift
20+
;;
21+
-hardsubx)
22+
HARDSUBX=true
23+
RUST_FEATURES="--features hardsubx_ocr"
24+
shift
25+
;;
26+
-*)
27+
echo "Unknown option $1"
28+
exit 1
29+
;;
30+
esac
31+
done
32+
33+
BLD_FLAGS="-std=gnu99 -Wno-write-strings -Wno-pointer-sign -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -Dfopen64=fopen -Dopen64=open -Dlseek64=lseek -DFT2_BUILD_LIBRARY -DGPAC_DISABLE_VTT -DGPAC_DISABLE_OD_DUMP -DGPAC_DISABLE_REMOTERY -DNO_GZIP"
34+
35+
# Add debug flags if needed
36+
if [[ "$DEBUG" == "true" ]]; then
37+
BLD_FLAGS="$BLD_FLAGS -g -fsanitize=address"
38+
fi
39+
40+
# Add OCR support if requested
41+
if [[ "$ENABLE_OCR" == "true" ]]; then
42+
BLD_FLAGS="$BLD_FLAGS -DENABLE_OCR"
43+
fi
44+
45+
# Add hardsubx support if requested
46+
if [[ "$HARDSUBX" == "true" ]]; then
47+
BLD_FLAGS="$BLD_FLAGS -DENABLE_HARDSUBX"
48+
fi
49+
550
BLD_INCLUDE="-I../src/ -I../src/lib_ccx -I../src/lib_hash -I../src/thirdparty/libpng -I../src/thirdparty -I../src/thirdparty/zlib -I../src/thirdparty/freetype/include `pkg-config --cflags --silence-errors gpac`"
6-
[[ $1 = "OCR" ]] && BLD_INCLUDE="$BLD_INCLUDE `pkg-config --cflags --silence-errors tesseract`"
51+
52+
if [[ "$ENABLE_OCR" == "true" ]]; then
53+
BLD_INCLUDE="$BLD_INCLUDE `pkg-config --cflags --silence-errors tesseract`"
54+
fi
55+
756
SRC_CCX="$(find ../src/lib_ccx -name '*.c')"
857
SRC_LIB_HASH="$(find ../src/thirdparty/lib_hash -name '*.c')"
958
SRC_LIBPNG="$(find ../src/thirdparty/libpng -name '*.c')"
1059
SRC_UTF8="../src/thirdparty/utf8proc/utf8proc.c"
1160
SRC_ZLIB="$(find ../src/thirdparty/zlib -name '*.c')"
1261
SRC_FREETYPE="../src/thirdparty/freetype/autofit/autofit.c \
13-
../src/thirdparty/freetype/base/ftbase.c \
14-
../src/thirdparty/freetype/base/ftbbox.c \
15-
../src/thirdparty/freetype/base/ftbdf.c \
16-
../src/thirdparty/freetype/base/ftbitmap.c \
17-
../src/thirdparty/freetype/base/ftcid.c \
18-
../src/thirdparty/freetype/base/ftfntfmt.c \
19-
../src/thirdparty/freetype/base/ftfstype.c \
20-
../src/thirdparty/freetype/base/ftgasp.c \
21-
../src/thirdparty/freetype/base/ftglyph.c \
22-
../src/thirdparty/freetype/base/ftgxval.c \
23-
../src/thirdparty/freetype/base/ftinit.c \
24-
../src/thirdparty/freetype/base/ftlcdfil.c \
25-
../src/thirdparty/freetype/base/ftmm.c \
26-
../src/thirdparty/freetype/base/ftotval.c \
27-
../src/thirdparty/freetype/base/ftpatent.c \
28-
../src/thirdparty/freetype/base/ftpfr.c \
29-
../src/thirdparty/freetype/base/ftstroke.c \
30-
../src/thirdparty/freetype/base/ftsynth.c \
31-
../src/thirdparty/freetype/base/ftsystem.c \
32-
../src/thirdparty/freetype/base/fttype1.c \
33-
../src/thirdparty/freetype/base/ftwinfnt.c \
34-
../src/thirdparty/freetype/bdf/bdf.c \
35-
../src/thirdparty/freetype/bzip2/ftbzip2.c \
36-
../src/thirdparty/freetype/cache/ftcache.c \
37-
../src/thirdparty/freetype/cff/cff.c \
38-
../src/thirdparty/freetype/cid/type1cid.c \
39-
../src/thirdparty/freetype/gzip/ftgzip.c \
40-
../src/thirdparty/freetype/lzw/ftlzw.c \
41-
../src/thirdparty/freetype/pcf/pcf.c \
42-
../src/thirdparty/freetype/pfr/pfr.c \
43-
../src/thirdparty/freetype/psaux/psaux.c \
44-
../src/thirdparty/freetype/pshinter/pshinter.c \
45-
../src/thirdparty/freetype/psnames/psnames.c \
46-
../src/thirdparty/freetype/raster/raster.c \
47-
../src/thirdparty/freetype/sfnt/sfnt.c \
48-
../src/thirdparty/freetype/smooth/smooth.c \
49-
../src/thirdparty/freetype/truetype/truetype.c \
50-
../src/thirdparty/freetype/type1/type1.c \
51-
../src/thirdparty/freetype/type42/type42.c \
52-
../src/thirdparty/freetype/winfonts/winfnt.c"
53-
BLD_SOURCES="../src/ccextractor.c $SRC_API $SRC_CCX $SRC_LIB_HASH $SRC_LIBPNG $SRC_UTF8 $SRC_ZLIB $SRC_ZVBI $SRC_FREETYPE"
54-
BLD_LINKER="-lm -liconv -lpthread -ldl `pkg-config --libs --silence-errors tesseract` `pkg-config --libs --silence-errors gpac`"
55-
[[ $1 = "OCR" ]] && BLD_LINKER="$BLD_LINKER `pkg-config --libs --silence-errors tesseract` `pkg-config --libs --silence-errors lept`"
62+
../src/thirdparty/freetype/base/ftbase.c \
63+
../src/thirdparty/freetype/base/ftbbox.c \
64+
../src/thirdparty/freetype/base/ftbdf.c \
65+
../src/thirdparty/freetype/base/ftbitmap.c \
66+
../src/thirdparty/freetype/base/ftcid.c \
67+
../src/thirdparty/freetype/base/ftfntfmt.c \
68+
../src/thirdparty/freetype/base/ftfstype.c \
69+
../src/thirdparty/freetype/base/ftgasp.c \
70+
../src/thirdparty/freetype/base/ftglyph.c \
71+
../src/thirdparty/freetype/base/ftgxval.c \
72+
../src/thirdparty/freetype/base/ftinit.c \
73+
../src/thirdparty/freetype/base/ftlcdfil.c \
74+
../src/thirdparty/freetype/base/ftmm.c \
75+
../src/thirdparty/freetype/base/ftotval.c \
76+
../src/thirdparty/freetype/base/ftpatent.c \
77+
../src/thirdparty/freetype/base/ftpfr.c \
78+
../src/thirdparty/freetype/base/ftstroke.c \
79+
../src/thirdparty/freetype/base/ftsynth.c \
80+
../src/thirdparty/freetype/base/ftsystem.c \
81+
../src/thirdparty/freetype/base/fttype1.c \
82+
../src/thirdparty/freetype/base/ftwinfnt.c \
83+
../src/thirdparty/freetype/bdf/bdf.c \
84+
../src/thirdparty/freetype/bzip2/ftbzip2.c \
85+
../src/thirdparty/freetype/cache/ftcache.c \
86+
../src/thirdparty/freetype/cff/cff.c \
87+
../src/thirdparty/freetype/cid/type1cid.c \
88+
../src/thirdparty/freetype/gzip/ftgzip.c \
89+
../src/thirdparty/freetype/lzw/ftlzw.c \
90+
../src/thirdparty/freetype/pcf/pcf.c \
91+
../src/thirdparty/freetype/pfr/pfr.c \
92+
../src/thirdparty/freetype/psaux/psaux.c \
93+
../src/thirdparty/freetype/pshinter/pshinter.c \
94+
../src/thirdparty/freetype/psnames/psnames.c \
95+
../src/thirdparty/freetype/raster/raster.c \
96+
../src/thirdparty/freetype/sfnt/sfnt.c \
97+
../src/thirdparty/freetype/smooth/smooth.c \
98+
../src/thirdparty/freetype/truetype/truetype.c \
99+
../src/thirdparty/freetype/type1/type1.c \
100+
../src/thirdparty/freetype/type42/type42.c \
101+
../src/thirdparty/freetype/winfonts/winfnt.c"
102+
103+
BLD_SOURCES="../src/ccextractor.c $SRC_CCX $SRC_LIB_HASH $SRC_LIBPNG $SRC_UTF8 $SRC_ZLIB $SRC_FREETYPE"
104+
105+
BLD_LINKER="-lm -liconv -lpthread -ldl `pkg-config --libs --silence-errors gpac`"
106+
107+
if [[ "$ENABLE_OCR" == "true" ]]; then
108+
BLD_LINKER="$BLD_LINKER `pkg-config --libs --silence-errors tesseract` `pkg-config --libs --silence-errors lept`"
109+
fi
110+
111+
if [[ "$HARDSUBX" == "true" ]]; then
112+
BLD_LINKER="$BLD_LINKER -lswscale -lavutil -pthread -lavformat -lavcodec -lavfilter"
113+
fi
56114

115+
echo "Running pre-build script..."
57116
./pre-build.sh
58-
gcc $BLD_FLAGS $BLD_INCLUDE -o ccextractor $BLD_SOURCES $BLD_LINKER
117+
echo "Trying to compile..."
118+
119+
# Check for cargo
120+
echo "Checking for cargo..."
121+
if ! [ -x "$(command -v cargo)" ]; then
122+
echo 'Error: cargo is not installed.' >&2
123+
exit 1
124+
fi
125+
126+
# Check rust version
127+
rustc_version="$(rustc --version)"
128+
semver=( ${rustc_version//./ } )
129+
version="${semver[1]}.${semver[2]}.${semver[3]}"
130+
MSRV="1.54.0"
131+
if [ "$(printf '%s\n' "$MSRV" "$version" | sort -V | head -n1)" = "$MSRV" ]; then
132+
echo "rustc >= MSRV(${MSRV})"
133+
else
134+
echo "Minimum supported rust version(MSRV) is ${MSRV}, please upgrade rust"
135+
exit 1
136+
fi
137+
138+
echo "Building rust files..."
139+
(cd ../src/rust && CARGO_TARGET_DIR=../../mac/rust cargo build $RUST_PROFILE $RUST_FEATURES) || { echo "Failed building Rust components." ; exit 1; }
140+
141+
# Copy the Rust library
142+
cp $RUST_LIB ./libccx_rust.a
143+
144+
# Add Rust library to linker flags
145+
BLD_LINKER="$BLD_LINKER ./libccx_rust.a"
146+
147+
echo "Building ccextractor"
148+
out=$((LC_ALL=C gcc $BLD_FLAGS $BLD_INCLUDE -o ccextractor $BLD_SOURCES $BLD_LINKER) 2>&1)
149+
res=$?
150+
151+
# Handle common error cases
152+
if [[ $out == *"gcc: command not found"* ]]; then
153+
echo "Error: please install gcc or Xcode command line tools"
154+
exit 1
155+
fi
156+
157+
if [[ $out == *"curl.h: No such file or directory"* ]]; then
158+
echo "Error: please install curl development library"
159+
exit 2
160+
fi
161+
162+
if [[ $out == *"capi.h: No such file or directory"* ]]; then
163+
echo "Error: please install tesseract development library"
164+
exit 3
165+
fi
166+
167+
if [[ $out == *"allheaders.h: No such file or directory"* ]]; then
168+
echo "Error: please install leptonica development library"
169+
exit 4
170+
fi
171+
172+
if [[ $res -ne 0 ]]; then # Unknown error
173+
echo "Compiled with errors"
174+
>&2 echo "$out"
175+
exit 5
176+
fi
177+
178+
if [[ "$out" != "" ]]; then
179+
echo "$out"
180+
echo "Compilation successful, compiler message shown in previous lines"
181+
else
182+
echo "Compilation successful, no compiler messages."
183+
fi

src/CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ include (CTest)
66
option (WITH_FFMPEG "Build using FFmpeg demuxer and decoder" OFF)
77
option (WITH_OCR "Build with OCR (Optical Character Recognition) feature" OFF)
88
option (WITH_HARDSUBX "Build with support for burned-in subtitles" OFF)
9-
option (WITHOUT_RUST "Build without Rust library" OFF)
109

1110
# Version number
1211
set (CCEXTRACTOR_VERSION_MAJOR 0)
@@ -237,12 +236,10 @@ add_executable (ccextractor ${SOURCEFILE} ${FREETYPE_SOURCE} ${UTF8PROC_SOURCE})
237236
# Build with Rust library
238237
########################################################
239238

240-
if (PKG_CONFIG_FOUND AND NOT WITHOUT_RUST)
239+
if (PKG_CONFIG_FOUND)
241240
add_subdirectory (rust)
242241
set (EXTRA_LIBS ${EXTRA_LIBS} ccx_rust)
243-
else ()
244-
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDISABLE_RUST")
245-
endif (PKG_CONFIG_FOUND AND NOT WITHOUT_RUST)
242+
endif (PKG_CONFIG_FOUND)
246243

247244

248245
target_link_libraries (ccextractor ${EXTRA_LIBS})

src/ccextractor.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,15 +418,9 @@ int main(int argc, char *argv[])
418418
// See docs/ccextractor.cnf.sample for more info.
419419
parse_configuration(&ccx_options);
420420

421-
#ifndef DISABLE_RUST
422421
ccxr_init_basic_logger();
423-
#endif
424422

425-
#ifndef DISABLE_RUST
426423
int compile_ret = ccxr_parse_parameters(argc, argv);
427-
#else
428-
int compile_ret = parse_parameters(&ccx_options, argc, argv);
429-
#endif
430424

431425
if (compile_ret == EXIT_NO_INPUT_FILES)
432426
{

src/lib_ccx/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ if (WITH_HARDSUBX)
8787
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_HARDSUBX")
8888
endif (WITH_HARDSUBX)
8989

90-
if (WITHOUT_RUST)
91-
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDISABLE_RUST")
92-
endif (WITHOUT_RUST)
93-
9490
file (GLOB HeaderFiles *.h)
9591
file (WRITE ccx.pc "prefix=${CMAKE_INSTALL_PREFIX}\n"
9692
"includedir=\${prefix}/include\n"

0 commit comments

Comments
 (0)