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

Compile and run on macOS #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

brandonxin
Copy link

This patch allows clice to be compiled and run on macOS.

Main Changes

Use std::localtime_r instead of std::chrono::zoned_time

std::chrono::zoned_time is an experimental feature of libc++ and is unavailable on macOS, so I concatenate the output of std::localtime_r and the millisecond part of chrono::system_clock::now() to get a time string identical to current implementation. I admit that it is a little bit clumsy and more like a temporary solution, and I am looking forward to a better one.

Query xcrun to acquire macOS's SDK path

I noticed that clice cannot find all standard headers (, , etc.), which is not the case when running on Linux, so I referred to clangd's code. In short, when running on macOS, clangd will invoke xcrun to get the SDK path (detectSysroot and append it into the compile commands, so I port queryXcrun to clice and imitate this behavior in mangleCommand.

Use std::iota instead of std::ranges::iota

Currently std::ranges::iota is also not supported by libc++. It looks like std::iota does exactly the same thing here.

Build

Now I can build clice with lld and llvm-19, installed by following commands:

brew install llvm lld

export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib/c++ -L/opt/homebrew/opt/llvm/lib/unwind -lunwind"

The macOS version is Sonoma 14.7.2 (23H311). The SDK version is 15.2 (Apple clang version 16.0.0 (clang-1600.0.26.6)).

Test

[brandon@Brandons-MBP clice]$ build/bin/clice-tests --test-dir tests                  
[==========] Running 68 tests from 11 test suites.
[----------] Global test environment set-up.
[----------] 1 test from SourceCode
[ RUN      ] SourceCode.Remeasure
[       OK ] SourceCode.Remeasure (0 ms)
[----------] 1 test from SourceCode (0 ms total)

[----------] 5 tests from URI
[ RUN      ] URI.Basic
[       OK ] URI.Basic (0 ms)
[ RUN      ] URI.Copy
[       OK ] URI.Copy (0 ms)
[ RUN      ] URI.Eq
[       OK ] URI.Eq (0 ms)
[ RUN      ] URI.File
[       OK ] URI.File (0 ms)
[ RUN      ] URI.Parse
[       OK ] URI.Parse (0 ms)
[----------] 5 tests from URI (0 ms total)

[----------] 3 tests from clice
[ RUN      ] clice.Command
[       OK ] clice.Command (0 ms)
[ RUN      ] clice.Diagnostic
[       OK ] clice.Diagnostic (0 ms)
[ RUN      ] clice.coroutine
[       OK ] clice.coroutine (0 ms)
[----------] 3 tests from clice (0 ms total)

[----------] 5 tests from Compiler
[ RUN      ] Compiler.buildAST
[       OK ] Compiler.buildAST (25 ms)
[ RUN      ] Compiler.ComputeBounds
warning: no such sysroot directory: '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'
[       OK ] Compiler.ComputeBounds (4 ms)
[ RUN      ] Compiler.buildPCH
[       OK ] Compiler.buildPCH (48 ms)
[ RUN      ] Compiler.buildPCM
[       OK ] Compiler.buildPCM (8 ms)
[ RUN      ] Compiler.codeCompleteAt
COMPLETION: inline
COMPLETION: int
[       OK ] Compiler.codeCompleteAt (3 ms)
[----------] 5 tests from Compiler (90 ms total)

[----------] 3 tests from Directive
[ RUN      ] Directive.Include
[       OK ] Directive.Include (3 ms)
[ RUN      ] Directive.Condition
[       OK ] Directive.Condition (4 ms)
[ RUN      ] Directive.Macro
[       OK ] Directive.Macro (4 ms)
[----------] 3 tests from Directive (11 ms total)

[----------] 2 tests from Module
[ RUN      ] Module.Scan
[       OK ] Module.Scan (307 ms)
[ RUN      ] Module.Normal
[       OK ] Module.Normal (4 ms)
[----------] 2 tests from Module (312 ms total)

[----------] 20 tests from TemplateResolver
[ RUN      ] TemplateResolver.TypeParameterType
[       OK ] TemplateResolver.TypeParameterType (5 ms)
[ RUN      ] TemplateResolver.SingleLevel
[       OK ] TemplateResolver.SingleLevel (4 ms)
[ RUN      ] TemplateResolver.SingleLevelNotDependent
[       OK ] TemplateResolver.SingleLevelNotDependent (3 ms)
[ RUN      ] TemplateResolver.MultiLevel
[       OK ] TemplateResolver.MultiLevel (4 ms)
[ RUN      ] TemplateResolver.MultiLevelNotDependent
[       OK ] TemplateResolver.MultiLevelNotDependent (3 ms)
[ RUN      ] TemplateResolver.ArgumentDependent
[       OK ] TemplateResolver.ArgumentDependent (4 ms)
[ RUN      ] TemplateResolver.AliasArgument
[       OK ] TemplateResolver.AliasArgument (5 ms)
[ RUN      ] TemplateResolver.AliasDependent
[       OK ] TemplateResolver.AliasDependent (4 ms)
[ RUN      ] TemplateResolver.AliasTemplate
[       OK ] TemplateResolver.AliasTemplate (4 ms)
[ RUN      ] TemplateResolver.BaseDependent
[       OK ] TemplateResolver.BaseDependent (4 ms)
[ RUN      ] TemplateResolver.MultiNested
[       OK ] TemplateResolver.MultiNested (4 ms)
[ RUN      ] TemplateResolver.OuterDependentMemberClass
[       OK ] TemplateResolver.OuterDependentMemberClass (5 ms)
[ RUN      ] TemplateResolver.InnerDependentMemberClass
[       OK ] TemplateResolver.InnerDependentMemberClass (4 ms)
[ RUN      ] TemplateResolver.InnerDependentPartialMemberClass
[       OK ] TemplateResolver.InnerDependentPartialMemberClass (3 ms)
[ RUN      ] TemplateResolver.PartialSpecialization
[       OK ] TemplateResolver.PartialSpecialization (3 ms)
[ RUN      ] TemplateResolver.PartialDefaultArgument
[       OK ] TemplateResolver.PartialDefaultArgument (3 ms)
[ RUN      ] TemplateResolver.DefaultArgument
[       OK ] TemplateResolver.DefaultArgument (5 ms)
[ RUN      ] TemplateResolver.PackExpansion
[       OK ] TemplateResolver.PackExpansion (3 ms)
[ RUN      ] TemplateResolver.BasePackExpansion
[       OK ] TemplateResolver.BasePackExpansion (4 ms)
[ RUN      ] TemplateResolver.Standard
[       OK ] TemplateResolver.Standard (1304 ms)
[----------] 20 tests from TemplateResolver (1388 ms total)

[----------] 2 tests from Feature
[ RUN      ] Feature.CodeCompletion
[       OK ] Feature.CodeCompletion (4 ms)
[ RUN      ] Feature.SemanticTokens
[       OK ] Feature.SemanticTokens (0 ms)
[----------] 2 tests from Feature (4 ms total)

[----------] 13 tests from FoldingRange
[ RUN      ] FoldingRange.Namespace
[       OK ] FoldingRange.Namespace (3 ms)
[ RUN      ] FoldingRange.Enum
[       OK ] FoldingRange.Enum (3 ms)
[ RUN      ] FoldingRange.RecordDecl
[       OK ] FoldingRange.RecordDecl (3 ms)
[ RUN      ] FoldingRange.CXXRecordDeclAndMemberMethod
[       OK ] FoldingRange.CXXRecordDeclAndMemberMethod (4 ms)
[ RUN      ] FoldingRange.LambdaCapture
[       OK ] FoldingRange.LambdaCapture (5 ms)
[ RUN      ] FoldingRange.LambdaExpression
[       OK ] FoldingRange.LambdaExpression (3 ms)
[ RUN      ] FoldingRange.FnParas
[       OK ] FoldingRange.FnParas (3 ms)
[ RUN      ] FoldingRange.FnBody
[       OK ] FoldingRange.FnBody (3 ms)
[ RUN      ] FoldingRange.FnCall
[       OK ] FoldingRange.FnCall (3 ms)
[ RUN      ] FoldingRange.CompoundStmt
[       OK ] FoldingRange.CompoundStmt (4 ms)
[ RUN      ] FoldingRange.InitializeList
[       OK ] FoldingRange.InitializeList (4 ms)
[ RUN      ] FoldingRange.AccessControlBlock
[       OK ] FoldingRange.AccessControlBlock (3 ms)
[ RUN      ] FoldingRange.Macro
[       OK ] FoldingRange.Macro (3 ms)
[----------] 13 tests from FoldingRange (50 ms total)

[----------] 6 tests from Index
[ RUN      ] Index.Test
Total size: 0k
[       OK ] Index.Test (3 ms)
[ RUN      ] Index.ClassTemplate
[       OK ] Index.ClassTemplate (4 ms)
[ RUN      ] Index.FunctionTemplate
[       OK ] Index.FunctionTemplate (5 ms)
[ RUN      ] Index.AliasTemplate
[       OK ] Index.AliasTemplate (5 ms)
[ RUN      ] Index.VarTemplate
[       OK ] Index.VarTemplate (4 ms)
[ RUN      ] Index.Concept
[       OK ] Index.Concept (3 ms)
[----------] 6 tests from Index (27 ms total)

[----------] 8 tests from Support
[ RUN      ] Support.Equal
[       OK ] Support.Equal (0 ms)
[ RUN      ] Support.Less
[       OK ] Support.Less (0 ms)
[ RUN      ] Support.NormalEnum
[       OK ] Support.NormalEnum (0 ms)
[ RUN      ] Support.MaskEnum
[       OK ] Support.MaskEnum (0 ms)
[ RUN      ] Support.JSON
[       OK ] Support.JSON (0 ms)
[ RUN      ] Support.StatefulSerde
[       OK ] Support.StatefulSerde (0 ms)
[ RUN      ] Support.Struct
[       OK ] Support.Struct (0 ms)
[ RUN      ] Support.Inheritance
[       OK ] Support.Inheritance (0 ms)
[----------] 8 tests from Support (0 ms total)

[----------] Global test environment tear-down
[==========] 68 tests from 11 test suites ran. (1885 ms total)
[  PASSED  ] 68 tests.

[brandon@Brandons-MBP clice]$ build/bin/clice                       
[2025-01-05 22:31:30.761] [WARN] No config file specified; using default configuration.
[2025-01-05 22:31:30.767] [INFO] Server started in socket mode at 127.0.0.1:50051
^C
[brandon@Brandons-MBP clice]$ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant