Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support icu provided by Windows #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion fuzz/libpsl_fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ typedef unsigned __int8 uint8_t;
#include <stdlib.h> /* malloc, free */
#include <string.h> /* memcpy */

#if defined(WITH_LIBICU)
#ifdef WITH_LIBICU
#ifndef WITH_LIBICU_WIN
#include <unicode/uclean.h>
#else
#include <icu.h>
#endif
#endif

#include "libpsl.h"
Expand Down
12 changes: 12 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ buildtype = get_option('buildtype')
notfound = dependency('', required : false)
libidn2_dep = notfound
libicu_dep = notfound
libicu_win_dep = notfound
libidn_dep = notfound
libunistring = notfound
networking_deps = notfound
Expand Down Expand Up @@ -57,6 +58,16 @@ if ['libicu', 'auto'].contains(enable_runtime)
endif
endif

if host_machine.system() == 'windows' and ['libicu-win', 'auto'].contains(enable_runtime)
libicu_win_dep = cc.find_library('icu', required: false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also skip this for "auto" when the host machine isn't Windows, as it can't be found anyway. Result: configuring on Linux or macOS or BSD with runtime == auto is a bit faster due to running one less check.

if libicu_win_dep.found()
libicu_dep = libicu_win_dep
enable_runtime = 'libicu' # Treat libicu-win as a libicu variant.
elif enable_runtime == 'libicu-win'
error('You requested libicu-win but it is not found.')
endif
endif

if ['libidn', 'auto'].contains(enable_runtime)
libidn_dep = dependency('libidn', required : false)
if not libidn_dep.found() and cc.has_header('idna.h')
Expand Down Expand Up @@ -89,6 +100,7 @@ config = configuration_data()
config.set_quoted('PACKAGE_VERSION', meson.project_version())
config.set('WITH_LIBIDN2', enable_runtime == 'libidn2')
config.set('WITH_LIBICU', enable_runtime == 'libicu')
config.set('WITH_LIBICU_WIN', libicu_win_dep.found())
config.set('WITH_LIBIDN', enable_runtime == 'libidn')
config.set('ENABLE_BUILTIN', enable_builtin)
config.set('HAVE_UNISTD_H', cc.check_header('unistd.h'))
Expand Down
2 changes: 1 addition & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
option('runtime', type : 'combo',
choices : ['libidn2', 'libicu', 'libidn', 'no', 'auto'], value : 'auto',
choices : ['libidn2', 'libicu', 'libicu-win', 'libidn', 'no', 'auto'], value : 'auto',
description : 'Specify the IDNA library used for libpsl run-time conversions')

option('builtin', type : 'boolean',
Expand Down
16 changes: 12 additions & 4 deletions src/psl.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ typedef SSIZE_T ssize_t;
#endif

#ifdef WITH_LIBICU
# include <unicode/uversion.h>
# include <unicode/ustring.h>
# include <unicode/uidna.h>
# include <unicode/ucnv.h>
# ifndef WITH_LIBICU_WIN
# include <unicode/uversion.h>
# include <unicode/ustring.h>
# include <unicode/uidna.h>
# include <unicode/ucnv.h>
# else
# include <icu.h>
# endif
#elif defined(WITH_LIBIDN2)
# include <iconv.h>
# include <idn2.h>
Expand Down Expand Up @@ -116,6 +120,10 @@ typedef SSIZE_T ssize_t;
#define PRIV_PSL_FLAG_PRIVATE (1<<3) /* entry of PRIVATE section */
#define PRIV_PSL_FLAG_PLAIN (1<<4) /* just used for PSL syntax checking */

#ifdef WITH_LIBICU_WIN
# define U_ICU_VERSION "Windows"
#endif

typedef struct {
char
label_buf[128];
Expand Down