Skip to content

fix(common): enable build for win x64, use global VERSION.md and fix decxstr() bug#3076

Merged
mcdurdin merged 9 commits intomasterfrom
refactor/windows/core
May 5, 2020
Merged

fix(common): enable build for win x64, use global VERSION.md and fix decxstr() bug#3076
mcdurdin merged 9 commits intomasterfrom
refactor/windows/core

Conversation

@mcdurdin
Copy link
Copy Markdown
Member

@mcdurdin mcdurdin commented May 4, 2020

Keyman Core build on Windows x64

Keyman core was only being built for x86 on Windows. This builds also for x64.

Build Agents updated: I have updated the build scripts on TeamCity to reference build.bat instead of calling meson/ninja directly.

build.bat has various parameters:

  • x86 - build x86 version of core (Windows) into build-x86/ and test
  • x64 - build x64 version of core (Windows) into build-x64/ and test
  • all - build both versions and test
  • -c - use after x86 or x64 to leave your shell configured for VC++ for that target platform

Reference root VERSION.md

meson.build now references the root VERSION.md instead of a copy in the local folder. This means we no longer need to copy it in during build. Build Agents updated accordingly.

decxstr() bug

Importantly, this fixes a long-standing latent bug in decxstr() where it could test before the start of the string. It always happened to work okay in test cases in the past, but failed in x64 tests because the filler bytes were 0xFF...

Obviously testing outside array bounds is a serious no-no. Hence fixed in both windows and core code.

Might be worth checking macos code at some point, although may be not necessary as intent is to replace it this release with Keyman Core.

@mcdurdin mcdurdin added this to the P10S6 milestone May 4, 2020
@mcdurdin mcdurdin changed the title fix(common): enable build for win x64 and use global VERSION.md fix(common): enable build for win x64, use global VERSION.md and fix decxstr() bug May 4, 2020
# Fallback to "more" for Windows compatbility
version: run_command(find_program('cat', 'more'),
files('VERSION.md')).stdout().strip(),
files('../../../VERSION.md')).stdout().strip(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think @ermshiperete intentionally used 'VERSION.md' in #2843 to fix the failing Linux packaging builds

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, I did. This fixes the Linux package build, but unfortunately breaks things everywhere else unless you (manually) copy VERSION.md... I'm working on a better solution that should work everywhere...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I take it meson will choose the correct script in find_program based on the OS? Because the documentation is a little vague on that point.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It takes the first it finds and can execute. On Windows (at least on my machine) it finds both .bat and .sh, but has problems executing .sh (runs without obvious error, but doesn't seem to DO anything) which is why I put .bat first. On Linux it ignores the .bat file.

`VERSION.md` is in the root of the source directory. However, when
building a Linux package from a source package we can't access files
from the root directory. Prior to creating the source package
`VERSION.md` gets copied to `common/core/desktop` so that it is
available in the source package. However, this hack broke the
meson build everywhere else unless `VERSION.md` got copied manually.

This change uses `VERSION.md` from the root directory if it is
available and otherwise assumes that it exists in the same directory
as the `meson.build` script. This change also switches to using
scripts to get the version number rather than doing it in the meson
build itself because that gives more flexibility. It is important to
note that the Windows batch file has to be listed first in
`find_program` because Windows might detect `getversion.sh` and
tries to run it with bash but this fails because of the different
directory separators.
@darcywong00
Copy link
Copy Markdown
Contributor

Should https://github.com/keymanapp/keyman/blob/master/common/core/desktop/doc/BUILDING.md be updated to mention build.bat or x64?

{
for(PKMX_WCHAR q = incxstr(buf); *buf; buf = q, q = incxstr(buf))
if(!u16ncmp(buf, chr, (int)(q-buf)))
if(!u16ncmp(buf, chr, (intptr_t)(q-buf)))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does the Windows version (line 167) remain the same?

    if(!wcsncmp(buf, chr, (int)(q-buf)))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch. I knew there was something else I needed to do. We should audit the rest of keyman32/keyman64 for use of improper casts.

It is unlikely to cause a problem presently because we currently have a base address fixed in the keyman64.dll below 2GB (which itself is not recommended...) so we should probably put this in as a maintenance issue. It could arise if Windows needs to relocate the dll I guess.

Copy link
Copy Markdown
Contributor

@darcywong00 darcywong00 left a comment

Choose a reason for hiding this comment

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

lgtm

@mcdurdin mcdurdin merged commit 04c029a into master May 5, 2020
@mcdurdin mcdurdin deleted the refactor/windows/core branch May 5, 2020 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants