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

always build grammars with c++14 and c11 #6792

Merged
merged 1 commit into from
Apr 18, 2023
Merged

always build grammars with c++14 and c11 #6792

merged 1 commit into from
Apr 18, 2023

Conversation

pascalkuthe
Copy link
Member

Closes #6788

Usually, modern compilers always default to c++ 14 or c++17 anyway. Clang defaults to c++14 and gcc to c++17. MSVC++ even dropped support for older standards in msvc17 (and defaults to c++14) However, it seems that apple-clang sometimes (but not always) defaults to c++98. By explicitly setting the argument we can work around such cases.

This also ensures more consistent builds across various systems (that may default to newer c++ standards in the future) and provides more easily understood error messages on ancient systems that don't support c++14 yet.

@pascalkuthe pascalkuthe added C-bug Category: This is a bug E-easy Call for participation: Experience needed to fix: Easy / not much A-packaging Area: Packaging and bundling labels Apr 17, 2023
@David-Else
Copy link
Contributor

Sorry if this is not strictly related to this PR, but on Linux (I have not tested on another OS), if there is no c++ compiler installed when using cargo install --path helix-term --locked Helix silently fails to compile the grammar and shows no highlighting, perhaps that could also be addressed with an error message?

@pascalkuthe
Copy link
Member Author

pascalkuthe commented Apr 17, 2023

Sorry if this is not strictly related to this PR, but on Linux (I have not tested on another OS), if there is no c++ compiler installed when using cargo install --path helix-term --locked Helix silently fails to compile the grammar and shows no highlighting, perhaps that could also be addressed with an error message?

It does seem like we only print to stdout for error and don't actually return a proper error This would be easy to fix but would change the error output slightly from:

Building 149 grammars
140 grammars already built
9 grammars failed to build
	Failure 0/9: Failed to read directory "/home/pascalkuthe/.config/helix/runtime/grammars/sources/robot". Did you use 'hx --grammar fetch'?
	Failure 1/9: Failed to read directory "/home/pascalkuthe/.config/helix/runtime/grammars/sources/dtd". Did you use 'hx --grammar fetch'?
	Failure 2/9: Failed to read directory "/home/pascalkuthe/.config/helix/runtime/grammars/sources/nim". Did you use 'hx --grammar fetch'?
	Failure 3/9: Failed to read directory "/home/pascalkuthe/.config/helix/runtime/grammars/sources/just". Did you use 'hx --grammar fetch'?
	Failure 4/9: Failed to read directory "/home/pascalkuthe/.config/helix/runtime/grammars/sources/cabal". Did you use 'hx --grammar fetch'?
	Failure 5/9: Failed to read directory "/home/pascalkuthe/.config/helix/runtime/grammars/sources/rego". Did you use 'hx --grammar fetch'?
	Failure 6/9: Failed to read directory "/home/pascalkuthe/.config/helix/runtime/grammars/sources/opencl". Did you use 'hx --grammar fetch'?
	Failure 7/9: Failed to read directory "/home/pascalkuthe/.config/helix/runtime/grammars/sources/markdoc". Did you use 'hx --grammar fetch'?
	Failure 8/9: Failed to read directory "/home/pascalkuthe/.config/helix/runtime/grammars/sources/hurl". Did you use 'hx --grammar fetch'?

to

Building 149 grammars
140 grammars already built
	Failure 0/9: Failed to read directory "/home/pascalkuthe/.config/helix/runtime/grammars/sources/robot". Did you use 'hx --grammar fetch'?
	Failure 1/9: Failed to read directory "/home/pascalkuthe/.config/helix/runtime/grammars/sources/dtd". Did you use 'hx --grammar fetch'?
	Failure 2/9: Failed to read directory "/home/pascalkuthe/.config/helix/runtime/grammars/sources/rego". Did you use 'hx --grammar fetch'?
	Failure 3/9: Failed to read directory "/home/pascalkuthe/.config/helix/runtime/grammars/sources/nim". Did you use 'hx --grammar fetch'?
	Failure 4/9: Failed to read directory "/home/pascalkuthe/.config/helix/runtime/grammars/sources/cabal". Did you use 'hx --grammar fetch'?
	Failure 5/9: Failed to read directory "/home/pascalkuthe/.config/helix/runtime/grammars/sources/hurl". Did you use 'hx --grammar fetch'?
	Failure 6/9: Failed to read directory "/home/pascalkuthe/.config/helix/runtime/grammars/sources/markdoc". Did you use 'hx --grammar fetch'?
	Failure 7/9: Failed to read directory "/home/pascalkuthe/.config/helix/runtime/grammars/sources/opencl". Did you use 'hx --grammar fetch'?
	Failure 8/9: Failed to read directory "/home/pascalkuthe/.config/helix/runtime/grammars/sources/just". Did you use 'hx --grammar fetch'?
Error: 9 grammars failed to build

(ignore the exact errors here I just made the build fail quickly this would work the same for any errors). Should probably be a separate PR but not sure if we want to change the formatting a bit.

Anyway, this patch fixes what you described:

diff --git a/helix-loader/src/grammar.rs b/helix-loader/src/grammar.rs
index 060d9332..09ced91f 100644
--- a/helix-loader/src/grammar.rs
+++ b/helix-loader/src/grammar.rs
@@ -1,4 +1,4 @@
-use anyhow::{anyhow, Context, Result};
+use anyhow::{anyhow, Context, Result, bail};
 use serde::{Deserialize, Serialize};
 use std::fs;
 use std::time::SystemTime;
@@ -178,10 +178,10 @@ pub fn build_grammars(target: Option<String>) -> Result<()> {
 
     if !errors.is_empty() {
         let len = errors.len();
-        println!("{} grammars failed to build", len);
         for (i, error) in errors.into_iter().enumerate() {
             println!("\tFailure {}/{}: {}", i, len, error);
         }
+        bail!("{} grammars failed to build", len);
     }
 
     Ok(())

@pascalkuthe pascalkuthe changed the title always build grammars with c++ 14 always build grammars with c++14 and c11 Apr 17, 2023
@David-Else
Copy link
Contributor

Should probably be a separate PR but not sure if we want to change the formatting a bit.

Anyway, this patch fixes what you described:

@pascalkuthe Great news you fixed it so fast! I have no opinion on the formatting, but I hope the fix can get into 23.03.1 https://github.com/helix-editor/helix/milestone/5 as it has caught me out a few times, and I have also seen people run into this problem in the issues. Silent failure is the worst kind of fail.

@pascalkuthe
Copy link
Member Author

@David-Else #6795

@pascalkuthe
Copy link
Member Author

pascalkuthe commented Apr 17, 2023

It turns out that the grammar build was actually failing in CI too but because of the bug pointed out by @David-Else it didn't cause a build failure. With #6795 the macros build with master fails in CI but succeeds with this branch so this is actually reproducible. The CI also showed an oversight in this PR, only on macOS, turns out apple-clang is really picky about separating c/c++ flags so I had to create a temporary object file when compiling c++ (we already depend on tempfile elsewhere anyway).

I also took the chance to cleanup the build flags a bit. -O3 is added automatically by cc already and -g always enables debug info on UNIX based system. While we always disable it on windows. cc should already enable debug info in debug builds but leave it off in release mode. Since grammars tend to be quite large we probably want to turn that off here to keep the binary size down. Debugging inside the grammars isn't really useful anyways, it's usually enough to know that we are inside the grammar or now and we should know that even without -g.

@archseer
Copy link
Member

Hmm I remember we used to build with C++14 because the haskell grammar had more complicated requirements but that failed to build on some systems. Eventually the haskell grammar was simplified and we dropped the requirement.

@archseer
Copy link
Member

That was probably because the cross images used a very old compiler, I think that has since been resolved

@archseer archseer merged commit ca65d31 into master Apr 18, 2023
@archseer archseer deleted the build_cpp branch April 18, 2023 01:10
@pascalkuthe
Copy link
Member Author

If its really an issue in the future we can lower the c++ version down to something more compatible and patch the grammars. c++14 support is pretty widespread these days so I hope it won't be an issue. The only distro wehrre this may cause problems that is still supported is redhl 7 based stuff and that's nearing EOL and has an easy way to install a newer compiler trough the support packagss.

Fxing the exact c standard version probably a good idea regardless even if we would habe to lower the version again to make sure builds are consistent across different systems

@pascalkuthe pascalkuthe mentioned this pull request Apr 20, 2023
Triton171 pushed a commit to Triton171/helix that referenced this pull request Jun 18, 2023
wes-adams pushed a commit to wes-adams/helix that referenced this pull request Jul 4, 2023
fweimer-rh added a commit to fweimer-rh/helix that referenced this pull request Nov 30, 2023
Commit ca65d31 ("always build
grammars with c++14 and c11 (helix-editor#6792)") turned on semi-strict
standard mode for C and C++ by accident.  Some grammars use
non-standard functions such as isascii (from <ctype.h>) and
fail to build as a result, particularly with future compilers
which do not support implicit function declarations.

(Ideally, the build environment would only raise the standard
versions relative to the toolchain default, not lower them, but
this change does not implement that.)
smortime pushed a commit to smortime/helix that referenced this pull request Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-packaging Area: Packaging and bundling C-bug Category: This is a bug E-easy Call for participation: Experience needed to fix: Easy / not much
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build failure on Cabal and Just grammars
4 participants