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

Fix generated cc command for cross compile #13661

Merged
merged 7 commits into from
Jul 14, 2023

Conversation

fnordfish
Copy link
Contributor

Ref #13657

@Blacksmoke16 Blacksmoke16 added kind:bug topic:compiler:codegen kind:regression Something that used to correctly work but no longer works labels Jul 13, 2023
@fnordfish fnordfish changed the title Fix generated cc command for static cross compile Fix generated cc command for cross compile Jul 13, 2023
@fnordfish
Copy link
Contributor Author

Just realized, that the --static part is unnecessary. --cross-compile is where things go wrong.

Copy link
Member

@straight-shoota straight-shoota left a comment

Choose a reason for hiding this comment

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

This looks like a good fix and the test is great to avoid repetition 🙇

There might be some merit in refactoring the code to clearly separate the different output path names by their function. But this is just a thought for later and out of scope for this bug fix.

src/compiler/crystal/compiler.cr Outdated Show resolved Hide resolved
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
FileUtils.mkdir_p("#{path}/bin")
expected_bin = "#{path}/bin/compiler_sample-linux-x86_64"
output = IO::Memory.new
Process.run(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is effectively an integration spec and will fail if a local Crystal compiler isn't built, as the spec will simply pick up the existing Crystal installation. You have two choices here:

  • If you could get hold of a Crystal::Compiler in this spec, it has a #stdout property which you could reassign the above IO::Memory to. Then you could call Crystal::Command.run directly, which uses the fresh compiler code, and test the compiler output as usual. The easiest way would probably be adding a new stdout parameter in Command#initialize and using it in #create_compiler.
  • Move this spec into a separate test suite, say spec/compiler/integration_spec.cr, and create a corresponding new Makefile target that depends on the fresh compiler, similar to how $(O)/primitives_spec depends on $(O)/crystal. All the CI workflows must be updated to run this. This spec alone should be fast to build (i.e. it never requires the compiler source).

Copy link
Member

Choose a reason for hiding this comment

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

Hm, isn't this the same with the following example?
Anywawy, I'd be happy to merge only the bugfix directly and figure out the spec later.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is true, that spec can also fail in the same way

Copy link
Member

Choose a reason for hiding this comment

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

For the record, I think a unit test would be best for this. It may even need some refactoring to make that easier.
But we really just need a method that produces the linker command based on some pathnames and a basically empty Program instance with some flags configured.

spec/compiler/compiler_spec.cr Outdated Show resolved Hide resolved
@straight-shoota
Copy link
Member

straight-shoota commented Jul 14, 2023

@fnordfish In order to prioritize on shipping the bug fix, I think it's most practical to drop the spec from this PR. That way we can merge the bug fix right away for the release of 1.9.1.
We can then take the time to implement the spec in a robust manner and merge it later. There are a couple of details that may need some more discusion.

@fnordfish
Copy link
Contributor Author

@straight-shoota Works for me. Should I remove the spec and squash everything down to a single commit?

@HertzDevil
Copy link
Contributor

No need to squash or rebase, just a plain commit that reverts the spec

@straight-shoota straight-shoota added this to the 1.9.1 milestone Jul 14, 2023
@straight-shoota straight-shoota merged commit 3a02b56 into crystal-lang:master Jul 14, 2023
48 of 52 checks passed
@straight-shoota straight-shoota linked an issue Jul 15, 2023 that may be closed by this pull request
stakach pushed a commit to stakach/crystal that referenced this pull request Jul 22, 2023
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
Blacksmoke16 pushed a commit to Blacksmoke16/crystal that referenced this pull request Dec 11, 2023
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug kind:regression Something that used to correctly work but no longer works topic:compiler:codegen
Projects
None yet
Development

Successfully merging this pull request may close these issues.

static cross compile leads to incorrect cc command
4 participants