Skip to content

Commit

Permalink
Merge pull request #25 from cmacdonald/windows_msvc
Browse files Browse the repository at this point in the history
native Windows compilation
  • Loading branch information
isoboroff authored Sep 3, 2020
2 parents 0c9d7a3 + 8c33f74 commit d95ca64
Show file tree
Hide file tree
Showing 18 changed files with 839 additions and 43 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# This workflow will install Python dependencies, and runs tests with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Continuous Integration

on:
push:
pull_request:

jobs:
build:

strategy:
matrix:
os: ['ubuntu-latest', 'windows-latest', 'macOs-latest']
architecture: ['x64']

runs-on: ${{ matrix.os }}
steps:

- uses: actions/checkout@v2

- name: build-windows
if: matrix.os == 'windows-latest'
shell: cmd
run: |
call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x86_amd64
build.bat
dir trec_eval.exe
- name: build-unix
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macOs-latest'
run: |
make
- name: run-unix
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macOs-latest'
run: |
./trec_eval -h
- name: run-windows
if: matrix.os == 'windows-latest'
shell: cmd
run: |
trec_eval -h
- name: test-unix
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macOs-latest'
run: |
make quicktest
# longtest doesnt pass at present
#make longtest
- name: test-windows
if: matrix.os == 'windows-latest'
shell: cmd
run: |
quicktest.bat
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
trec_eval.*/
*.obj
*.tar
.DS_Store
test.long
trec_eval
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ MEAS_SRCS = measures.c m_map.c m_P.c m_num_q.c m_num_ret.c m_num_rel.c \

SRCS = $(TOP_SRCS) $(FORMAT_SRCS) $(MEAS_SRCS)

SRCH = common.h trec_eval.h sysfunc.h functions.h trec_format.h
SRCH = common.h trec_eval.h sysfunc.h functions.h trec_format.h

SRCOTHER = README Makefile test bpref_bug CHANGELOG
SRCOTHER = README Makefile test bpref_bug CHANGELOG windows

trec_eval: $(SRCS) Makefile $(SRCH)
$(CC) $(CFLAGS) -o trec_eval $(SRCS) -lm
Expand Down
19 changes: 16 additions & 3 deletions README.windows.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
## Compiling
# Windows Support

To achieve a compilation of trec_eval for Windows, you will need Cygwin installed.
trec_eval can be compiled natively for Windows, using Visual Studio build tools, or using Cygwin

## Compiling using Visual Studio build tools

See the [Github Workflow](.github/workflow/push.yml) for compilation.

A few additional includes are used:
- `mman.h` - a mmap() implementation for Windows
- `unistd.h` - dropin replacement for the Unix header file unistd.h
- `ya_getopt.h` - BSD licensed getopt_log() implementation

The resulting .exe can be used natively on Windows without any further dependencies.

## Compiling on Cygwin

Download and install the [Cygwin](https://www.cygwin.com/) platform. You will need make and gcc installed by Cygwin. To achieve this, on top of the default Cygwin installation, it is recommended to install automake, make, gcc, cygwin-gcc and git from the Develop category, and permitting dependencies to be installed.

Then, to compile trec_eval, open a Cygwin Terminal, navigate using cd to the directory of the trec_eval source, and type make.

## Running
## Running on Cygwin

The resulting trec_eval.exe should be usable directly from the Cygwin Terminal.

Expand Down
1 change: 1 addition & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cl /DVERSIONID=\"9.0.7\" trec_eval.c formats.c meas_init.c meas_acc.c meas_avg.c meas_print_single.c meas_print_final.c get_qrels.c get_trec_results.c get_prefs.c get_qrels_prefs.c get_qrels_jg.c form_res_rels.c form_res_rels_jg.c form_prefs_counts.c utility_pool.c get_zscores.c convert_zscores.c measures.c m_map.c m_P.c m_num_q.c m_num_ret.c m_num_rel.c m_num_rel_ret.c m_gm_map.c m_Rprec.c m_recip_rank.c m_bpref.c m_iprec_at_recall.c m_recall.c m_Rprec_mult.c m_utility.c m_11pt_avg.c m_ndcg.c m_ndcg_cut.c m_Rndcg.c m_ndcg_rel.c m_binG.c m_G.c m_rel_P.c m_success.c m_infap.c m_map_cut.c m_gm_bpref.c m_runid.c m_relstring.c m_set_P.c m_set_recall.c m_set_rel_P.c m_set_map.c m_set_F.c m_num_nonrel_judged_ret.c m_prefs_num_prefs_poss.c m_prefs_num_prefs_ful.c m_prefs_num_prefs_ful_ret.c m_prefs_simp.c m_prefs_pair.c m_prefs_avgjg.c m_prefs_avgjg_Rnonrel.c m_prefs_simp_ret.c m_prefs_pair_ret.c m_prefs_avgjg_ret.c m_prefs_avgjg_Rnonrel_ret.c m_prefs_simp_imp.c m_prefs_pair_imp.c m_prefs_avgjg_imp.c m_map_avgjg.c m_Rprec_mult_avgjg.c m_P_avgjg.c m_yaap.c windows/mman.c windows/ya_getopt.c /link /out:trec_eval.exe
12 changes: 6 additions & 6 deletions get_prefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ typedef struct {
int
te_get_prefs (EPI *epi, char *text_prefs_file, ALL_REL_INFO *all_rel_info)
{
int fd;
FILE* fd;
int size = 0;
char *ptr;
char *current_qid;
Expand All @@ -153,12 +153,12 @@ te_get_prefs (EPI *epi, char *text_prefs_file, ALL_REL_INFO *all_rel_info)
TEXT_PREFS *text_prefs_ptr;

/* Read entire file into memory */
if (-1 == (fd = open (text_prefs_file, 0)) ||
0 >= (size = lseek (fd, 0L, 2)) ||
if (! (fd = fopen (text_prefs_file, "rb")) ||
fseek (fd, 0L, SEEK_END) != 0 || 0 >= (size = ftell(fd)) ||
NULL == (trec_prefs_buf = malloc ((unsigned) size+2)) ||
-1 == lseek (fd, 0L, 0) ||
size != read (fd, trec_prefs_buf, size) ||
-1 == close (fd)) {
-1 == fseek (fd, 0L, SEEK_SET) ||
size != fread (trec_prefs_buf, 1, size, fd) ||
-1 == fclose (fd)) {
fprintf (stderr,
"trec_eval.get_prefs: Cannot read prefs file '%s'\n",
text_prefs_file);
Expand Down
15 changes: 8 additions & 7 deletions get_qrels.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "trec_format.h"
#include <ctype.h>


/* Read all relevance information from text_qrels_file.
Relevance for each docno to qid is determined from text_qrels_file, which
consists of text tuples of the form
Expand Down Expand Up @@ -64,6 +63,8 @@ static int parse_qrels_line (char **start_ptr, char **qid_ptr,

static int comp_lines_qid_docno ();

extern int errno ;


/* static pools of memory, allocated here and never changed.
Declared static so one day I can write a cleanup procedure to free them */
Expand All @@ -75,7 +76,7 @@ static REL_INFO *rel_info_pool = NULL;
int
te_get_qrels (EPI *epi, char *text_qrels_file, ALL_REL_INFO *all_rel_info)
{
int fd;
FILE *fd;
int size = 0;
char *ptr;
char *current_qid;
Expand All @@ -90,12 +91,12 @@ te_get_qrels (EPI *epi, char *text_qrels_file, ALL_REL_INFO *all_rel_info)
TEXT_QRELS *text_qrels_ptr;

/* Read entire file into memory */
if (-1 == (fd = open (text_qrels_file, 0)) ||
0 >= (size = lseek (fd, 0L, 2)) ||
if (!(fd = fopen (text_qrels_file, "rb")) ||
fseek (fd, 0L, SEEK_END) != 0 || 0 >= (size = ftell(fd)) ||
NULL == (trec_qrels_buf = malloc ((unsigned) size+2)) ||
-1 == lseek (fd, 0L, 0) ||
size != read (fd, trec_qrels_buf, size) ||
-1 == close (fd)) {
-1 == fseek (fd, 0L, SEEK_SET) ||
size != fread (trec_qrels_buf, 1, size, fd) ||
-1 == fclose (fd)) {
fprintf (stderr,
"trec_eval.get_qrels: Cannot read qrels file '%s'\n",
text_qrels_file);
Expand Down
14 changes: 7 additions & 7 deletions get_qrels_jg.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static REL_INFO *rel_info_pool = NULL;
int
te_get_qrels_jg (EPI *epi, char *text_qrels_file, ALL_REL_INFO *all_rel_info)
{
int fd;
FILE* fd;
int size = 0;
char *ptr;
char *current_qid, *current_jg;
Expand All @@ -99,14 +99,14 @@ te_get_qrels_jg (EPI *epi, char *text_qrels_file, ALL_REL_INFO *all_rel_info)
TEXT_QRELS *text_qrels_ptr;

/* Read entire file into memory */
if (-1 == (fd = open (text_qrels_file, 0)) ||
0 >= (size = lseek (fd, 0L, 2)) ||
if (!(fd = fopen (text_qrels_file, "rb")) ||
fseek (fd, 0L, SEEK_END) != 0 || 0 >= (size = ftell(fd)) ||
NULL == (trec_qrels_buf = malloc ((unsigned) size+2)) ||
-1 == lseek (fd, 0L, 0) ||
size != read (fd, trec_qrels_buf, size) ||
-1 == close (fd)) {
-1 == fseek (fd, 0L, SEEK_SET) ||
size != fread (trec_qrels_buf, 1, size, fd) ||
-1 == fclose (fd)) {
fprintf (stderr,
"trec_eval.get_qrels: Cannot read qrels file '%s'\n",
"trec_eval.get_qrels_jg: Cannot read qrels file '%s'\n",
text_qrels_file);
return (UNDEF);
}
Expand Down
12 changes: 6 additions & 6 deletions get_qrels_prefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ typedef struct {
int
te_get_qrels_prefs (EPI *epi, char *text_prefs_file, ALL_REL_INFO *all_rel_info)
{
int fd;
FILE* fd;
int size = 0;
char *ptr;
char *current_qid;
Expand All @@ -124,12 +124,12 @@ te_get_qrels_prefs (EPI *epi, char *text_prefs_file, ALL_REL_INFO *all_rel_info)
TEXT_PREFS *text_prefs_ptr;

/* Read entire file into memory */
if (-1 == (fd = open (text_prefs_file, 0)) ||
0 >= (size = lseek (fd, 0L, 2)) ||
if (!(fd = fopen (text_prefs_file, "rb")) ||
fseek (fd, 0L, SEEK_END) != 0 || 0 >= (size = ftell(fd)) ||
NULL == (trec_prefs_buf = malloc ((unsigned) size+2)) ||
-1 == lseek (fd, 0L, 0) ||
size != read (fd, trec_prefs_buf, size) ||
-1 == close (fd)) {
-1 == fseek (fd, 0L, SEEK_SET) ||
size != fread (trec_prefs_buf, 1, size, fd) ||
-1 == fclose (fd)) {
fprintf (stderr,
"trec_eval.get_prefs: Cannot read prefs file '%s'\n",
text_prefs_file);
Expand Down
2 changes: 1 addition & 1 deletion get_trec_results.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ te_get_trec_results (EPI *epi, char *text_results_file,
/* mmap entire file into memory and copy it into writable memory */
if (-1 == (fd = open (text_results_file, 0)) ||
0 >= (size = lseek (fd, 0L, 2)) ||
(char *) -1 == (orig_buf = (char *) mmap ((caddr_t) 0,
(char *) -1 == (orig_buf = (char *) mmap (0,
(size_t) size,
PROT_READ,
MAP_SHARED,
Expand Down
16 changes: 8 additions & 8 deletions get_zscores.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int
te_get_zscores (const EPI *epi, const char *zscores_file,
ALL_ZSCORES *all_zscores)
{
int fd;
FILE* fd;
int size = 0;
char *ptr;
char *current_qid;
Expand All @@ -81,18 +81,18 @@ te_get_zscores (const EPI *epi, const char *zscores_file,
ZSCORES *zscores_ptr;

/* Read entire file into memory */
if (-1 == (fd = open (zscores_file, 0)) ||
0 >= (size = lseek (fd, 0L, 2)) ||
if (!(fd = fopen (zscores_file, "rb")) ||
fseek (fd, 0L, SEEK_END) != 0 || 0 >= (size = ftell(fd)) ||
NULL == (trec_zscores_buf = malloc ((unsigned) size+2)) ||
-1 == lseek (fd, 0L, 0) ||
size != read (fd, trec_zscores_buf, size) ||
-1 == close (fd)) {
-1 == fseek (fd, 0L, SEEK_SET) ||
size != fread (trec_zscores_buf, 1, size, fd) ||
-1 == fclose (fd)) {
fprintf (stderr,
"trec_eval.get_zscores: Cannot read zscores file '%s'\n",
"trec_eval.get_prefs: Cannot read zscores file '%s'\n",
zscores_file);
return (UNDEF);
}

/* Append ending newline if not present, Append NULL terminator */
if (trec_zscores_buf[size-1] != '\n') {
trec_zscores_buf[size] = '\n';
Expand Down
24 changes: 24 additions & 0 deletions quicktest.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
REM See https://stackoverflow.com/a/734634 for how to exit on failure
trec_eval test/qrels.test test/results.test > out.test && fc out.test test/out.test
if %errorlevel% neq 0 exit /b %errorlevel%
trec_eval -m all_trec test/qrels.test test/results.test > out.test.a && fc out.test.a test/out.test.a
if %errorlevel% neq 0 exit /b %errorlevel%
trec_eval -m all_trec -q test/qrels.test test/results.test > out.test.aq && fc out.test.aq test/out.test.aq
if %errorlevel% neq 0 exit /b %errorlevel%
trec_eval -m all_trec -q -c test/qrels.test test/results.trunc > out.test.aqc && fc out.test.aqc test/out.test.aqc
if %errorlevel% neq 0 exit /b %errorlevel%
trec_eval -m all_trec -q -c -M100 test/qrels.test test/results.trunc > out.test.aqcM && fc out.test.aqcM test/out.test.aqcM
if %errorlevel% neq 0 exit /b %errorlevel%
trec_eval -m all_trec -mrelstring.20 -q -l2 test/qrels.rel_level test/results.test> out.test.aql && fc out.test.aql test/out.test.aql
if %errorlevel% neq 0 exit /b %errorlevel%
trec_eval -m all_prefs -q -R prefs test/prefs.test test/prefs.results.test > out.test.prefs && fc out.test.prefs test/out.test.prefs
if %errorlevel% neq 0 exit /b %errorlevel%
trec_eval -m all_prefs -q -R qrels_prefs test/qrels.test test/results.test > out.test.qrels_prefs && fc out.test.qrels_prefs test/out.test.qrels_prefs
if %errorlevel% neq 0 exit /b %errorlevel%
trec_eval -m qrels_jg -q -R qrels_jg test/qrels.123 test/results.test > out.test.qrels_jg && fc out.test.qrels_jg test/out.test.qrels_jg
if %errorlevel% neq 0 exit /b %errorlevel%
trec_eval -q -miprec_at_recall..10,.20,.25,.75,.50 -m P.5,7,3 -m recall.20,2000 -m Rprec_mult.5.0,0.2,0.35 -mutility.2,-1,0,0 -m 11pt_avg..25,.5,.75 -mndcg.1=3,2=9,4=4.5 -mndcg_cut.10,20,23.4 -msuccess.2,5,20 test/qrels.test test/results.test > out.test.meas_params && fc out.test.meas_params test/out.test.meas_params
if %errorlevel% neq 0 exit /b %errorlevel%
trec_eval -q -m all_trec -Z test/zscores_file test/qrels.test test/results.test > out.test.aqZ && fc out.test.aqZ test/out.test.aqZ
if %errorlevel% neq 0 exit /b %errorlevel%
del out.test out.test.*
12 changes: 9 additions & 3 deletions sysfunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
suit!), this file should just include system header files from
/usr/include. Until then... */

#if defined(_WIN32) || defined(_WIN64)
#include "windows/unistd.h"
#else
#include <unistd.h>
#endif
#include <limits.h>
#include <ctype.h>
#include <fcntl.h>
Expand All @@ -21,11 +25,13 @@
#include <math.h>
#include <memory.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/time.h>
#if defined(_WIN32) || defined(_WIN64)
#include "windows/mman.h"
#include "windows/ya_getopt.h"
#else
#include <sys/mman.h>

#include <getopt.h>
#endif

/* see http://stackoverflow.com/questions/33058014/trec-eval-make-error-using-cygwin/34927338 */
#ifdef __CYGWIN__
Expand Down
Loading

0 comments on commit d95ca64

Please sign in to comment.